2019/11/14

put driver firmware bin file into kernel

看看比較簡單(?) 的 firmware driver : WHITEHEAT
他是 usb serial converter,所以要到 usb client driver 上找,usb ez...
enable 起來後,make log:
make -f /home/charles-chang/mt2712robot/kernel-4.9/scripts/Makefile.build obj=firmware
  FWNAME="whiteheat_loader.fw"; FWSTR="whiteheat_loader_fw"; ASM_WORD=.quad; ASM_ALIGN=3; PROGBITS=@progbits;
 echo "/* Generated by firmware/Makefile */"               > firmware/whiteheat_loader.fw.gen.S;
 echo "    .section .rodata"                               >>firmware/whiteheat_loader.fw.gen.S;
 echo "    .p2align ${ASM_ALIGN}"                  >>firmware/whiteheat_loader.fw.gen.S;
 echo "_fw_${FWSTR}_bin:"                          >>firmware/whiteheat_loader.fw.gen.S;
 echo "    .incbin \"firmware/whiteheat_loader.fw\""                               >>firmware/whiteheat_loader.fw.gen.S;
 echo "_fw_end:"                                   >>firmware/whiteheat_loader.fw.gen.S;
 echo "   .section .rodata.str,\"aMS\",${PROGBITS},1"      >>firmware/whiteheat_loader.fw.gen.S;
 echo "    .p2align ${ASM_ALIGN}"                  >>firmware/whiteheat_loader.fw.gen.S;
 echo "_fw_${FWSTR}_name:"                         >>firmware/whiteheat_loader.fw.gen.S;
 echo "    .string \"$FWNAME\""                    >>firmware/whiteheat_loader.fw.gen.S;
 echo "    .section .builtin_fw,\"a\",${PROGBITS}" >>firmware/whiteheat_loader.fw.gen.S;
 echo "    .p2align ${ASM_ALIGN}"                  >>firmware/whiteheat_loader.fw.gen.S;
 echo "    ${ASM_WORD} _fw_${FWSTR}_name"          >>firmware/whiteheat_loader.fw.gen.S;
 echo "    ${ASM_WORD} _fw_${FWSTR}_bin"           >>firmware/whiteheat_loader.fw.gen.S;
 echo "    ${ASM_WORD} _fw_end - _fw_${FWSTR}_bin" >>firmware/whiteheat_loader.fw.gen.S;
  gcc -Wp,-MD,firmware/.ihex2fw.d -Ifirmware -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
 -o firmware/ihex2fw /home/charles-chang/mt2712robot/kernel-4.9/firmware/ihex2fw.c
這會把 firmwae 下的 *.HEX 檔轉成 binary 檔,ro 產生一個 section 放置。
這樣就會變成kernel 的一部分,所以用 section name (label) 就可以 access到這個 bin 的位置。

ㄎ 但是這是很不好的方法。

這種方法另一個方式是用 menuconfig, 不用改 kernel source..
ref: Usage and Mechanism of kernel function "request firmware()"

menuconfig -- device driver -- generic .... -- firmware....
有一項就是firmare,因為 firmware dir 的 default 是 firmware,所以直接把 bin 檔放到 firmware/ 下就可以,
然後把 bin 檔的檔名寫在 剛剛 menuconfig 的 FIRMWARE 選項中。

這樣就不用改 kernel Makefile,也不用把 bin 檔轉成hex

沒有留言:

張貼留言