u-boot-2014.10移植第23天----nand flash啟動(一),uboot2014.10移植

來源:互聯網
上載者:User

u-boot-2014.10移植第23天----nand flash啟動(一),uboot2014.10移植

硬體平台:tq2440

開發環境:Ubuntu-3.11

u-boot版本:2014.10

本文允許轉載,請註明出處:http://blog.csdn.net/fulinus

在Nand flash中儲存環境變數

u-boot中的環境變數可以通過pri命令可以查看,可以通過set(setenv)命令設定一個參數,設定之後的參數僅僅是儲存在SDRAM中,掉電後丟失,

使用save命令可以儲存參數到Nor flash或Nand flash中去,但是u-boot預設是儲存到Nor flash中去,下面修改u-boot,使其儲存的環境變數儲存到

Nand flash中去。

在include/configs/tq2440.h檔案中修改:

+ #if NONE_FLAG                  #define CONFIG_ENV_ADDR         (CONFIG_SYS_FLASH_BASE + 0x070000)#define CONFIG_ENV_IS_IN_FLASH #define CONFIG_ENV_SIZE         0x10000+ #else                          + #define CONFIG_ENV_IS_IN_NAND  + #define CONFIG_ENV_OFFSET       0x40000 /* 256K for u-boot */+ #define CONFIG_ENV_SIZE         0x20000 /* 128K for environment */+ #endif

編譯、燒錄到SDRAM中去,運行。示範:

*** Warning - bad CRC, using default environment
這條提示說明沒有沒有環境變數,使用預設的環境變數,使用pri查看有哪些環境變數:

[TQ2440 #] pri
baudrate=115200
bootdelay=5
ethact=dm9000
ipaddr=10.0.0.110
netmask=255.255.255.0
serverip=10.0.0.1
stderr=serial
stdin=serial
stdout=serial

使用save命令儲存預設的環境變數:

[TQ2440 #] save
Saving Environment to NAND...
Erasing NAND...
Erasing at 0x5c000 -- 100% complete.
Writing to NAND... OK
[TQ2440 #] 
[TQ2440 #] nand dump 40000
Page 00040000 dump:
        fd 4a d7 7a 62 61 75 64  72 61 74 65 3d 31 31 35
        32 30 30 00 62 6f 6f 74  64 65 6c 61 79 3d 35 00
        65 74 68 61 63 74 3d 64  6d 39 30 30 30 00 69 70
        61 64 64 72 3d 31 30 2e  30 2e 30 2e 31 31 30 00
        6e 65 74 6d 61 73 6b 3d  32 35 35 2e 32 35 35 2e
        32 35 35 2e 30 00 73 65  72 76 65 72 69 70 3d 31
        30 2e 30 2e 30 2e 31 00  73 74 64 65 72 72 3d 73
        65 72 69 61 6c 00 73 74  64 69 6e 3d 73 65 72 69
        61 6c 00 73 74 64 6f 75  74 3d 73 65 72 69 61 6c
        00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00

再次燒錄運行,就沒有上面的警告了。在tq2440.h標頭檔中設定環境變數:

#define CONFIG_NETMASK      255.255.255.0+ #define CONFIG_IPADDR       192.168.169.9+ #define CONFIG_SERVERIP     192.168.169.8+ #define CONFIG_ETHADDR      12:34:56:78:9A:BC

添加mtd分區命令

修改tq2440.h檔案,使能該命令宏:

/* * File system */+ #if NONE_FLAG#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+ #else+ #define CONFIG_CMD_MTDPARTS+ define CONFIG_MTD_DEVICE#endif

編譯、燒錄到SDRAM中去,運行。示範:

[TQ2440 #] mtdmtdids not defined, no default present
上述提示位於common/cmd_mtdparts.c檔案1751行
if (mtdids_default) {            debug("mtdids variable not defined, using default\n");            ids = mtdids_default;            setenv("mtdids", (char *)ids);        } else {            printf("mtdids not defined, no default present\n");            return 1;        }
mtdids_default為假時錯誤列印該條資訊,mtdids_default變數在該檔案中定義如下:

/* default values for mtdids and mtdparts variables */#if defined(MTDIDS_DEFAULT)static const char *const mtdids_default = MTDIDS_DEFAULT;#elsestatic const char *const mtdids_default = NULL;#endif#if defined(MTDPARTS_DEFAULT)static const char *const mtdparts_default = MTDPARTS_DEFAULT;#elsestatic const char *const mtdparts_default = NULL;#endif
現在這裡的mtdids_default=NULL,因為未定義MTDIDS_DEFAULT宏。下面定義MTDIDS_DEFAULT宏和MTDPARTS_DEFAULT宏,參考該檔案中最上面注釋部分內容:

 * Examples:
 *
 * 1 NOR Flash, with 1 single writable partition:
 * mtdids=nor0=edb7312-nor
 * mtdparts=mtdparts=edb7312-nor:-
 *
 * 1 NOR Flash with 2 partitions, 1 NAND with one
 * mtdids=nor0=edb7312-nor,nand0=edb7312-nand
 * mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
 *
 */

在tq2440.h標頭檔中定義:

#else#define CONFIG_CMD_MTDPARTS#define CONFIG_MTD_DEVICE+ #define MTDIDS_DEFAULT "nand0=tq2440-0"+ #define MTDPARTS_DEFAULT "mtdparts=tq2440-0:1m(u-boot)," \+     "4m(kernel)," \+     "-(rootfs)"#endif
編譯、燒錄到SDRAM中去,運行。示範:

[TQ2440 #] pri
baudrate=115200
bootdelay=5
ethact=dm9000
ethaddr=12:34:56:78:9A:BC
ipaddr=192.168.169.9
netmask=255.255.255.0
serverip=192.168.169.8
stderr=serial
stdin=serial
stdout=serial

[TQ2440 #] mtdparts
mtdparts variable not set, see 'help mtdparts'
no partitions defined


defaults:
mtdids  : nand0=tq2440-0
mtdparts: mtdparts=tq2440-0:1m(u-boot),4m(kernel),-(rootfs)
[TQ2440 #] mtdparts default
[TQ2440 #] save
[TQ2440 #] mtdparts

device nand0 <tq2440-0>, # parts = 3
 #: name                size            offset          mask_flags
 0: u-boot              0x00100000      0x00000000      0
 1: kernel              0x00400000      0x00100000      0
 2: rootfs              0x03b00000      0x00500000      0

active partition: nand0,0 - (u-boot) 0x00100000 @ 0x00000000











聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.