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 0x00010000 0x00080000 0 // 64K
1: params 0x00010000 0x00090000 0 // 64K
2: kernel 0x00500000 0x000a0000 0 // 5M
3: rootfs 0x0fda0000 0x0085a0000 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:256k@0(bootloader)," \ "128k(params)," \ "2m(kernel)," \ "-(root)"
变成
#define MTDPARTS_DEFAULT "mtdparts=nandflash0:512k@0(bootloader)," \ "64k(device_tree)," \ "64k(params)," \ "5m(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); } }
添加头文件
#include <ft_build.h>