From: Sean Anderson <seanga2@gmail.com>
To: Anshul Dalal <anshuld@ti.com>, u-boot@lists.denx.de
Cc: vigneshr@ti.com
Subject: Re: [BUG report] spl: image size check fails in spl_load()
Date: Sat, 15 Feb 2025 12:48:04 -0500 [thread overview]
Message-ID: <8a2961af-fbaa-74f6-8f2a-be9dd5e84a8a@gmail.com> (raw)
In-Reply-To: <20250214111251.2349093-1-anshuld@ti.com>
On 2/14/25 06:12, Anshul Dalal wrote:
> Hi all!
>
> I was trying to implement falcon boot on TI AM62x EVM with the kernel image on
> SD card's filesystem but the following check in `_spl_load` at
> `include/spl_load.h:95` fails to -EIO as per the latest commit [89d3333]:
>
> return read < spl_image->size ? -EIO : 0;
>
> The check seems to be comparing the image size gathered from the header
> (spl_image->size) with the number of bytes read form the loader.
>
> From spl_load.h:
>
> ret = spl_parse_image_header(spl_image, bootdev, header);
> if (ret)
> return ret;
>
> base_offset = spl_image->offset;
> /* Only NOR sets this flag. */
> if (IS_ENABLED(CONFIG_SPL_NOR_SUPPORT) &&
> spl_image->flags & SPL_COPY_PAYLOAD_ONLY)
> base_offset += sizeof(*header);
> image_offset = ALIGN_DOWN(base_offset, spl_get_bl_len(info));
> overhead = base_offset - image_offset;
> size = ALIGN(spl_image->size + overhead, spl_get_bl_len(info));
>
> read = info->read(info, offset + image_offset, size,
> map_sysmem(spl_image->load_addr - overhead, size));
>
> if (read < 0)
> return read;
>
> return read < spl_image->size ? -EIO : 0;
>
> During kernel build process the header size is computed including the BSS
> whereas it's removed when creating the uncompressed image. Therefore the size
> of the uncompressed image on filesystem will be smaller than the size specified
> in the header. Which leads to failure of the above check.
>
> From linux kernel's `arch/arm64/kernel/image.h:63`:
>
> #define HEAD_SYMBOLS \
> DEFINE_IMAGE_LE64(_kernel_size_le, _end - _text); \
> DEFINE_IMAGE_LE64(_kernel_flags_le, __HEAD_FLAGS);
>
> Disabling the check leads to a successful boot directly to the kernel.
> Therefore it seems like the check is non functional as the size in the kernel
> header does not correspond with the file size of the kernel image.
Did this work before v2024.04?
How exactly are you loading your image? E.g. what are the values of
CONFIG_SPL_OS_BOOT
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
CONFIG_SPL_FALCON_BOOT_MMCSD
CONFIG_SPL_FS_FAT
CONFIG_SPL_FS_EXT4
CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
CONFIG_SUPPORT_EMMC_BOOT
From what I can tell, the OS_BOOT path should not call spl_load in the first place.
In any case, the root problem is that the size reported by the kernel is actually the
space the kernel will need when it is loaded, and not the size of the data to load
(which we need). So if we have a short read, we have no way of knowing if the filesystem
is corrupt, the image was truncated while writing, or if it's just missing the bss. And
we still have to rely of the image size so that we can load from e.g. NAND or SPI where
there is no filesystem.
One way to fix this could be to move the length check to spl_load_info->read. This would
involve updating all the callers and callees.
--Sean
next parent reply other threads:[~2025-02-15 17:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250214111251.2349093-1-anshuld@ti.com>
2025-02-15 17:48 ` Sean Anderson [this message]
2025-02-18 6:07 ` [BUG report] spl: image size check fails in spl_load() Anshul Dalal
2025-02-19 15:47 ` Sean Anderson
2025-02-20 5:22 ` Anshul Dalal
2025-02-21 2:18 ` Sean Anderson
2025-02-14 11:16 Anshul Dalal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8a2961af-fbaa-74f6-8f2a-be9dd5e84a8a@gmail.com \
--to=seanga2@gmail.com \
--cc=anshuld@ti.com \
--cc=u-boot@lists.denx.de \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox