移植uboot第八步:裁剪、修改默认参数、分区
寫(xiě)在前面:
我的博客已遷移至自建服務(wù)器:博客傳送門(mén),CSDN博客暫時(shí)停止,如有機(jī)器學(xué)習(xí)方面的興趣,歡迎來(lái)看一看。
此外目前我在gitHub上準(zhǔn)備一些李航的《統(tǒng)計(jì)學(xué)習(xí)方法》的實(shí)現(xiàn)算法,目標(biāo)將書(shū)內(nèi)算法全部手打?qū)崿F(xiàn),歡迎參觀并打星。GitHib傳送門(mén)
正文
到這里uboot差不多已經(jīng)結(jié)束了,再完成最后一步,就能啟動(dòng)內(nèi)核啦。
一. 首先先解決啟動(dòng)時(shí)的一個(gè)警告,這個(gè)和裁剪無(wú)關(guān),只是先把警告消除掉
*** Warning - bad CRC, using default environment這句話意思就是環(huán)境沒(méi)有配置,搜索這句話是哪里打出來(lái)的
a.在env_common.c文件內(nèi)的下面這個(gè)函數(shù)
進(jìn)入default_environment結(jié)構(gòu)體看看
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" };看到那么多宏定義,頭都有點(diǎn)大了。
一個(gè)一個(gè)往下看,不用全部都看,平時(shí)用到的參數(shù)看一看,首先是
這個(gè)是boot啟動(dòng)的時(shí)候那個(gè)倒計(jì)時(shí),默認(rèn)是5秒,我們可以改成3秒,也可以不改
#define CONFIG_BOOTDELAY 3 /* autoboot after 3 seconds */然后是ip設(shè)置
"ipaddr=" MK_STR(CONFIG_IPADDR)將宏修改成如下,可以隨便設(shè),只要和網(wǎng)內(nèi)其他IP不沖突就行了
#define CONFIG_IPADDR 192.168.1.120連帶的一些都直接寫(xiě)出來(lái)吧,就不一個(gè)個(gè)說(shuō)了,這些都挨個(gè)設(shè)置好
#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. 設(shè)置環(huán)境變量,之前boot里面設(shè)置參數(shù)的時(shí)候,set之后是不能save的,因?yàn)闆](méi)有設(shè)置保存地址,所以這里修改保存地址
原先的值:
#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 /* 環(huán)境變量保存在40000這個(gè)地址 */ #define CONFIG_ENV_SIZE 0x0002000 /* 保存區(qū)的長(zhǎng)度 */ #define CONFIG_ENV_RANGE CONFIG_ENV_SIZE /* 擦除的長(zhǎng)度 */ #endif二. 裁剪內(nèi)核
進(jìn)入smdk2440.h,把不需要的功能的宏定義都注釋掉或者去掉
a. USB用不著
b. RTC時(shí)鐘不需要
/************************************************************* 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 /* 動(dòng)態(tài)獲得IP地址 */ #define CONFIG_CMD_ELF #define CONFIG_CMD_NAND #define CONFIG_CMD_PING #define CONFIG_CMD_REGINFO //#define CONFIG_CMD_USBe.文件系統(tǒng),只要能燒寫(xiě)映像文件就行,用不著文件系統(tǒng)
/** File system 文件系統(tǒng)*/ //#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編譯。果然出現(xiàn)了一堆錯(cuò)誤
/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$看第一個(gè)錯(cuò)誤,rtc的cmd_date有問(wèn)題,把這個(gè)的宏也直接注釋掉
//#define CONFIG_CMD_DATE然后看下面的錯(cuò)誤,好像都和ubi有關(guān),但是ubi已經(jīng)去掉了啊,可能沒(méi)有make clean。
先make clean,然后再重新編譯。
果然沒(méi)有錯(cuò)誤了。
看一下bin有多大
返回:
-rwxr-xr-x 1 book book 216844 2016-08-13 23:38 u-boot.bin兩百多k,原先是400多K,的確小了很多。
三. 劃分分區(qū)
劃分區(qū)不能隨便畫(huà),要看一下使用的內(nèi)核是打算怎么分的,不然兩邊數(shù)據(jù)讀取的時(shí)候都對(duì)不上。
tftp下載uImage內(nèi)核,bootm啟動(dòng),這個(gè)在之前應(yīng)該寫(xiě)過(guò),內(nèi)核會(huì)在內(nèi)核中啟動(dòng),重新上電就沒(méi)有了,測(cè)試的時(shí)候很方便,啟動(dòng)內(nèi)核以后在打出來(lái)的數(shù)據(jù)里查看分區(qū),它是這樣寫(xiě)的
我們boot也照著這個(gè)樣子分區(qū)好了。命令mtdpart是和分區(qū)有關(guān)的,查找boot里有沒(méi)有名字是mtdpart的文件,找到cmd_mtdpart,找到里面的初始化函數(shù)mtdparts_init,里面太亂了,還是看看別人怎么用好了,搜索這個(gè)關(guān)鍵詞,隨便進(jìn)入一個(gè)文件,看到別人這么寫(xiě)的
#define CONFIG_CMD_MTDPARTS #define MTDIDS_DEFAULT "nor0=TQM8xxM-0" /* 表示哪一個(gè)設(shè)備 */ #define MTDPARTS_DEFAULT "mtdparts=TQM8xxM-0:512k(u-boot)," \"128k(params)," \"1920k(kernel)," \"5632(rootfs)," \"4m(data)" \直接復(fù)制到2440.h,修改"nor0=TQM8xxM-0"中的nor為nand,“TQM8xxM”改為“jz2440”(兩個(gè)TQM8xxM都要改為一致,我當(dāng)時(shí)就是只改了一個(gè),報(bào)錯(cuò)如下)
invalid mtd device 'TQM8xxM-0'(u-boot)的大小改為256k,params改為128k,kernel改為2m,rootfs改為“-”,“-”表示剩下的空間,(data)直接刪掉,注意rootfs后面的逗號(hào)一定要去掉,我之前沒(méi)去掉,報(bào)錯(cuò)
no partitions allowed after a fill-up partition后來(lái)查代碼才發(fā)現(xiàn),只要后面有逗號(hào),它就會(huì)認(rèn)為下面還有劃分空間,這時(shí)候你又已經(jīng)寫(xiě)了“-”表示這段空間到末尾,所以會(huì)報(bào)錯(cuò)。
所以整段代碼改為
最后還要到board.c的
for (;;) {main_loop();}之前加上一句話
run_command("mtdparts default", 0);這是命令mtdparts default,就是說(shuō)每次boot啟動(dòng)以后先分區(qū),因?yàn)榉謪^(qū)是我們程序軟規(guī)定的,每次啟動(dòng)都要規(guī)定一下。
編譯,沒(méi)有錯(cuò)誤,燒寫(xiě)。
四. 測(cè)試分區(qū)是否好使
a. 輸入命令mtd,返回結(jié)果:
已經(jīng)分區(qū)成功了
b. 使用TFTP下載,把名為uImage的內(nèi)核下載到30000000的地址
c. 擦除內(nèi)核要使用的分區(qū)
nand erase.part kerneld. 將內(nèi)核寫(xiě)入kernel
nand write.part kernele. 重啟,等待3秒結(jié)束后啟動(dòng)內(nèi)核,
f. 啟動(dòng)成功
總結(jié)
以上是生活随笔為你收集整理的移植uboot第八步:裁剪、修改默认参数、分区的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 移植uboot第七步:支持DM9000
- 下一篇: 移植uboot第九步:支持yaffs映像