This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How can I extract the kernel size from uImage?

All my images are located on a NAND flash and I boot my device from it. The problem is that it takes a VERY long time for U-BOOT to copy the uImage file before executing it from the RAM.

When I configure the U-BOOT, there is a parameter to specify the image's size:

"nand_img_siz=0x500000\0"

and my goal here is to make this a dynamic parameter. This 0x500000 is the maximum size that the uImage file can reach.

So, is there a way to read the uImage file to check for its size? Where is this information located?

Thanks,

Davi

  • The uImage file should be a zImage or Image with a u-boot specific header. The iminfo command parses the header from an image in memory and prints the header. You can trace through the u-boot code to see the structure of the header. That's probably not what you want. The nboot command should load an image from NAND into memory without actually specifying the image size.

  • Following your advice I found the function image_get_data_size that should give me a way to read uImage's header. I'm still trying to make it work, but nevertheless thanks for the tip!

    DAVI

  • In case anyone ever needs the same optimization, here is what I added to the file "common/cmd_bootm.c".

    This code adds another command to u-boot responsible to update the value of nand_img_siz, the parameter used to copy a determined number of bytes from the NAND to the RAM. Feel free to modify it. Don't forget to call the new commnad (imzise) before calling bootm.

    int do_imsize(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
    {
       return image_size(0x82000000);
    }

    static int image_size(ulong addr)
    {
       void *hdr=(void*)addr;
       int size;
       char str[29]; /* 29 = strlen("setenv nand_img_siz 0x500000")+'\0' */

       run_command("nand read.i 0x82000000 ${nand_src_addr} 0x10",0);

       size=image_get_data_size(hdr)+0x40; /* 64 bytes to complete uImage's real size */

       if(size>0x500000) {
          size=0x500000;
          printf("ERROR: An error occurred while reading the image's size... Loading default value\n");
       }

       sprintf(str,"setenv nand_img_siz 0x%X",size);
       run_command(str,0);

       return 0;
    }

    U_BOOT_CMD(
       imsize, CONFIG_SYS_MAXARGS, 1, do_imsize,
       "update the environment variable nand_img_siz with the image's exact size",
       ""
    );

  • The nboot command might do something similiar. Never used it myself. Might not be seeing the difference.