[U-Boot] Linux boot and list loading feature

Simon Schwarz simonschwarzcor at googlemail.com
Mon Aug 1 13:20:53 CEST 2011


Hi Aneesh,

I am working on the OS booting right now and have a bigger change of 
your code in spl.c in mind.

Hope you can say one or two words what you think about it.

THE PROBLEM
For the direct OS boot and in some other situations - env image e.g., I 
have to load more than one image in SPL.

This can be done by hardcoding these cases and use #ifdef or ifs to 
switch between them. Or I can implement a general image loading with lists.
(This was discussed here: 
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/102345)

I already implemented the list for NAND - and now start prototyping it 
also for MMC. There will be some change to your spl.c-code so I decided 
to ask what you think about it.

These are the modifications in the board config:

/* Assemble boot lists */
/* Last image in list is image to boot! */
/* NAND boot lists */
#define CONFIG_SPL_NAND_OS_LOAD {CONFIG_CMD_SAVEBP_NAND_OFS, \
                                         CONFIG_SYS_NAND_SPL_KERNEL_OFFS}

#ifdef CONFIG_NAND_ENV_DST
#ifdef CONFIG_ENV_OFFSET_REDUND
#define CONFIG_SPL_NAND_UBOOT_LOAD {CONFIG_ENV_OFFSET_REDUND, \
                                         CONFIG_ENV_OFFSET, \
                                         CONFIG_SYS_NAND_U_BOOT_OFFS}
#endif
#define CONFIG_SPL_NAND_UBOOT_LOAD {CONFIG_ENV_OFFSET, \
                                         CONFIG_SYS_NAND_U_BOOT_OFFS}
#else
#define CONFIG_SPL_NAND_UBOOT_LOAD {CONFIG_SYS_NAND_U_BOOT_OFFS}
#endif

/* MMC RAW boot lists */
#define CONFIG_SPL_MMCSD_RAW_OS_LOAD {0x0, 0x0} /* XXX: define me */
#define CONFIG_SPL_MMCSD_RAW_UBOOT_LOAD {\
                         CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR}

/* MMC RAW boot lists */
#define CONFIG_SPL_MMCSD_FAT_OS_LOAD {"uImage", "fdt_params.img"}
#define CONFIG_SPL_MMCSD_FAT_UBOOT_LOAD {CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME}

Essentially just putting together the lists for all the different boot 
devices/modes.

Your mmc_load_image_raw will then look like this:
static void mmc_load_image_raw(struct mmc *mmc)
{
         u32 image_size_sectors, err;
         const struct image_header *header;
         uint32_t i;
#ifdef CONFIG_SPL_OS_BOOT
         uint32_t load_list_os[] = CONFIG_SPL_MMCSD_RAW_OS_LOAD;
#endif
         uint32_t load_list_uboot[] = CONFIG_SPL_MMCSD_RAW_UBOOT_LOAD;
         uint32_t *load_list = load_list_uboot;

         header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
                                                 sizeof(struct 
image_header));

#ifdef CONFIG_SPL_OS_BOOT
         if (!uboot_key())
                 load_list = load_list_os;
#endif

         for(i = 0; i < N_LOAD_LIST_ENTRYS; i++) {
                 /* read image header to find the image size & load 
address */
                 err = mmc->block_dev.block_read(0, load_list[i], 1,
                         (void *)header);
                 if (err <= 0)
                         goto end;
                 parse_image_header(header);
                 /* convert size to sectors - round up */
                 image_size_sectors = (image_size + MMCSD_SECTOR_SIZE - 1) /
                         MMCSD_SECTOR_SIZE;
                 /* Read the header too to avoid extra memcpy */
                 err = mmc->block_dev.block_read(0,
                         load_list[i], image_size_sectors, 
                                (void *)image_load_addr);
         }

end:
         if (err <= 0) {
                 printf("spl: mmc blk read err - %d\n", err);
                 hang();
         }
}

This is just a protoype - quick, dirty & untested. I would be happy to 
hear what you think about the approach.

Regards
Simon


More information about the U-Boot mailing list