通過u-boot把內核和文件系統燒錄到Nand Flash

前提條件:
板子可以啓動到u-boot環境;
內核文件、文件系統都準備好而且能正常運行;
tftp服務器打開;

測試環境:
AT91SAM9263-EK;
 
設置板子和tftp服務器的ip地址以及板子的mac地址;
U-Boot>setenv ipaddr 192.168.1.2
U-Boot>setenv serverip 192.168.1.100
U-Boot>setenv ethaddr 0:1:2:3:4:5

通過tftp下載內核文件vmlinux和文件系統ramdisk.gz,並將他們寫入Nand Flash中;
先擦除flash
U-Boot>nand scrub 或者 nand erase
下載並寫入flash
U-Boot>tftp 0x22000000 vmlinux
U-Boot>nand write 0x22000000 0x0 0x200000
U-Boot>tftp 0x22000000 ramdisk.gz
U-Boot>nand write 0x22000000 0x400000 0x300000
從Nand Flash讀出內核和文件系統到SDRAM上,注意此處讀出操作可以省,只要上一步的下載地址指定好既可;
U-Boot>nand read 0x22000000 0x0 0x16c58a (vmlinux大小)
U-Boot>nand read 0x20500000 0x400000 0x24bc12 (ramdisk.gz大小)
從SDRAM啓動系統
U-Boot>go 0x22000000
如果能正確運行系統,燒錄文件到Nand Flash成功。
自動啓動(自動從Nand Flash拷貝文件到SDRAM裏),設置U-boot的環境變量:
U-Boot>setenv bootcmd nand read 0x22000000 0x0 0x16c58a/;nand read 0x20500000 0x400000 0x24bc12/;go 0x22000000
U-Boot>saveenv
reset板子即可。
 
附上U-boot下Nand Flash的相關命令(u-boot-<version>/common/cmd_nand.c -- U_BOOT_CMD) :

    "nand - NAND sub-system/n",
    "info - show available NAND devices/n"
    "nand device [dev] - show or set current device/n"
    "nand read[.jffs2] - addr off|partition size/n"
    "nand write[.jffs2] - addr off|partiton size - read/write `size' bytes starting/n"
    " at offset `off' to/from memory address `addr'/n"
    "nand erase [clean] [off size] - erase `size' bytes from/n"
    " offset `off' (entire device if not specified)/n"
    "nand bad - show bad blocks/n"
    "nand dump[.oob] off - dump page/n"
    "nand scrub - really clean NAND erasing bad blocks (UNSAFE)/n"
    "nand markbad off - mark bad block at offset (UNSAFE)/n"
    "nand biterr off - make a bit error at offset (UNSAFE)/n"
    "nand lock [tight] [status] - bring nand to lock state or display locked pages/n"
    "nand unlock [offset] [size] - unlock section/n";

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章