Makefile 常用函數 與 語法

使用Makefile function可用{}或()將function包起來
${function string}  or $(function string)
以下開始介紹YC常用的

Makefile function

$(notdir string...)   
找出最後一個 / 輸出後續的的字串

$(notdir /mnt/test1.c test2.c) 
output result : test1.c test2.c

 
$(wildcard string...)  
在folder下找出所有指定好副檔名
 
假設/mnt/下有test1.c test2.c test3.o test4.o
$(wildcard /mnt/*.c) 
output reslut : test1.c test2.c (*.o不會被輸出)
 
$(subst from, to, string) 
從string中找出from取代成to
 
$(subst hate, love, I hate linux) 
output result : I love linux 

$(filter-out pattern, string)
輸出pattern以外的字串
 
$(filter-out test1.c, test.1.c test2.c)
output result : test2.c
 
$(foreach var, StringList, $var) 
StringList以空白隔開,逐一取得值,將值傳給var,並輸出$var計算後的結果 
 
$(foreach var,a b c d, $(var).x) 
output result : a.x b.x c.x d.x
 
假設/src1目錄/下有test1.c test1.o, /src2目錄下有test2.c test2.o
$(foreach var, /src1 /src2, $(wildcard $(var)/*.c)) 
output result : test1.c test2.c
 
變數使用語法
 
以下是YC常常健忘的語法 
:= 語法
指定變數的語法,make 會先把整個檔案展開,找出該變數最後一個被賦予的值

x := foo
y := $(x)
x := foobar
y的結果為 foobar

?= 語法
變數已經被指定過,不會再被賦予新值
 
Makefile隱藏變數 
 
VPATH
告知Makefile原始碼目錄在哪
 
 
Makefile sample
 
# target source
SRCS =  main.c \
                test1.c #under folder src
TARGET := main

.PHONY : clean
 
#default Makefile compiler variable
VPATH= $(PWD)/src $(PWD)
#################################

OBJ_PATH=$(PWD)/obj
OBJS :=$(SRCS:%.c=$(OBJ_PATH)/%.o)

$(OBJ_PATH)/%.o : %.c
 @echo compiler $(notdir $<) 
 @[ -e $(OBJ_PATH) ] || mkdir -p $(OBJ_PATH)
 @$(CC) $(CFLAGS) -o $@ -c $<

$(TARGET):$(OBJS)
 $(CC)  -o $(TARGET) $(OBJS)

clean:
 @rm -rf $(TARGET) $(OBJS)
 @rm -rf $(OBJ_PATH)  
 

Ubuntu 小筆記

移除舊kernel image 與 kernel header 
 
ubuntu每隔一段時間就會出新kernel,隨著每次更新後,檔案系統Disk的Free Size越來越小
偶爾要把沒用到的檔案刪除,YC第一個想到就是舊的kernel image與header檔
 
用以下指令先查看系統安裝了多少kernel image與kernel header 
dpkg -l | awk -F " " '{print $2}' | egrep '(linux-image|linux-header)'
 
手動一一將舊的kernel image/header移除
指令如下: 
apt-get purge linux-image-3.19.0-81-generic

更新開機grub table
sudo update-grub2 

Hisi BSP Part1 - Build environment for Toolchain/Kernel/u-boot

When I got a BSP, I used to find kernel, u-boot and toolchain first.

After setup cross-compiler toolchain path to env


A.Kernel Part

Kernel source code Path :  osdrv/opensource/kernel/linux-3.18.y.tgz

After  decompress it. copy default kernel config

cp arch/arm/configs/hi3516cv300_full_defconfig  .config

menuconfig :

make ARCH=arm CROSS_COMPILE=arm-hisiv600-linux-gnueabi- menuconfig

make kernel :

make -j4 ARCH=arm CROSS_COMPILE=arm-hisiv600-linux-gnueabi- uImage


Compiler kernel succeed^_^



B.BootLoader Part

uboot source code Path : osdrv/opensource/uboot/u-boot-2010.06.tgz
After decompress u-boot.tgz file, Enter u-boot root folder. Type below commands.

make ARCH=arm CROSS_COMPILE=arm-hisiv600-linux-gnueabi- hi3516cv300_config
make ARCH=arm CROSS_COMPILE=arm-hisiv600-linux-gnueabi-


After comiler, many errors.... I think Hisi-uboot document wrote not good. And Makefile also has problem. Ok, Let's find how to solve this problem.

u-boot Compiler Error Solution :
Enter to Toolchain Folder. Enter bin Folder and Find these compiler tool gcc, objdump, ar, objcopy, ld, ranlib, nm .

ln -sf arm-hisiv600-linux-gnueabi-gcc arm-hisiv600-linux-gcc
ln -sf arm-hisiv600-linux-gnueabi-
objdump arm-hisiv600-linux-objdump
ln -sf arm-hisiv600-linux-gnueabi-
ar arm-hisiv600-linux-ar
ln -sf arm-hisiv600-linux-gnueabi-
objcopy arm-hisiv600-linux-objcopy
ln -sf arm-hisiv600-linux-gnueabi-
ld arm-hisiv600-linux-ld
ln -sf arm-hisiv600-linux-gnueabi-
ranlib arm-hisiv600-linux-ranlib
ln -sf arm-hisiv600-linux-gnueabi-
nm arm-hisiv600-linux-nm

Enter u-boot root folder.  And enter below commands
make ARCH=arm CROSS_COMPILE=arm-hisiv600-linux- hi3516cv300_config
make ARCH=arm CROSS_COMPILE=arm-hisiv600-linux-

 
Finally, compiler  succeed.





But this u-boot cann't be burn to NorFlash.
It need to add ddr-reg binary to u-boot.bin

Find the pc tool, Enter folder osdrv/tools/pc/uboot_tools
Open Hi3516CV300-DEMB-uboot-DDR3_1066M-16bit-256MB-ARM9_800M-BUS_266M.xls
Edit tab mddrc_dmc and mddrc_phy for your DDR. Go to tab main and click Generage reg bin file.





Generate a binary file.




Combine cfg.bin and u-boot.bin
Enter below command:
./mkboot.sh cfg.bin u-boot-ok.bin


End


Install KDE Desktop for Ubuntu 24.04

1. Enter following command to install the KDE-plasma sudo apt install kde-plasma-desktop 2. Disable the login screen 2-1. Create default sdd...