移植uboot第八步:裁剪、修改默认参数、分区
寫在前面:
我的博客已遷移至自建服務器:博客傳送門,CSDN博客暫時停止,如有機器學習方面的興趣,歡迎來看一看。
此外目前我在gitHub上準備一些李航的《統計學習方法》的實現算法,目標將書內算法全部手打實現,歡迎參觀并打星。GitHib傳送門
正文
到這里uboot差不多已經結束了,再完成最后一步,就能啟動內核啦。
一. 首先先解決啟動時的一個警告,這個和裁剪無關,只是先把警告消除掉
*** Warning - bad CRC, using default environment這句話意思就是環境沒有配置,搜索這句話是哪里打出來的
a.在env_common.c文件內的下面這個函數
進入default_environment結構體看看
const uchar default_environment[] = { #ifdef CONFIG_BOOTARGS"bootargs=" CONFIG_BOOTARGS "\0" #endif #ifdef CONFIG_BOOTCOMMAND"bootcmd=" CONFIG_BOOTCOMMAND "\0" #endif #ifdef CONFIG_RAMBOOTCOMMAND"ramboot=" CONFIG_RAMBOOTCOMMAND "\0" #endif #ifdef CONFIG_NFSBOOTCOMMAND"nfsboot=" CONFIG_NFSBOOTCOMMAND "\0" #endif #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)"bootdelay=" MK_STR(CONFIG_BOOTDELAY) "\0" #endif #if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0)"baudrate=" MK_STR(CONFIG_BAUDRATE) "\0" #endif #ifdef CONFIG_LOADS_ECHO"loads_echo=" MK_STR(CONFIG_LOADS_ECHO) "\0" #endif #ifdef CONFIG_ETHADDR"ethaddr=" MK_STR(CONFIG_ETHADDR) "\0" #endif #ifdef CONFIG_ETH1ADDR"eth1addr=" MK_STR(CONFIG_ETH1ADDR) "\0" #endif #ifdef CONFIG_ETH2ADDR"eth2addr=" MK_STR(CONFIG_ETH2ADDR) "\0" #endif #ifdef CONFIG_ETH3ADDR"eth3addr=" MK_STR(CONFIG_ETH3ADDR) "\0" #endif #ifdef CONFIG_ETH4ADDR"eth4addr=" MK_STR(CONFIG_ETH4ADDR) "\0" #endif #ifdef CONFIG_ETH5ADDR"eth5addr=" MK_STR(CONFIG_ETH5ADDR) "\0" #endif #ifdef CONFIG_IPADDR"ipaddr=" MK_STR(CONFIG_IPADDR) "\0" #endif #ifdef CONFIG_SERVERIP"serverip=" MK_STR(CONFIG_SERVERIP) "\0" #endif #ifdef CONFIG_SYS_AUTOLOAD"autoload=" CONFIG_SYS_AUTOLOAD "\0" #endif #ifdef CONFIG_PREBOOT"preboot=" CONFIG_PREBOOT "\0" #endif #ifdef CONFIG_ROOTPATH"rootpath=" CONFIG_ROOTPATH "\0" #endif #ifdef CONFIG_GATEWAYIP"gatewayip=" MK_STR(CONFIG_GATEWAYIP) "\0" #endif #ifdef CONFIG_NETMASK"netmask=" MK_STR(CONFIG_NETMASK) "\0" #endif #ifdef CONFIG_HOSTNAME"hostname=" MK_STR(CONFIG_HOSTNAME) "\0" #endif #ifdef CONFIG_BOOTFILE"bootfile=" CONFIG_BOOTFILE "\0" #endif #ifdef CONFIG_LOADADDR"loadaddr=" MK_STR(CONFIG_LOADADDR) "\0" #endif #ifdef CONFIG_CLOCKS_IN_MHZ"clocks_in_mhz=1\0" #endif #if defined(CONFIG_PCI_BOOTDELAY) && (CONFIG_PCI_BOOTDELAY > 0)"pcidelay=" MK_STR(CONFIG_PCI_BOOTDELAY) "\0" #endif #ifdef CONFIG_EXTRA_ENV_SETTINGSCONFIG_EXTRA_ENV_SETTINGS #endif"\0" };看到那么多宏定義,頭都有點大了。
一個一個往下看,不用全部都看,平時用到的參數看一看,首先是
這個是boot啟動的時候那個倒計時,默認是5秒,我們可以改成3秒,也可以不改
#define CONFIG_BOOTDELAY 3 /* autoboot after 3 seconds */然后是ip設置
"ipaddr=" MK_STR(CONFIG_IPADDR)將宏修改成如下,可以隨便設,只要和網內其他IP不沖突就行了
#define CONFIG_IPADDR 192.168.1.120連帶的一些都直接寫出來吧,就不一個個說了,這些都挨個設置好
#define CONFIG_NETMASK 255.255.255.0 #define CONFIG_IPADDR 192.168.1.120 #define CONFIG_SERVERIP 192.168.1.101 #define CONFIG_ETHADDR 00:0c:29:d3:fe:1db. 設置環境變量,之前boot里面設置參數的時候,set之后是不能save的,因為沒有設置保存地址,所以這里修改保存地址
原先的值:
#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000) /* */ #define CONFIG_ENV_IS_IN_FLASH #define CONFIG_ENV_SIZE 0x10000 /* allow to overwrite serial and ethaddr */ #define CONFIG_ENV_OVERWRITE修改后的代碼
#if 0 #define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000) /* */ #define CONFIG_ENV_IS_IN_FLASH #define CONFIG_ENV_SIZE 0x10000 /* allow to overwrite serial and ethaddr */ #define CONFIG_ENV_OVERWRITE #else #define CONFIG_ENV_IS_IN_NAND #define CONFIG_ENV_OFFSET 0x00040000 /* 環境變量保存在40000這個地址 */ #define CONFIG_ENV_SIZE 0x0002000 /* 保存區的長度 */ #define CONFIG_ENV_RANGE CONFIG_ENV_SIZE /* 擦除的長度 */ #endif二. 裁剪內核
進入smdk2440.h,把不需要的功能的宏定義都注釋掉或者去掉
a. USB用不著
b. RTC時鐘不需要
/************************************************************* RTC************************************************************/ //#define CONFIG_RTC_S3C24X0c.BOOTP /** BOOTP 看不懂,我就全去掉了*/ //#define CONFIG_BOOTP_BOOTFILESIZE //#define CONFIG_BOOTP_BOOTPATH //#define CONFIG_BOOTP_GATEWAY //#define CONFIG_BOOTP_HOSTNAMEd. 看不懂,去掉一些不眼熟的
/** Command line configuration.*/ #include <config_cmd_default.h>#define CONFIG_CMD_BSP #define CONFIG_CMD_CACHE #define CONFIG_CMD_DATE //#define CONFIG_CMD_DHCP /* 動態獲得IP地址 */ #define CONFIG_CMD_ELF #define CONFIG_CMD_NAND #define CONFIG_CMD_PING #define CONFIG_CMD_REGINFO //#define CONFIG_CMD_USBe.文件系統,只要能燒寫映像文件就行,用不著文件系統
/** File system 文件系統*/ //#define CONFIG_CMD_FAT //#define CONFIG_CMD_EXT2 //#define CONFIG_CMD_UBI //#define CONFIG_CMD_UBIFS //#define CONFIG_CMD_MTDPARTS //#define CONFIG_MTD_DEVICE //#define CONFIG_MTD_PARTITIONS //#define CONFIG_YAFFS2 //#define CONFIG_RBTREE編譯。果然出現了一堆錯誤
/work/system/u-boot-2012.04.01/common/cmd_date.c:60: undefined reference to `rtc_reset' /work/system/u-boot-2012.04.01/common/cmd_date.c:63: undefined reference to `rtc_get' /work/system/u-boot-2012.04.01/common/cmd_date.c:72: undefined reference to `rtc_set' /work/system/u-boot-2012.04.01/common/cmd_date.c:81: undefined reference to `rtc_get' drivers/mtd/ubi/libubi.o: In function `ubi_detach_mtd_dev': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/build.c:925: undefined reference to `put_mtd_device' drivers/mtd/ubi/libubi.o: In function `open_mtd_device': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/build.c:957: undefined reference to `get_mtd_device_nm' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/build.c:959: undefined reference to `get_mtd_device' drivers/mtd/ubi/libubi.o: In function `ubi_init': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/build.c:1023: undefined reference to `put_mtd_device' drivers/mtd/ubi/libubi.o: In function `process_lvol': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/vtbl.c:381: undefined reference to `rb_first' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/vtbl.c:381: undefined reference to `rb_next' drivers/mtd/ubi/libubi.o: In function `ubi_eba_init_scan': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/eba.c:1193: undefined reference to `rb_first' drivers/mtd/ubi/libubi.o: In function `ubi_scan_move_to_list': /work/system/u-boot-2012.04.01/include/../drivers/mtd/ubi/scan.h:146: undefined reference to `rb_erase' drivers/mtd/ubi/libubi.o: In function `ubi_eba_init_scan': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/eba.c:1193: undefined reference to `rb_next' drivers/mtd/ubi/libubi.o: In function `leb_write_unlock': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/eba.c:322: undefined reference to `rb_erase' drivers/mtd/ubi/libubi.o: In function `leb_read_unlock': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/eba.c:238: undefined reference to `rb_erase' drivers/mtd/ubi/libubi.o: In function `ltree_add_entry': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/eba.c:191: undefined reference to `rb_insert_color' drivers/mtd/ubi/libubi.o: In function `find_wl_entry': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:419: undefined reference to `rb_first' drivers/mtd/ubi/libubi.o: In function `ensure_wear_leveling': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:999: undefined reference to `rb_first' drivers/mtd/ubi/libubi.o: In function `prot_tree_del': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:574: undefined reference to `rb_erase' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:575: undefined reference to `rb_erase' drivers/mtd/ubi/libubi.o: In function `wl_tree_add': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:241: undefined reference to `rb_insert_color' drivers/mtd/ubi/libubi.o: In function `ubi_wl_init_scan': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:1515: undefined reference to `rb_first' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:1516: undefined reference to `rb_first' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:1516: undefined reference to `rb_next' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:1515: undefined reference to `rb_next' drivers/mtd/ubi/libubi.o: In function `check_protection_over': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:665: undefined reference to `rb_first' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:675: undefined reference to `rb_erase' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:676: undefined reference to `rb_erase' drivers/mtd/ubi/libubi.o: In function `ubi_wl_scrub_peb': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:1266: undefined reference to `rb_erase' drivers/mtd/ubi/libubi.o: In function `ubi_wl_put_peb': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:1204: undefined reference to `rb_erase' drivers/mtd/ubi/libubi.o: In function `prot_tree_add': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:389: undefined reference to `rb_insert_color' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:403: undefined reference to `rb_insert_color' drivers/mtd/ubi/libubi.o: In function `wear_leveling_worker': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:796: undefined reference to `rb_first' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:805: undefined reference to `rb_erase' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:811: undefined reference to `rb_first' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:814: undefined reference to `rb_erase' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:819: undefined reference to `rb_erase' drivers/mtd/ubi/libubi.o: In function `ubi_wl_get_peb': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:498: undefined reference to `rb_first' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:500: undefined reference to `rb_last' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:518: undefined reference to `rb_first' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/wl.c:533: undefined reference to `rb_erase' drivers/mtd/ubi/libubi.o: In function `ubi_scan_rm_volume': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/scan.c:634: undefined reference to `rb_erase' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/scan.c:632: undefined reference to `rb_first' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/scan.c:638: undefined reference to `rb_erase' drivers/mtd/ubi/libubi.o: In function `add_volume': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/scan.c:219: undefined reference to `rb_insert_color' drivers/mtd/ubi/libubi.o: In function `ubi_scan_add_used': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/scan.c:556: undefined reference to `rb_insert_color' drivers/mtd/ubi/libubi.o: In function `ubi_scan': /work/system/u-boot-2012.04.01/drivers/mtd/ubi/scan.c:958: undefined reference to `rb_first' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/scan.c:959: undefined reference to `rb_first' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/scan.c:959: undefined reference to `rb_next' /work/system/u-boot-2012.04.01/drivers/mtd/ubi/scan.c:958: undefined reference to `rb_next' fs/ext2/libext2fs.o: In function `ext2fs_set_blk_dev': /work/system/u-boot-2012.04.01/fs/ext2/dev.c:44: undefined reference to `get_partition_info' fs/fat/libfat.o: In function `file_fat_detectfs': /work/system/u-boot-2012.04.01/fs/fat/fat.c:1162: undefined reference to `dev_print' fs/fat/libfat.o: In function `fat_register_device': /work/system/u-boot-2012.04.01/fs/fat/fat.c:79: undefined reference to `get_partition_info' fs/ubifs/libubifs.o: In function `insert_old_idx': /work/system/u-boot-2012.04.01/fs/ubifs/tnc.c:105: undefined reference to `rb_insert_color' fs/ubifs/libubifs.o: In function `ubifs_add_bud': /work/system/u-boot-2012.04.01/fs/ubifs/log.c:86: undefined reference to `rb_insert_color' fs/ubifs/libubifs.o: In function `insert_dead_orphan': /work/system/u-boot-2012.04.01/fs/ubifs/orphan.c:129: undefined reference to `rb_insert_color' fs/ubifs/libubifs.o: In function `ubifs_recover_size': /work/system/u-boot-2012.04.01/fs/ubifs/recovery.c:1171: undefined reference to `rb_first' /work/system/u-boot-2012.04.01/fs/ubifs/recovery.c:1214: undefined reference to `rb_next' /work/system/u-boot-2012.04.01/fs/ubifs/recovery.c:1220: undefined reference to `rb_next' /work/system/u-boot-2012.04.01/fs/ubifs/recovery.c:1221: undefined reference to `rb_erase' fs/ubifs/libubifs.o: In function `add_ino': /work/system/u-boot-2012.04.01/fs/ubifs/recovery.c:1050: undefined reference to `rb_insert_color' fs/ubifs/libubifs.o: In function `remove_ino': /work/system/u-boot-2012.04.01/fs/ubifs/recovery.c:1088: undefined reference to `rb_erase' fs/ubifs/libubifs.o: In function `insert_node': /work/system/u-boot-2012.04.01/fs/ubifs/replay.c:373: undefined reference to `rb_insert_color' fs/ubifs/libubifs.o: In function `insert_dent': /work/system/u-boot-2012.04.01/fs/ubifs/replay.c:448: undefined reference to `rb_insert_color' fs/ubifs/libubifs.o: In function `insert_ref_node': /work/system/u-boot-2012.04.01/fs/ubifs/replay.c:689: undefined reference to `rb_insert_color' fs/ubifs/libubifs.o: In function `apply_replay_tree': /work/system/u-boot-2012.04.01/fs/ubifs/replay.c:306: undefined reference to `rb_next' /work/system/u-boot-2012.04.01/fs/ubifs/replay.c:294: undefined reference to `rb_first' make: *** [u-boot] Error 1 book@book-desktop:/work/system/u-boot-2012.04.01$看第一個錯誤,rtc的cmd_date有問題,把這個的宏也直接注釋掉
//#define CONFIG_CMD_DATE然后看下面的錯誤,好像都和ubi有關,但是ubi已經去掉了啊,可能沒有make clean。
先make clean,然后再重新編譯。
果然沒有錯誤了。
看一下bin有多大
返回:
-rwxr-xr-x 1 book book 216844 2016-08-13 23:38 u-boot.bin兩百多k,原先是400多K,的確小了很多。
三. 劃分分區
劃分區不能隨便畫,要看一下使用的內核是打算怎么分的,不然兩邊數據讀取的時候都對不上。
tftp下載uImage內核,bootm啟動,這個在之前應該寫過,內核會在內核中啟動,重新上電就沒有了,測試的時候很方便,啟動內核以后在打出來的數據里查看分區,它是這樣寫的
我們boot也照著這個樣子分區好了。命令mtdpart是和分區有關的,查找boot里有沒有名字是mtdpart的文件,找到cmd_mtdpart,找到里面的初始化函數mtdparts_init,里面太亂了,還是看看別人怎么用好了,搜索這個關鍵詞,隨便進入一個文件,看到別人這么寫的
#define CONFIG_CMD_MTDPARTS #define MTDIDS_DEFAULT "nor0=TQM8xxM-0" /* 表示哪一個設備 */ #define MTDPARTS_DEFAULT "mtdparts=TQM8xxM-0:512k(u-boot)," \"128k(params)," \"1920k(kernel)," \"5632(rootfs)," \"4m(data)" \直接復制到2440.h,修改"nor0=TQM8xxM-0"中的nor為nand,“TQM8xxM”改為“jz2440”(兩個TQM8xxM都要改為一致,我當時就是只改了一個,報錯如下)
invalid mtd device 'TQM8xxM-0'(u-boot)的大小改為256k,params改為128k,kernel改為2m,rootfs改為“-”,“-”表示剩下的空間,(data)直接刪掉,注意rootfs后面的逗號一定要去掉,我之前沒去掉,報錯
no partitions allowed after a fill-up partition后來查代碼才發現,只要后面有逗號,它就會認為下面還有劃分空間,這時候你又已經寫了“-”表示這段空間到末尾,所以會報錯。
所以整段代碼改為
最后還要到board.c的
for (;;) {main_loop();}之前加上一句話
run_command("mtdparts default", 0);這是命令mtdparts default,就是說每次boot啟動以后先分區,因為分區是我們程序軟規定的,每次啟動都要規定一下。
編譯,沒有錯誤,燒寫。
四. 測試分區是否好使
a. 輸入命令mtd,返回結果:
已經分區成功了
b. 使用TFTP下載,把名為uImage的內核下載到30000000的地址
c. 擦除內核要使用的分區
nand erase.part kerneld. 將內核寫入kernel
nand write.part kernele. 重啟,等待3秒結束后啟動內核,
f. 啟動成功
總結
以上是生活随笔為你收集整理的移植uboot第八步:裁剪、修改默认参数、分区的全部內容,希望文章能夠幫你解決所遇到的問題。

- 上一篇: 移植uboot第七步:支持DM9000
- 下一篇: 移植uboot第九步:支持yaffs映像