u-boot-1.1.6 設定新分割槽支援裝置樹
在u-boot命令列執行mtaparts命令
mini2440 :> mtdparts
device nand0 <smdk2440-0>, # parts = 4
#: name size offset mask_flags
0: bootloader 0x00040000 0x00000000 0 // 256K
1: params 0x00020000 0x00040000 0 // 128K
2: kernel 0x00200000 0x00060000 0 // 2M
3: rootfs 0x0fda0000 0x00260000 0 // -
當使用高版本kernel或者BootLoader時發現編譯出來的bin檔案都很大, 加上裝置樹的支援, 現在重新規劃分割槽
#: name size offset mask_flags
0: bootloader 0x00080000 0x00000000 0 // 512K
1: device_tree 0x00020000 0x00080000 0 // 128K
1: params 0x00020000 0x000a0000 0 // 128K
2: kernel 0x00800000 0x000C0000 0 // 8M
3: rootfs 0x0fda0000 0x008C0000 0 // -
需要修改的內容:
(1)檔案系統分割槽
#define CONFIG_BOOTARGS "noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0" -> // rootfs分割槽offset變成了4
#define CONFIG_BOOTARGS "noinitrd root=/dev/mtdblock4 rw init=/linuxrc console=ttySAC0,115200"
(2)啟動引數
原來啟動執行bootm kernel
現在變成 bootm 0x30007FC0 - 0x32000000
其中0x30007FC0 是核心地址, 0x32000000 是裝置樹載入地址
#define CONFIG_BOOTCOMMAND "nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0" -> //
#define CONFIG_BOOTCOMMAND "nand read.jffs2 0x30007FC0 kernel; nand read.jffs2 32000000 device_tree; bootm 0x30007FC0 - 0x32000000"
(3)環境變數offset由0x40000 變成0xa0000
#define CFG_ENV_OFFSET 0x40000 ->
#define CFG_ENV_OFFSET 0xa0000
(4)MTDPARTS_DEFAULT
#define MTDPARTS_DEFAULT "mtdparts=nandflash0:[email protected](bootloader)," \
"128k(params)," \
"2m(kernel)," \
"-(root)"
變成
#define MTDPARTS_DEFAULT "mtdparts=nandflash0:[email protected](bootloader)," \
"128k(device_tree)," \
"128k(params)," \
"8m(kernel)," \
"-(root)"
最後一點:u-boot怎麼把device_tree傳遞給kernel呢?
由r2暫存器
核心啟動時:
theKernel (0, bd->bi_arch_number, bd->bi_boot_params);
theKernel = (void (*)(int, int, uint))30008000);
三個引數分別是r0, r1, r2
原來這三個引數分別是
/*
* mov r0, #0
* ldr r1, =362 // machine-id
* ldr r2, =0x30000100
* mov pc, #0x30008000
*/
根據啟動引數bootm 0x30007FC0 - 0x32000000
判斷獲取最後一個引數傳遞給r2,即可
在do_bootm_linux函式最後新增如下程式碼:
if (argc == 4) { of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16); if (be32_to_cpu(*(ulong *)of_flat_tree) == OF_DT_HEADER) { printf ("\nStarting kernel with device tree at 0x%x...\n\n", of_flat_tree); cleanup_before_linux (); theKernel (0, bd->bi_arch_number, of_flat_tree); } else { printf("Bad magic of device tree at 0x%x!\n\n", of_flat_tree); } }