1.準備
標明一個目錄,在標明的目錄下,建立builroot目錄用于存放buildroot源碼,建立linux目錄存放Linux源碼。
[email protected]:~/chao/work/test$ ls
buildroot linux
2.将Linux核心源碼打包為壓縮檔案
準備SDK,找開發闆的廠家要,這裡為“Hi3518E_SDK_V1.0.3.0_20200728.tar.gz”。複制到/home/chao/chao/work/test/linux目錄。
解壓SDK
tar -zxvf Hi3518E_SDK_V1.0.3.0_20200728.tar.gz
解壓完成後出多出來一個目錄
[email protected]:~/chao/work/test/linux$ ls
Hi3518E_SDK_V1.0.3.0 Hi3518E_SDK_V1.0.3.0_20200728.tar.gz
進入該目錄,找到Linux核心源碼,這裡的Linux核心源碼位置為
./Hi3518E_SDK_V1.0.3.0/osdrv/opensource/kernel/linux-3.4.y
壓縮Linux核心源碼為linux-hi3518e.tar.gz壓縮檔案。
注意,要在Linux核心源碼的根目錄,進行壓縮,這樣解壓出來之後直接就是源碼根目錄,否則到時候buildroot自動解壓出來目錄不對,buildroot會報錯。
[email protected]:~/chao/work/test/linux/Hi3518E_SDK_V1.0.3.0/osdrv/opensource/kernel/linux-3.4.y$ tar -zcvf linux-hi3518e.tar.gz ./*
然後根目錄下出現linux-hi3518e.tar.gz壓縮檔案,之後将會放到buildroot的指定目錄下。
3.buildroot
将buildroot壓縮包“buildroot-2016.02.tar.gz”拷貝到buildroot目錄下
也就是/home/chao/chao/work/test/buildroot目錄
解壓buildroot
tar -zxvf buildroot-2016.02.tar.gz
解壓完畢之後出現buildroot-2016.02目錄
[email protected]:~/chao/work/test/buildroot$ ls
buildroot-2016.02 buildroot-2016.02.tar.gz
3.1 在buildroot根目錄,執行make menuconfig進入buildroot配置界面,逐一修改配置
進入Target options —>
CPU相關的配置
原本為
Target Architecture (i386) --->
Target Binary Format (ELF) --->
Target Architecture Variant (i586) --->
進入第一個Target Architecture (i386) —>,選擇架構為ARM (little endian)
修改為
│ │ Target Architecture (ARM (little endian)) ---> │ │
│ │ Target Binary Format (ELF) ---> │ │
│ │ Target Architecture Variant (arm926t) ---> │ │
│ │ [ ] Enable VFP extension support (NEW) │ │
│ │ Target ABI (EABI) ---> │ │
│ │ Floating point strategy (Soft float) ---> │ │
│ │ ARM instruction set (ARM) --->
在“Hi3518EV200經濟型HD IP Camera SoC産品簡介.pdf”可看到是arm926:
進入Build options —>
隻修改一項,修改進行make menuconfig之後,buildroot的新的配置檔案的儲存路徑和名字:
原本為
($(CONFIG_DIR)/defconfig) Location to save buildroot config
修改為
(/home/chao/chao/work/test/buildroot/buildroot-2016.02/configs/hi3518ev200_deconfig) Location to save buildroot config
進入Toolchain —>
配置工具鍊,這裡使用海思SDK裡帶的工具鍊(需要先安裝海思安裝交叉編譯工具鍊,可參考https://blog.csdn.net/qq_31885403/article/details/112909980?spm=1001.2014.3001.5501文章)。
配置如下:
海思交叉編譯工具鍊安裝完後,其路徑在“/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/bin”,這裡面是安裝好的工具鍊,如下:
是以buildroot的路徑要設定為
“(/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target) Toolchain path”
以及
“(arm-hisiv300-linux) Toolchain prefix”
注意:其中Custom kernel headers series (3.4.x) —>要選擇正确的版本,否則會報類似如下的錯誤:假設配置為5.10.x,會報如下的錯誤
.....
Incorrect selection of kernel headers: expected 5.10.x, got 3.4.x
.....
Makefile:84: recipe for target '_all' failed
make: *** [_all] Error 2
其中主要的一句“Incorrect selection of kernel headers: expected 5.10.x, got 3.4.x”
意思是編譯器裡面預設比對的是5.10.x,但是檢測到,在Linux核心裡面的核心版本是3.4.x。
在Linux核心根目錄搜尋“version.h”檔案
搜尋到如下檔案
./drivers/net/ethernet/chelsio/cxgb3/version.h
./drivers/net/wireless/ath/carl9170/version.h
./fs/btrfs/version.h
./include/sound/version.h
./include/xen/interface/version.h
./include/linux/version.h
./include/linux/dvb/version.h
./arch/x86/math-emu/version.h
打開其中的vi./include/linux/version.h
打開後内容為:
#define LINUX_VERSION_CODE 197667
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
其中197667是十進制,變成16進制之後為30423,是以是3.4.x的核心版本。
是以這裡需要配置為Custom kernel headers series (3.4.x) —>的版本才能成功編譯。
進入System configuration —>
設定根檔案系統目錄要覆寫/添加的檔案路徑,暫時不需要寫。
進入Kernel —>
現在選擇本地包的方式,以及設定對應的核心配置檔案:
原本為
[ ] Linux Kernel (NEW)
修改為
[*] Linux Kernel
然後跳出很多選項。配置為如下,主要配置核心源碼壓縮包的路徑。
│ │ [*] Linux Kernel │ │
│ │ Kernel version (Custom tarball) ---> │ │
│ │ (dl/linux/linux-hi3518e.tar.gz) URL of custom kernel tarball │ │
│ │ () Custom kernel patches (NEW) │ │
│ │ Kernel configuration (Using an in-tree defconfig file) ---│ │
│ │ (hi3518ev200_full) Defconfig name
Defconfig name的配置是根據Linux源碼内的配置檔案:
Hi3518E_SDK_V1.0.3.0/osdrv/opensource/kernel/linux-3.4.y/arch/arm/configs$ ls hi3518*
hi3518ev200_full_defconfig hi3518ev201_full_defconfig
我們使用的是hi3518ev200,是以選擇其中的hi3518ev200_full_defconfig。注意這裡填寫的時候不要後面的_defconfig,直接填寫前面的“hi3518ev200_full”。
Target packages —>
需要下載下傳安裝的軟體包,根據需求添加,一般預設即可。
Filesystem images —>
沒什麼需要改的,預設即可。
Bootloaders —>
不需要編譯uboot,不需要修改。
Host utilities —>
預設即可。
Legacy config options —>
一些陸續被移除buildroot的配置選項,不需要配置。
儲存退出。
執行make savedefconfig儲存配置檔案,儲存上面配置的資訊。
配置檔案将會生成在buildroot根目錄下的configs目錄,配置檔案的名字為上面Location to save buildroot config選項中填寫的hi3518ev200_deconfig。
前面對配置做了一系列修改,新增了不少目錄和檔案,接下來要依次添加上面填寫的目錄和檔案。
準備Linux核心,将Linux核心壓縮包“linux-hi3518e.tar.gz”,放入上面的URL of custom kernel tarball選項指定的目錄中,沒有這個目錄就建立。
注意,執行make all之前,如果你已經下載下傳有了軟體的壓縮包,請直接複制到dl檔案夾下,這樣就不需要花時間下載下傳了。下載下傳的壓縮包如下:
最後在buildroot根目錄執行make all,會下載下傳并編譯選擇的軟體包,然後編譯Linux核心,編譯完後,将在buildroot根目錄的./output/images/生成zImage檔案。