
On Sun, 5 Nov 2023 at 19:26, Sean Anderson seanga2@gmail.com wrote:
Implementers of SPL_LOAD_IMAGE_METHOD have to correctly determine what type of image is being loaded and then call the appropriate image load function correctly. This is tricky, because some image load functions expect the whole image to already be loaded (CONFIG_SPL_LOAD_FIT_FULL), some will load the image automatically using spl_load_info.read() (CONFIG_SPL_LOAD_FIT/CONFIG_SPL_LOAD_IMX_CONTAINER), and some just parse the header and expect the caller to do the actual loading afterwards (legacy/raw images). Load methods often only support a subset of the above methods, meaning that not all image types can be used with all load methods. Further, the code to invoke these functions is duplicated between different load functions.
To address this problem, this commit introduces a "spl_load" function. It aims to handle image detection and correct invocation of each of the parse/load functions.
Although this function generally results in a size reduction with several users, it tends to bloat boards with only a single user. This is generally because programmers open-coding the contents of this function can make optimizations based on the specific loader. For example, NOR flash is memory-mapped, so it never bothers calling load->read. The compiler can't really make these optimizations across translation units. LTO solves this, but it is only available on some arches. To address this, perform "pseudo-LTO" by inlining spl_load when there are one or fewer users. At the moment, there are no users, so define SPL_LOAD_USERS to be 0.
Signed-off-by: Sean Anderson seanga2@gmail.com
Changes in v6:
- Use pseudo-LTO for spl_load
- Align reads to bl_len
Changes in v5:
- Load the header in spl_load as well
- Don't bother trying to DMA-align the buffer, since we can't really fix it.
Changes in v4:
- Fix format specifiers in debug prints
- Reword/fix some of the doc comments for spl_load
Changes in v3:
- Fix using ffs instead of fls
- Fix using not initializing bl_len when info->filename was NULL
Changes in v2:
- Use reverse-xmas-tree style for locals in spl_simple_read. This is not complete, since overhead depends on bl_mask.
common/spl/spl.c | 10 ++++ include/spl_load.h | 135 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 include/spl_load.h
Reviewed-by: Simon Glass sjg@chromium.org
Definitely a lot of effort on code size!