一、准備工作
在建立之前,先需要將下載的u-boot 拷貝一份出來解壓,在此工程下進行更改和創建。同時根據前面搜索到的 mini2440開發板所在的版本,下載一份u-boot 拷貝出 mini2440 的工程文件。
選擇2013.10版本的 u-boot。下載,並解壓。
1.1 board 目錄修改
u-boot-2013.10/board/samsung/smdk2410 復制進 u-boot-2017.11/board/samsung/ 目錄
文件名修改:
Makefile 修改為:
創建 Kconfig 文件並修改:
1.2 頭文件修改
u-boot-2013.10/include/configs/smdk2410.h 拷貝進 u-boot-2017.11//include/configs/mini2440.h
在頭文件中添加對 S3C2440芯片的支持:
在2013.10版本中,執行命令:grep -R -l "smdk2410.h"
查找是否還有包含 smdk2410.h 文件
1.3 修改arch/arm下文件
1.3.1 修改Kconfig文件
當前新版的u-boot與linux源碼一樣,都執行make menuconfig 進行配置,所以在configs目錄下要有mini2440的配置
1.3.2 修改arch/arm/include/asm/mach-types.h
mach-types.h 已經有了相關配置:
1.3.3 加入S3C24X0文件夾
u-boot-2013.10/arch/arm/cpu/arm920t/s3c24x0 復制進 u-boot-2017.11/arch/arm/cpu/arm920t/目錄
1.4 修改 u-boot-2017.11/configs 下的defconfig文件
在新版本的 u-boot 中,並沒有我們適用和仿照的配置文件。既然沒有,那么我們執行 make menuconfig 在其中配置一份最小配置。
- Architecture select:架構,選擇 ARM architecture
- ARM architecture:
- Target select:選擇我們配置的開發板 mini2440
- 其余全不選中
- General setup:通用配置
- 選中 Configure standard U-boot features 即可,其余全不選。
- boot images 啟動鏡像,暫且默認
- API:默認不選中即可
- Boot timing:暫時默認
- Boot media:選中支持 NAND flash
- delay in seconds before automatically booting :啟動延遲的時間,設置為5
- Enable boot arguments:使能啟動命令參數,暫時不做修改,為空
- Console:默認
- Default fdt file:默認不填
- add U-Boot environment variable vers:默認不寫
- Display information about the CPU during start up:選上
- Display information about the board during start up:選上
- Start-up hooks:里面是特殊板子的啟動選項,默認不選
- Security support:編譯的選項,暫時默認
- SPL / TPL:默認
- Command line interface:命令行接口,
- Support U-Boot commands:支持U-boot命令,選中
- Use hush shell:不選
- Shell prompt:命令行的類型,默認就好
- Autoboot options:自動啟動選項,默認即可
- Info commands:命令信息,默認即可
- Boot commands:啟動命令,暫時默認,后面可能裁剪一下
- Environment commands:環境變量命令,默認
- Memory commands :內存命令
- Compression commands:壓縮命令
- Device access commands:設備到達命令,去掉 fpga,我們是ARM,加入nand命令,其他保持默認
- Shell scripting commands:SHELL腳本命令,默認
- Network commands:網絡命令,暫且默認
- Misc commands:雜項命令,都去掉
- Power commands:電源命令,無
- Security commands:加密命令,不選
- Firmware commands:防火牆命令
- Filesystem commands:文件系統命令,默認不選
- Debug commands:調試命令,默認不選
- Enable UBI - Unsorted block images commands:鏡像分塊命令,默認不選
- Partition Types:磁盤類型,暫時默認
- Device Tree Control:設備樹控制,默認都不選中即可
- Path to dtc binary for use within mkimage:dtc二進制文件路徑,默認即可
- Environment:環境變量,默認即可
- Networking support:網絡設備支持,默認即可
- Device Drivers:設備驅動,暫且默認
- File systems:文件系統支持,選擇YAFFS2 filesystem support
- Library routines:庫選擇,默認即可
- Unit tests:單元測試,不選中
配置完后,保存編譯一遍。
1.5 編譯報錯解決
1.5.1 config_cmd_default.h: No such file or directory
沒有 config_cmd_default.h 文件,此文件中裝載的是 U-BOOT中的一些命令。
注釋掉頭文件
1.5.2 lib/asm-offsets.c:1:0: error: bad value (armv4t) for -march= switch
一般是由於交叉編譯工具鏈沒有指定,在頂層的 Makefile 下加入交叉編譯工具鏈。
1.5.3 重復定義的選項:
include/configs/mini2440.h:84:0: warning: "CONFIG_CMD_ELF" redefined
include/configs/mini2440.h:85:0: warning: "CONFIG_CMD_NAND" redefined
include/configs/mini2440.h:113:0: warning: "CONFIG_SYS_PROMPT" redefined
include/configs/mini2440.h:121:0: warning: "CONFIG_DISPLAY_CPUINFO" redefined
include/configs/mini2440.h:195:0: warning: "CONFIG_YAFFS2" redefined
這些選項在 config文件或者是 其他文件中都已經定義,先注釋掉
1.5.4 scripts/Makefile.build:280: recipe for target 'cmd/reginfo.o' failed
cmd/reginfo.c:10:21: fatal error: asm/ppc.h: No such file or directory
#include <asm/ppc.h>
缺少文件。
追蹤 reginfo.c 的源碼
追蹤到 asm/ppc.h 文件
需要宏控制,查找一下此宏在哪里定義的
注釋掉:
1.5.5 cmd/ubi.c:79:44: error: ‘CONFIG_MTD_UBI_WL_THRESHOLD’ undeclared (first use in this function)
文件系統全部干掉,menuconfig中可配
1.5.6 drivers/rtc/s3c24x0_rtc.c:17:34: fatal error: asm/arch/s3c24x0_cpu.h: No such file or directory
#include <asm/arch/s3c24x0_cpu.h>
頭文件未包含。
將文件同步過來即可
保存一下 .config 文件備份,然后 make distclean。再重新編譯一遍。
1.5.7 common/built-in.o:(.rodata.init_sequence_f+0x20): undefined reference to `board_early_init_f'
common/built-in.o:(.rodata.init_sequence_f+0x4c): undefined reference to `dram_init'
common/built-in.o:(.data.init_sequence_r+0x24): undefined reference to `board_init'
查找函數,可以知道 這些函數在 board/samsung/mini2440/mini2440.c 文件中,查看編譯的過程
mini2440.c文件並沒有編譯
修改里面的 board/samsung/mini2440/Makefile 文件為:
- obj-y = xxx.o:是最基本的賦值,make會將整個makefile展開后,再決定變量的值。也就是說,變量的值將會是整個makefile中最后被指定的值。
- obj-y := xxx.o:是覆蓋之前的值,表示變量的值決定於它在makefile中的位置,而不是整個makefile展開后的最終值。
- obj-y ?= xxx.o:是如果沒有被賦值過就賦予等號后面的值
- obj-y += xxx.o:是添加等號后面的值
在生成built-in.o的時候,如果使用:使 obj 的值為 lowlevel_init.o,覆蓋了mini2440.c。
重新編譯:board/samsung/mini2440/mini2440.c: In function ‘board_init’:
board/samsung/mini2440/mini2440.c:100:27: error: ‘MACH_TYPE_SMDK2410’ undeclared (first use in this function)
gd->bd->bi_arch_number = MACH_TYPE_SMDK2410;
再重新編譯,依然報錯,找到原因是因為我們的 machine_arch_type 沒有定義
再 arch/arm/include/asm/mach-types.h 中進行定義,加入如下配置:
文件頭上加上:
在board/samsung/mini2440/mini2440.c中加入頭文件:
編譯,錯誤終結。
1.5.8 drivers/serial/built-in.o: In function `get_current': 和 drivers/serial/built-in.o: In function `serial_initialize':
/u-boot-2017.11/drivers/serial/serial.c:379: undefined reference to `default_serial_console'
/u-boot-2017.11/drivers/serial/serial.c:242: undefined reference to `default_serial_console'
查找當前版本和以前的版本進行對比:
當前版本:
以前的版本:
少一個文件: serial_s3c24x0.c,拷貝一份進去
cp ../../uboot/u-boot-2016.01/drivers/serial/serial_s3c24x0.c drivers/serial/serial_s3c24x0.c
修改 Makefile:
執行編譯,錯誤消除。
1.5.9 env/built-in.o: In function `env_flash_save':
/u-boot-2017.11/env/flash.c:268: undefined reference to `flash_sect_protect'
/u-boot-2017.11/env/flash.c:303: undefined reference to `flash_sect_protect'
/env/flash.c:276: undefined reference to `flash_sect_erase'
/flash.c:280: undefined reference to `flash_write'
/env/flash.c:298: undefined reference to `flash_perror'
flash_sect_protect ,flash_sect_erase依賴於宏 CONFIG_MTD_NOR_FLASH 生效
menuconfig 中修改:
device drivers > mtd support:選中 norflash support
編譯執行,錯誤消失
1.5.9 Error: You must add new CONFIG options using Kconfig
The following new ad-hoc CONFIG options were detected:
CONFIG_ARM920T
CONFIG_MINI2440
CONFIG_NAND_S3C2440
CONFIG_RTC_S3C24X0
CONFIG_S3C2440
CONFIG_S3C24X0
CONFIG_S3C24X0_SERIAL
CONFIG_SYS_HUSH_PARSER
CONFIG_SYS_S3C2440_NAND_HWECC
CONFIG_ZERO_BOOTDELAY_CHECK
Please add these via Kconfig instead. Find a suitable Kconfig
file and add a 'config' or 'menuconfig' option.
注釋掉頂層 Makefile 中下面幾句:
clean 之后編譯。
編譯完成,生成了 u-boot.bin.