summaryrefslogtreecommitdiffstats
path: root/common/bootm.c
Commit message (Collapse)AuthorAgeFilesLines
* bootm: add support for booting compressed imagesLucas Stach2021-05-271-0/+93
| | | | | | | | | | | | ARM64 does not have a self extracting image format, but relies on the image being externally compressed with one of the standard compression algorithms. Add support for decompressing the bootm OS image. It is added in common code as it may also be useful for other images/architectures. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Link: https://lore.barebox.org/20210526090216.4003977-2-l.stach@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: bootm: replace printf by pr_err/infoMarco Felsch2021-05-251-44/+44
| | | | | | | | | | | This allows us to control the output behaviour e.g. booting silently to improve boot time. Furthermore it adds a 'ERROR:' prefixed output in case of pr_err which is colored as well (depending on your terminal). This helps us to identify unwanted behaviour. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20210521163435.17365-4-m.felsch@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/spdx'Sascha Hauer2020-12-111-12/+1
|\
| * common: replace license statements with SPDX-License-IdentifiersAhmad Fatoum2020-11-271-12/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | For all files in common/ that already have a license text: - Replace with appropriate SPDX-License-Identifier - Remove empty comment lines around replacement - remove comment completely if only thing remaining is name of file without description Reviewed-by: Roland Hieber <rhi@pengutronix.de> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | bootm: adapt help text and naming for bootm.provide_machine_idAhmad Fatoum2020-11-231-1/+1
|/ | | | | | | | | | | | | The Kconfig help text as well the function name machine_id_set_bootarg() suggest that enabling the Kconfig option is sufficient to have barebox pass the machine id to the kernel. This is not the case, so change the naming/documentation to make this clearer. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Reviewed-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/percent_pe' into masterSascha Hauer2020-10-141-2/+1
|\
| * vsprintf: retire strerrorp in favor of %peAhmad Fatoum2020-09-291-2/+1
| | | | | | | | | | | | | | | | | | strerrorp() is only used along with printf. We now have a format specifier for printing error pointers directly, so use that and remove strerrorp. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | magicvar: Replace BAREBOX_MAGICVAR_NAMED with BAREBOX_MAGICVARSascha Hauer2020-10-021-11/+11
|/ | | | | | | | BAREBOX_MAGICVAR now generates a unique identifier automatically, so we can convert users of BAREBOX_MAGICVAR_NAMED to the simpler BAREBOX_MAGICVAR macro. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: bootm: Add missing check of fit_open_image() return codeAlbert Schwarzkopf2020-09-141-1/+5
| | | | | | | | | Check the return code of fit_open_image() inside bootm_load_initrd(). Without this check, the code works with undefined values of "initrd_size" and "initrd" should fit_open_image() fail. Signed-off-by: Albert Schwarzkopf <a.schwarzkopf@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: add global.bootm.root_dev env var for booting via PARTUUIDRobert Karszniewicz2020-08-201-2/+23
| | | | | | | | | | | | | | | | | | | | Introduces a new env var which specifies which device is the rootfs device to be used in Linux, passed to Linux via bootargs, identified by the rootfs partition's PARTUUID. global.bootm.root_dev supplements global.bootm.appendroot, in that it overrides appendroot's naïve default, which picks the partition that the kernel resides on (global.bootm.image). Example: detect mmc2 global.bootm.image='/mnt/mmc2.0/zImage' global.bootm.appendroot=1 global.bootm.root_dev=/dev/mmc2.1 boot mmc Signed-off-by: Robert Karszniewicz <r.karszniewicz@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* FIT: Parse `load` and `entry` addresses.Christian Mauderer2020-08-141-1/+28
| | | | | | | | | | | | According to the U-Boot documentation for the FIT file format, the load and entry have to be allways defined for a "kernel" or "standalone". But Barebox ignored the parameters. That changes with this patch. For backward compatibility the default values for load or entry are still used if they are not given by the FIT file. Signed-off-by: Christian Mauderer <christian.mauderer@embedded-brains.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/kvx'Sascha Hauer2020-07-271-1/+1
|\
| * common: bootm: allow building with an undefined IH_ARCHClement Leger2020-07-011-1/+1
| | | | | | | | | | | | | | | | | | Some architectures might not want to support uImage. To do so, allow IH_ARCH to be let undefined which will make it possible to compile boot support. Signed-off-by: Clement Leger <cleger@kalray.eu> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | common: bootm: add support for elf file loadingClement Leger2020-06-151-0/+33
|/ | | | | | | | | | This will allows elf loader to directly have an elf file available. Thus filetype_elf bootm handlers will be able to use standard bootm functions and data. 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: bootm: Enforce CONFIG_BOOTM_FORCE_SIGNED_IMAGES for TEE binsAlbert Schwarzkopf2020-04-271-0/+1
| | | | | | | | | Currently, unsigned TEE binaries can be booted. This patch ensures that CONFIG_BOOTM_FORCE_SIGNED_IMAGES is also enforced for TEE binaries. Signed-off-by: Albert Schwarzkopf <a.schwarzkopf@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ARM: bootm: Add some printfs when request_sdram_region() failsSascha Hauer2020-03-251-3/+18
| | | | | | | request_sdram_region() can fail in which case it's interesting which region we tried to request. Add some printfs for it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: allow providing machine id to KernelBastian Krause2019-09-301-0/+19
| | | | | | | | | | | | | | | | | | | | | | By default systemd generates a machine id on first boot and tries to persist it (see `man machine-id`). When the root file system is read-only systemd cannot persist the machine id. In case multiple redundant slots are used the machine id will vary. When not handled explicitly the machine id will also change during system updates. It is possible to pass a machine id to the kernel which will be used by systemd (systemd.machine_id=). If global.bootm.provide_machine_id (or nv.bootm.provide_machine_id) is true then provide the machine id from global.machine_id as systemd.machine_id= parameter to the Kernel. Note that global.machine_id must be set, either by the machine_id_set_bootarg late init call or by setting it manually with nv.machine_id if necessary. Signed-off-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: release tee_resSascha Hauer2019-09-121-0/+2
| | | | | | | | When a tee_res has been acquired it must be released when bootm returns (for dryrun) Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
* ARM: Initial OP-TEE supportSascha Hauer2019-06-071-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | This adds initial support for OP-TEE, see https://www.op-tee.org/ barebox starts in secure mode as usual. When booting a kernel the bootm code also loads the optee_os binary. Instead of jumping into the kernel barebox jumps into the optee_os binary and puts the kernel execution address into the lr register. OP-TEE then jumps into the kernel in nonsecure mode. The optee_os binary is passed with the -t option to bootm or with global.bootm.tee. Optionally OP-TEE can be compiled into barebox using the builtin firmware feature. Enable the Kconfig option and place or link your tee binary as optee.bin into the firmware directory. The amount of SDRAM which is kept free for OP-TEE is configurable. This patch was tested on a i.MX6 Nitrogen6x board. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: Print which file cannot be openedSascha Hauer2018-11-151-7/+4
| | | | | | | | | | | When opening the OS image fails we used to print a message *which* file could not be opened. This message is no longer printed since we now fail in read_file_2 when there is an error. Move the message in the read_file_2 failure path to print it again. file_detect_type() needs no handling for ret < 0, in case of failure it returns filetype_unknown which is handled later, so we can remove the error handling there. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: Split bootm_load_devicetree into two functionsSascha Hauer2018-06-151-26/+43
| | | | | | | | | | | | | It is not always desired to get the devicetree from image data and load it to a SDRAM region at the same time. Sometimes it's enough to just load it to an allocated address (in case the user has no constraints where the devicetree should be placed. This patch splits bootm_load_devicetree into bootm_get_devicetree which returns a pointer to the allocated devicetree and bootm_load_devicetree which loads the devicetree to a specified region. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: Drop data->oftreeSascha Hauer2018-06-151-6/+0
| | | | | | | It's no longer necessary to store the devicetree pointer in struct image_data, it can be replaced with a local variable. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: provide handlers the start of the OS imageSascha Hauer2018-04-041-1/+9
| | | | | | | | | The bootm code needs to read the beginning of the OS image in order to determine the filetype. If it does so already, then we can provide the handlers the buffer. This can help the handlers to find some image metadata before loading the full image. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* FIT: Let user specify the configuration to useSascha Hauer2018-02-081-11/+14
| | | | | | | | | | | | | | | | The images in FIT images can be opened in two different ways. They can be either opened directly based on their names in the images/ node or as part of a configuration based on their names in the corresponding /configuration/ node. So far we only supported the latter. To prepare supporting the former we return a cookie belonging to the configuration from fit_open_configuration() which we use in fit_open_image() to refer to the desired configuration. While at it document fit_open_configuration(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: FIT: do not depend on FIT pre-opened imagesSascha Hauer2018-02-081-14/+32
| | | | | | | | | | When calling fit_open_configuration the FIT code already opens the images "kernel", "ramdisk" and "dtb". This does not fit well into the FIT code, so make the bootm code independent of these pre-opened images so that we can drop the opening from the FIT code in the next step. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* FIT: export fit_open_configuration() and fit_open_image()Sascha Hauer2018-01-181-1/+8
| | | | | | | | | Currently only fit_open() is exported which only opens the predefined images "kernel", "dtb" and "ramdisk". To make the FIT code more usable for other code which may want to open other images export fit_open_configuration() and fit_open_image(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Bootm: remove uimage_close done later in bootm_bootClément Leger2017-12-151-1/+0
| | | | | | | | | | | | | | From 24e24f9998342b23cd8de4145c8098f93c60cdc7 Mon Sep 17 00:00:00 2001 From: Clement Leger <clement.leger@kalray.eu> Date: Thu, 14 Dec 2017 13:29:50 +0100 Subject: [PATCH] Bootm: fix double uimage_close When uimage crc fails, the error handling path call uimage_close in bootm_open_os_uimage and also in bootm_boot. This leads to crash/exception. Keep the main error handling path in bootm_boot and remove uimage_close from bootm_open_os_uimage to avoid double uimage_close. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: bootm_open_initrd_uimage(): propagate error if initrd verification failsMarc Kleine-Budde2017-09-201-0/+1
| | | | | | | | | | If the verification of an initrd inside of an uImage fails an error message is printed but the error is not propagated. Although this is not security relevant, as the verification is currently only a CRC32 check, the error should be returned. This patch fixes the problem. Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Revert "globalvar: make globalvar functions more consistent"Sascha Hauer2017-06-131-1/+1
| | | | This reverts commit 1b4a05c9263ae26083526acfabdea1ef96531a1d.
* globalvar: make globalvar functions more consistentSascha Hauer2017-04-111-1/+1
| | | | | | | | | Similar to the device parameter functions also make the globalvar functions more consistent. This also adds support for readonly globalvars and changes several existing globalvars which should really be readonly to readonly. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: fix magicvar name for global_bootm_verboseEnrico Jorns2017-01-161-1/+1
| | | | | Signed-off-by: Enrico Jorns <ejo@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of_unflatten_dtb(): Check return value with IS_ERRAndrey Smirnov2016-09-051-1/+5
| | | | | | | | Of_unflatten_dtb returns a ERR_PTR value so checking it against NULL is incorrect. Fix it in all of the places where this was happening. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* include: Move bulk of boot.h to bootm.hSascha Hauer2016-07-261-1/+2
| | | | | | | | The majority of the stuff currently in include/boot.h is about bootm code implemented common/bootm.c. To be more consistent move it to a new file include/bootm.h. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: make verbosity controllable via global variableSascha Hauer2016-05-111-0/+5
| | | | | | | | When the bootm code is not called directly by the bootm command it is useful to control the verbosity with a globalvar. This introduces global.bootm.verbose for this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: Move magicvar descriptions to common/bootm.cSascha Hauer2016-05-111-0/+10
| | | | | | | | Now that the bootm code can be used without the command, we have to move the magicvar descriptions from the command code to the common bootm code aswell. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: Add verify mode "available"Sascha Hauer2016-05-101-0/+1
| | | | | | | | | The verify "available" mode checks whatever is available in the booted image, so when an image has a signature, it is checked and must be correct and when an image is hashed, it is also checked for correctness. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: set bootm_verify_mode to correct valueSascha Hauer2016-05-101-0/+4
| | | | | | | | When CONFIG_BOOTM_FORCE_SIGNED_IMAGES is enabled bootm_verify_mode shall be forced to "signature", so set bootm_verify_mode to this value during startup. Otherwise it shows up as "<NULL>" in devinfo. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: Move bootm options to common/KconfigSascha Hauer2016-05-101-4/+4
| | | | | | | | | | | | bootm has a C API, so the bootm options have to depend on the option providing the bootm code (CONFIG_BOOTM), not on the option providing the command (CONFIG_CMD_BOOTM). Fixing the dependencies makes it possible to fully use bootm from C without enabling the bootm command support. This also removes the CMD_ prefix from the options which means we have to update the defconfigs aswell. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: Optionally add a root= option to Kernel command lineSascha Hauer2016-05-041-0/+17
| | | | | | | | | It becomes a common case that the Kernel is loaded from the filesystem which later becomes the rootfs. This adds a possibility to let bootm automatically append the root= option to the kernel command line. This is done when global.bootm.appendroot is true. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: Fix booting uImagesSascha Hauer2016-02-251-6/+12
| | | | | | | | | | | | | | This fixes: 0a37e22d (bootm: use names instead of numbers for image parts) This commit switches to strings for the image numbers for better FIT image support (which uses names instead of numbers). These strings may be NULL when no image number is given. They are used uninitialzed in several places. Introduce a wrapper function to convert the string into a number. Check for NULL here in which case we return 0 which is the correct value. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: Free allocated fdt buffer in error pathHarald Welte2016-02-181-0/+1
| | | | | | | | | It seems like there is a memory leak in an error path of bootm_open_oftree_uimage() where the memory allocated for the fdt is not released again. Signed-off-by: Harald Welte <laforge@gnumonks.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: parse initrd and oftree into correct struct membersLucas Stach2016-02-151-2/+2
| | | | | | | | The code parsing the oftree and initrd file names is clearly wrong, leading to bootm not loading oftree or initrd files any more. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: restore load DT message for plain oftree filesLucas Stach2016-02-151-0/+1
| | | | | | | | This message was dropped when reorganizing the DT loading code, and it's really confusing to miss this. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: Fix resource_size_t format specifierSascha Hauer2016-02-111-2/+2
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2016-02-081-4/+4
|\
| * Convert users of PRINTF_CONVERSION_RESOURCE to %paSascha Hauer2016-01-151-6/+6
| | | | | | | | | | | | | | | | printf now supports printing resource_size_t directly, convert all users of the previously used PRINTF_CONVERSION_RESOURCE over to %pa. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | bootm: Add option to force booting signed imagesSascha Hauer2016-01-261-0/+19
| | | | | | | | | | | | | | | | | | | | | | With CONFIG_BOOTM_FORCE_SIGNED_IMAGES the bootm code will refuse to boot unsigned images. Since currently FIT is the only image type which supports signing, this means with this option we enforce using FIT images. All additionally passed in device trees and initrds will be ignored, so that only the ones from the FIT image can be used. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
* | bootm: add initial FIT supportJan Luebbe2016-01-261-3/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implementation is inspired by U-Boot's FIT support. Instead of using libfdt (which does not exist in barebox), configuration signatures are verified by using a simplified DT parser based on barebox's own code. Currently, only signed configurations with hashed images are supported, as the other variants are less useful for verified boot. Compatible FIT images can be created using U-Boot's mkimage tool. Signed-off-by: Jan Luebbe <jlu@pengutronix.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | bootm: make verifying/hashing configurableSascha Hauer2016-01-261-2/+18
| | | | | | | | | | | | | | | | | | So long struct bootm_data.verify is a bool which enables CRC checking (hashing). Extend this to a enum and add support for signature checking in the same option. This also adds the corresponding globalvar and a -s option to bootm. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | bootm: Initialize bootm_data defaults in single placeSascha Hauer2016-01-261-0/+11
| | | | | | | | | | | | | | | | Both the bootm and the boot code initialize the struct bootm_data with defaults from the bootm global variables. Create a common function for doing this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>