summaryrefslogtreecommitdiffstats
path: root/common/elf.c
Commit message (Collapse)AuthorAgeFilesLines
* common: elf: support loading to address 0Ahmad Fatoum2023-09-211-6/+11
| | | | | | | | | | | | | | Many platforms have DRAM starting at address 0, which clashes with barebox placing kernel images there, as barebox does that before shutting down and turning off the MMU. The <zero_page.h> header allows temporarily disabling the faulting zero page and is already used for boot other types of kernel images, so use it for ELF images as well. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230913125715.2142524-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: elf: use proper field to get segment memory sizeDenis Orlov2023-03-161-4/+3
| | | | | | | | | | | | | | | | For a program header, the value of 'p_filesz' may be less than the one of 'p_memsz', in which case the leftover amount of space should be filled with zeroes. This is done correctly when loading elf to memory. However, when we are requesting memory beforehand we do pass the value of 'p_filesz', instead of 'p_memsz', to 'request_sdram_region', resulting in potentially smaller amount of memory to be reserved. As 'p_memsz' is always greater or equal to 'p_filesz', use only the former for checking memory requirements in 'request_elf_segment'. Signed-off-by: Denis Orlov <denorl2009@gmail.com> Link: https://lore.barebox.org/20230315101126.4101087-1-denorl2009@gmail.com Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: replace errno_str() with %m printf format specifierAhmad Fatoum2022-10-111-7/+6
| | | | | | | | | | | Both errno_str() and printf("%m" end up calling strerror(). %m is more convenient to use, so switch over all instances to it. No functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20221010061122.2084009-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: elf: add elf_load_binaryClement Leger2022-01-181-22/+61
| | | | | | | | | | In order to load elf from a binary buffer, add elf_load_binary. This will be used by FIT support to allow loading an elf from FIT. Signed-off-by: Clement Leger <clement.leger@bootlin.com> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Link: https://lore.barebox.org/20220117221917.26970-5-jmaselbas@kalray.eu Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: elf: add elf_open, elf_close and elf_loadClement Leger2020-06-151-13/+7
| | | | | | | | | In order to integrate elf loading into bootm command, split elf opening from elf loading. Signed-off-by: Clement Leger <cleger@kalray.eu> Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: elf: load elf directly from fileClement Leger2020-06-151-35/+185
| | | | | | | | | | | | | | Currently, elf file must be loaded into a buffer and then passed to elf_load_image. This requires to copy the whole elf file before booting it. This commit allows to pass the filename directly and will allocate data only for the elf header (elf header + program headers). This will then be used to load the elf data from the file without copying it in an intermediate buffer. Elf segments are first parsed into a list and are then loaded from the file in a second time. Signed-off-by: Clement Leger <cleger@kalray.eu> Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: elf: check number of elf program headersClement Leger2020-06-151-0/+5
| | | | | | | | | An elf file without program headers should not be loaded. Add a check for such cases. Signed-off-by: Clement Leger <cleger@kalray.eu> Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: elf: use calloc instead of xzallocClement Leger2020-06-151-1/+4
| | | | | | | | This failure can be handled grecefully, use standard calloc. Signed-off-by: Clement Leger <cleger@kalray.eu> Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: elf: fix warning on 32 bits architecturesClement Leger2020-06-151-1/+1
| | | | | | | | | | | When pointers are 32 bits wide and we cast a potentially 64 bits value in it, the compiler will yield an error. Cast that value first into a phys_addr_t to match the architecture pointer size and then in a void *. Signed-off-by: Clement Leger <cleger@kalray.eu> Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: elf: add computation of elf boundariesClement Leger2020-06-151-0/+7
| | | | | | | | | | In order to correctly load an initrd or a device tree after an elf file, we need to know its boundaries. This commit adds support for that and allow the bootm implementations to use it for memory loading. Signed-off-by: Clement Leger <cleger@kalray.eu> Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* elf: add 64 bits elf loading supportClement Leger2019-09-061-22/+23
| | | | | | | | | | | | | | | | This patch add elf64 loading support to the elf loader. Since elf32 and elf64 uses completely different types, to avoid copying all the code and simply replace elf32 with elf64, use a macro which will return the appropriate field for each type of header. This macro generates getter for elf structures according to the class of the loaded elf. All direct elf struct dereference are then replaced by call to generated functions. This allows to keep a common loader code even if types are different. Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Clement Leger <cleger@kalray.eu> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* add basic ELF parserOleksij Rempel2018-06-181-0/+145
This parser is needed for kernel boot support on MIPS and can potentially reused on other platforms. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>