**
之前选择bootm模式启动boot.im,boot.img带有its格式的header,需要根据header去header。现在直接启动zImage,需要通过do bootz()函数启动。方式如下:
1.1.1. 在uboot目下执行make menuconfig,选中bootz
1.1.2. 选中Command line interface —> Boot commands —> bootz
这个配置其实就相当于在makefile里加了一句话 obj-$(CONFIG_CMD_BOOTZ) += bootz.o,意思是启动时执行bootz.c
看一下我们的uboot/cmd/bootz.c,我们根据
U_BOOT_CMD去调用do_bootz函数,然后调用bootz_start(),bootz_start()去调用bootz_setup()一步步启动内核
/*
* zImage booting support
*/
static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[], bootm_headers_t *images)
{
int ret;
ulong zi_start, zi_end;
printf("---1-------%s ------------------------\n",__func__);
ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
images, 1);
/* Setup Linux kernel zImage entry point */
if (!argc) {
images->ep = load_addr;
debug("* kernel: default image load address = 0x%08lx\n",
load_addr);
} else {
images->ep = simple_strtoul(argv[0], NULL, 16);
debug("* kernel: cmdline image address = 0x%08lx\n",
images->ep);
}
ret = bootz_setup(images->ep, &zi_start, &zi_end);
if (ret != 0)
return 1;
lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
/*
* Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
* have a header that provide this informaiton.
*/
if (bootm_find_images(flag, argc, argv))
return 1;
return 0;
}
#define LINUX_ARM_ZIMAGE_MAGIC 0x016f2818
#define BAREBOX_IMAGE_MAGIC 0x00786f62
struct arm_z_header {
uint32_t code[9];
uint32_t zi_magic;
uint32_t zi_start;
uint32_t zi_end;
} __attribute__ ((__packed__));
int bootz_setup(ulong image, ulong *start, ulong *end)
{
printf("----------%s ------ ------------------\n",__func__);
struct arm_z_header *zi = (struct arm_z_header *)image;
printf("-1---------%s ------zi->zi_magic=%#08x------------------\n",__func__,zi->zi_magic);
if (zi->zi_magic != LINUX_ARM_ZIMAGE_MAGIC &&
zi->zi_magic != BAREBOX_IMAGE_MAGIC) {
#ifndef CONFIG_SPL_FRAMEWORK
puts("zimage: Bad magic!\n");
#endif
return 1;
}
*start = zi->zi_start;
*end = zi->zi_end;
#ifndef CONFIG_SPL_FRAMEWORK
printf("Kernel image @ %#08lx [ %#08lx - %#08lx ]\n",
image, *start, *end);
#endif
return 0;
}
1.1.3. 选中Enable a default value for bootcmd修改bootcmd value为:bootz 0x82100000 0x860f8000:0x01000000
1.1.4. 执行make savedefconfig保存.config到defconfig
1.1.5. 执行cp defconfig configs/finch_fpga_defconfig保存到本地配置文件
1.1.6. 执行cp defconfig configs/finch_fpga_defconfig保存到本地配置文件
make mrproper 清除残留信息
在image.c的1069行可以看到要想支持rootfs.cpio.gz启动,必须先定义CONFIG_SUPPORT_RAW_INITRD
UBOOT下定义CONFIG_SUPPORT_RAW_INITRD
至此设置启动参数bootz zImage地址 ramdisk地址:ramdisk大小 dtb地址即可完成启动
(eg: bootz 0x82100000 0x860f8000:0x01000000 0x833f8000
依据load到sdram的地址,我已经将zImage ramdisk dtb分别下载到内存的0x82100000 0x860f8000:0x01000000 0x833f8000
所以我可以直接加载;
如果是从nand flash读取的话要加“nand read zImage地址 ramdisk地址 dtb地址;bootz zImage地址 ramdisk地址:ramdisk大小 dtb地址”)
从下面这段代码可以看fdt image无法直接传递地址时,需要使能TAG参数
使能TAG参数
Kernel目录下,使能CONFIG_ARM_APPENDED_DTB功能,该功能是将DTB文件拼接到Image的后面,步骤如下:
2.2.1. 执行make finch_fpga_defconfig ARCH=arm
2.2.2. make menuconfig ARCH=arm
2.2.3. 选中Use appended device tree blob to zImage (EXPERIMENTAL)和Supplement the appended DTB with traditional ATAG information
2.2.4. make savedefconfig ARCH=arm保存defconfig
2.2.5. cp defconfig arch/arm/configs/finch_fpga_defconfig