summaryrefslogtreecommitdiff
path: root/tools/mkimage.c
AgeCommit message (Collapse)AuthorFilesLines
2021-09-02mkimage: clarify error message for empty input filesThomas Hebb1-0/+6
Currently, an empty imput file causes `mmap()` to fail, and you get an error like "mkimage: Can't read file.img: Invalid argument", which is extremely unintuitive and hard to diagnose if you don't know what to look for. Add an explicit check for an empty file and provide a clear error message instead. We already bounds check the image size when listing and re-signing existing images, so we only need this check here, when opening data files going into a image. Signed-off-by: Thomas Hebb <tommyhebb@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-07-14mkimage: allow -l to work on block devices on LinuxYann Dirson1-3/+27
When "mkimage -l" was run on a block device it would fail with erroneous message, because fstat reports a size of zero for those: mkimage: Bad size: "/dev/sdb4" is not valid image This patch identifies the "is a block device" case and reports it as such, and if it knows how to determine the size of a block device on the current OS, proceeds. As shown in http://www.mit.edu/afs.new/sipb/user/tytso/e2fsprogs/lib/blkid/getsize.c this is no portable task, and I only handled the case of a modern Linux kernel, which is what I can test. Signed-off-by: Yann Dirson <yann@blade-group.com>
2021-04-14mkimage: Add a 'keyfile' argument for image signingAlexandru Gagniuc1-1/+5
It's not always desirable to use 'keydir' and some ad-hoc heuristics to get the filename of the signing key. More often, just passing the filename is the simpler, easier, and logical thing to do. Since mkimage doesn't use long options, we're slowly running out of letters. I've chosen '-G' because it was available. Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-01-23mkimage: Move padding commands outside of FIT_SIGNATUREJoel Stanley1-5/+6
These commands were disabled when CONFIG_FIT_SIGNATURE is disabled, but they do not depend on crypto support so they can be unconditionally enabled. Signed-off-by: Joel Stanley <joel@jms.id.au>
2020-10-22mkimage: Skip adding non-existent IDs to a listNaoki Hayama1-2/+7
In show_valid_options(), this patch introduces checking whether a category has an entry ID. If not, adding it to a list for output is skipped before calling qsort(). This patch will affect all kinds of image header categories (-A, -C, -O and -T flags). Signed-off-by: Naoki Hayama <naoki.hayama@lineo.co.jp> Reviewed-by: Simon Glass <sjg@chromium.org>
2020-07-25mkimage: Allow updating the FIT timestampSimon Glass1-1/+4
Normally the FIT timestamp is created the first time mkimage is run on a FIT, when converting the source .its to the binary .fit file. This corresponds to using the -f flag. But if the original input to mkimage is a binary file (already compiled) then the timestamp is assumed to have been set previously. Add a -t flag to allow setting the timestamp in this case. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2020-07-24Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"Tom Rini1-4/+1
This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing changes made to 56d37f1c564107e27d873181d838571b7d7860e7. Unfortunately this is causing CI failures: https://travis-ci.org/github/trini/u-boot/jobs/711313649 Signed-off-by: Tom Rini <trini@konsulko.com>
2020-07-20mkimage: Allow updating the FIT timestampSimon Glass1-1/+4
Normally the FIT timestamp is created the first time mkimage is run on a FIT, when converting the source .its to the binary .fit file. This corresponds to using the -f flag. But if the original input to mkimage is a binary file (already compiled) then the timestamp is assumed to have been set previously. Add a -t flag to allow setting the timestamp in this case. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2020-07-17mkimage: Fix error message if write less data then expectedMylène Josserand1-4/+11
Add a new error message in case the size of data written are shorter than the one expected. Currently, it will lead to the following error message: "mkimage: Write error on uImage: Success" This is not explicit when the error is because the device doesn't have enough space. Let's use a more understandable message: "mkimage: Write only 4202432/4682240 bytes, probably no space left on the device" Signed-off-by: Mylène Josserand <mylene.josserand@collabora.com> Reviewed-by: Walter Lozano <walter.lozano@collabora.com>
2020-05-15tools: mkimage: use /* fallthrough */ as neededHeinrich Schuchardt1-1/+1
GCC recognizes /* fallthrough */ if -Wimplicit-fallthrough=3 is enabled. Let's use it consistently. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-04-24mkimage: fit_image: Add option to make fit header alignKever Yang1-2/+12
The image is usually stored in block device like emmc, SD card, make the offset of image data aligned to block(512 byte) can avoid data copy during boot process. eg. SPL boot from FIT image with external data: - SPL read the first block of FIT image, and then parse the header; - SPL read image data separately; - The first image offset is the base_offset which is the header size; - The second image offset is just after the first image; - If the offset of imge does not aligned, SPL will do memcpy; The header size is a ramdon number, which is very possible not aligned, so add '-B size'to specify the align size in hex for better performance. example usage: ./tools/mkimage -E -f u-boot.its -B 0x200 u-boot.itb Signed-off-by: Kever Yang <kever.yang@rock-chips.com> Reviewed-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp> Reviewed-by: Tom Rini <trini@konsulko.com>
2020-04-24tools: mkimage: use common ALIGN to do the size alignKever Yang1-2/+3
The ALIGN() is now available at imagetool.h, migrate to use it. Signed-off-by: Kever Yang <kever.yang@rock-chips.com> Reviewed-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp> Reviewed-by: Tom Rini <trini@konsulko.com>
2019-12-27rockchip: mkimage: support packing optional second level boot-loaderJeffy Chen1-0/+8
Support packing optional second level boot-loader: $ ./tools/mkimage -n rk3399 -T rksd -d \ rk3399_ddr_800MHz_v1.24.bin:rk3399_miniloader_v1.19.bin out -v Adding Image rk3399_ddr_800MHz_v1.24.bin Size 116492(pad to 116736) Adding Image rk3399_miniloader_v1.19.bin Size 88060(pad to 88064) Image Type: Rockchip RK33 (SD/MMC) boot image Init Data Size: 116736 bytes Boot Data Size: 88064 bytes Mainly parse init file and boot file from datafile option, copy them to the image with 2KB alignment. Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
2019-07-18lib: rsa: add support to other openssl engine types than pkcs11Vesa Jääskeläinen1-1/+1
There are multiple other openssl engines used by HSMs that can be used to sign FIT images instead of forcing users to use pkcs11 type of service. Relax engine selection so that other openssl engines can be specified and use generic key id definition formula. Signed-off-by: Vesa Jääskeläinen <vesa.jaaskelainen@vaisala.com> Cc: Tom Rini <trini@konsulko.com>
2019-04-12fdt: Fix mkimage list to try every header typeJordan Hand1-8/+15
Signed-off-by: Jordan Hand <jorhand@microsoft.com> Tested-by: Vagrant Cascadian <vagrant@debian.org> Tested-by: Alex Kiernan <alex.kiernan@gmail.com>
2019-03-08fdt: Fix FIT header verification in mkimage and conduct same checks as bootmJordan Hand1-1/+1
FIT header verification in mkimage was treating a return code as a boolean, which meant that failures in validating the fit were seen as successes. Additionally, mkimage was checking all formats to find a header which passes validation, rather than using the image type specified to mkimage. checkpatch.pl checks for lines ending with '(' and alignment matching open parentheses are ignored to keep with existing coding style. Signed-off-by: Jordan Hand <jorhand@microsoft.com>
2019-01-01tools: add i.MX8M image supportPeng Fan1-0/+7
i.MX8M bootable image type is like i.MX6/7, but there is signed HDMI firmware image in front of A53 bootable image, which is also has an IVT header. Here we also include fit image to generate a bootable image. Signed-off-by: Peng Fan <peng.fan@nxp.com> Signed-off-by: Stefano Babic <sbabic@denx.de>
2018-10-22tools: add i.MX8/8X image supportPeng Fan1-0/+7
i.MX8/8X bootable image type is container type. The bootable image, containers a container set which supports two container. The 1st container is for SECO firmware, the 2nd container needs to include scfw, m4_0/1 image, ACore images per your requirement. Signed-off-by: Peng Fan <peng.fan@nxp.com>
2018-09-11tools: mkimage: Ensure munmap unmaps the same length that was mappedMark Tomlinson1-2/+4
The set_header call in kwbimage.c adds a checksum to the end of the image in addition to setting up the header. It 'helpfully' updates the st_size to match the fact that the file is now longer. However, mkimage uses this length in the munmap call. This can lead to unmapping an extra page, of perhaps required data. When this happens, a SEGV can occur. To prevent this from happening, the munmap call now uses the same length that was passed to mmap. This could also have been fixed by not changing the length in kwbimage.c, however changing it in the main file means that other plugins will also not fall for the same trap. Signed-off-by: Mark Tomlinson <mark.tomlinson@alliedtelesis.co.nz> Signed-off-by: Chris Packham <judge.packham@gmail.com> [cp: resolve checkpatch complaints] Tested-by: Chris Packham <judge.packham@gmail.com>
2018-05-11tools: zynqmpimage: Add bif supportAlexander Graf1-0/+7
The officially described way to generate boot.bin files for ZynqMP is to describe the contents of the target binary using a file of the "bif" format. This file then links to other files that all get packed into a bootable image. This patch adds support to read such a .bif file and generate a respective ZynqMP boot.bin file that can include the normal image and pmu files, but also supports image partitions now. This makes it a handy replacement for the proprietary "bootgen" utility that is currently used to generate boot.bin files with FSBL. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
2018-05-07SPDX: Convert all of our single license tags to Linux Kernel styleTom Rini1-2/+1
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
2018-04-29tools: mkimage: Check for datafile when type is scriptAlex Kiernan1-0/+2
If generating a script image and no datafile has been passed in, mkimage dies with SIGSEGV: #0 __strchr_sse2 () at ../sysdeps/x86_64/multiarch/../strchr.S:32 #1 0x0000000000403818 in main at tools/mkimage.c:503 Add explicit test for datafile to fix this. Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
2018-04-10mkimage: do not fail if there is no print_header functionGuillaume GARDET1-3/+2
Commit 253c60a breaks the exit value of 'mkimage -T rkimage' and print the following error: mkimage: Can't print header for Rockchip Boot Image support: Success It is not a failure to not print headers, so just display the warning message, and finish the function properly. Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr> Cc: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Cc: Simon Glass <sjg@chromium.org> Cc: Tom Rini <trini@konsulko.com> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
2017-07-06mkimage: fix display of image types listBaruch Siach1-1/+5
Since commit 5b9d44df2307f (mkimage: Display a better list of available image types) mkimage usage text suggest to "use -T to see a list of available image types". Unfortunately, commit 02221f29deb8 (mkimage: Convert to use getopt()) broke that feature, because getopt() fails when -T has no option argument. Add a pseudo image type name 'list' that lists all image types. Update the usage text accordingly. Cc: Simon Glass <sjg@chromium.org> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
2017-01-20tools: mkimage: fix sizeof_mismatch found by coveritySven Ebenfeld1-1/+1
Reported-by: Coverity (CID: 155214) Signed-off-by: Sven Ebenfeld <sven.ebenfeld@gmail.com>
2017-01-15mkimage: Add support for signing with pkcs11George McCollister1-3/+7
Add support for signing with the pkcs11 engine. This allows FIT images to be signed with keys securely stored on a smartcard, hardware security module, etc without exposing the keys. Support for other engines can be added in the future by modifying rsa_engine_get_pub_key() and rsa_engine_get_priv_key() to construct correct key_id strings. Signed-off-by: George McCollister <george.mccollister@gmail.com>
2017-01-02tools: mkimage: add firmware-ivt image type for HAB verificationSven Ebenfeld1-0/+32
When we want to use Secure Boot with HAB from SPL over U-Boot.img, we need to append the IVT to the image and leave space for the CSF. Images generated as firmware_ivt can directly be signed using the Freescale code signing tool. For creation of a CSF, mkimage outputs the correct HAB Blocks for the image. The changes to the usual firmware image class are quite small, that is why I implemented that directly into the default_image. Cc: sbabic@denx.de v2-Changes: None Signed-off-by: Sven Ebenfeld <sven.ebenfeld@gmail.com> Reviewed-by: George McCollister <george.mccollister@gmail.com> Tested-by: George McCollister <george.mccollister@gmail.com>
2016-11-06mkimage: Allow including a ramdisk in FIT auto modeTomeu Vizoso1-3/+7
Adds -i option that allows specifying a ramdisk file to be added to the FIT image when we are using the automatic FIT mode (no ITS file). This makes adding Depthcharge support to LAVA much more convenient, as no additional configuration files need to be kept around in the machine that dispatches jobs to the boards. Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com> Cc: Simon Glass <sjg@chromium.org> Cc: Matt Hart <matthew.hart@linaro.org> Cc: Neil Williams <codehelp@debian.org> Reviewed-by: Simon Glass <sjg@chromium.org>
2016-10-31mkimage: Fix missing free() in show_valid_options()Simon Glass1-0/+1
The allocated memory should be freed. Fix it. Signed-off-by: Simon Glass <sjg@chromium.org> Reported-by: Coverity (CID: 150963) Reviewed-by: Tom Rini <trini@konsulko.com>
2016-10-31Fix spelling of "occur".Vagrant Cascadian1-1/+1
Signed-off-by: Vagrant Cascadian <vagrant@debian.org> Acked-by: Angelo Dureghello <angelo@sysam.it> Reviewed-by: Simon Glass <sjg@chromium.org>
2016-08-06mkimage: Fix argument parsing with signature commentKarl Beldan1-1/+1
Inform getopt that '-c' requires a parameter. Fixes: a02221f29deb ("mkimage: Convert to use getopt()") Signed-off-by: Karl Beldan <kbeldan@baylibre.com> Reviewed-by: Tom Rini <trini@konsulko.com>
2016-07-15mkimage: fix missing break for -p switchTeddy Reed1-0/+1
Signed-off-by: Teddy Reed <teddy.reed@gmail.com> Reported-by: Coverity (CID: 150277) Reviewed-by: Tom Rini <trini@konsulko.com>
2016-07-15mkimage: Show item lists for all categoriesSimon Glass1-3/+9
Update the error-handling code for -A, -C and -O to show a list of valid options when an invalid one is provided. Signed-off-by: Simon Glass <sjg@chromium.org> Reported-by: Vinoth Eswaran <evinoth1206@gmail.com> Reviewed-by: Tom Rini <trini@konsulko.com>
2016-07-15mkimage: Use generic code for showing an 'image type' errorSimon Glass1-43/+2
The existing error code only displays image types which are claimed by a particular U_BOOT_IMAGE_TYPE() driver. But this does not seem correct. The mkimage tool should support all image types, so it makes sense to allow creation of images of any type with the tool. When an incorrect image type is provided, use generic code to display the error. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
2016-07-15mkimage: Allow display of a list of any image header categorySimon Glass1-0/+43
Add a generic function which can display a list of items in any category. This will allow displaying of images for the -A, -C, -O and -T flags. At present only -T is supported. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
2016-07-15mkimage: Drop blank line before main()Simon Glass1-1/+0
This is not needed. Drop it. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
2016-07-15mkimage: Drop premature setting of params.fit_image_typeSimon Glass1-1/+0
There is no need to set params.fit_image_type while parsing the arguments. It is set up later anyway. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
2016-07-15mkimage: Require a data file when auto-fit is usedSimon Glass1-0/+2
When auto-fit is used, it is not valid to create a FIT without an image file. Add a check for this to avoid a very confusing error message later ("Can't open (null): Bad address"). Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
2016-07-15mkimage: Explain the auto-fit imagefile special caseSimon Glass1-0/+1
There is a special case in the code when auto-fit is used. Add a comment to make it easier to understand why this is needed. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
2016-07-15mkimage: Honour the default image type with auto-fitSimon Glass1-1/+1
The default image type is supposed to be IH_TYPE_KERNEL, as set in the 'params' variable. Honour this with auto-fit also. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
2016-06-25mkimage: fit: spl: Add an optional static offset for external dataTeddy Reed1-2/+11
When building a FIT with external data (-E), U-Boot proper may require absolute positioning for executing the external firmware. To acheive this use the (-p) switch, which will replace the amended 'data-offset' with 'data-position' indicating the absolute position of external data. It is considered an error if the requested absolute position overlaps with the initial data required for the compact FIT. Signed-off-by: Teddy Reed <teddy.reed@gmail.com>
2016-05-23mkimage: Add a quiet modeSimon Glass1-1/+4
Some build systems want to be quiet unless there is a problem. At present mkimage displays quite a bit of information when generating a FIT file. Add a '-q' flag to silence this. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
2016-05-03mkimage: fix generation of FIT imageAndreas Bießmann1-6/+3
Commit 7a439cadcf3192eb012a2432ca34670b676c74d2 broke generation of SPL loadable FIT images (CONFIG_SPL_LOAD_FIT). Fix it by removing the unnecessary storage of expected image type. This was a left over of the previous implementation. It is not longer necessary since the mkimage -b switch always has one parameter. Tested-by: Lokesh Vutla <lokeshvutla@ti.com> Signed-off-by: Andreas Bießmann <andreas@biessmann.org>
2016-05-03mkimage: fix argument parsing on BSD systemsAndreas Bießmann1-21/+12
The getopt(3) optstring '-' is a GNU extension which is not available on BSD systems like OS X. Remove this dependency by implementing argument parsing in another way. This will also change the lately introduced '-b' switch behaviour. Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2016-03-15mkimage: Support placing data outside the FITSimon Glass1-1/+4
One limitation of FIT is that all the data is 'inline' within it, using a 'data' property in each image node. This means that to find out what is in the FIT it is necessary to scan the entire file. Once loaded it can be scanned and then the images can be copied to the correct place in memory. In SPL it can take a significant amount of time to copy images around in memory. Also loading data that does not end up being used is wasteful. It would be useful if the FIT were small, acting as a directory, with the actual data stored elsewhere. This allows SPL to load the entire FIT, without the images, then load the images it wants later. Add a -E option to mkimage to request that it output an 'external' FIT. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-03-15mkimage: Support adding device tree files to a FITSimon Glass1-2/+36
To make the auto-FIT feature useful we need to be able to provide a list of device tree files on the command line for mkimage to add into the FIT. Add support for this feature. So far there is no support for hashing or verified boot using this method. For those cases, a .its file must still be provided. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-03-15mkimage: Support automatic creating of a FIT without a .itsSimon Glass1-3/+5
At present, when generating a FIT, mkimage requires a .its file containing the structure of the FIT and referring to the images to be included. Creating the .its file is a separate step that makes it harder to use FIT. This is not required for creating legacy images. Often the FIT is pretty standard, consisting of an OS image, some device tree files and a single configuration. We can handle this case automatically and avoid needing a .its file at all. To start with, support automatically generate the FIT using a new '-f auto' option. Initially this only supports adding a single image (e.g. a linux kernel) and a single configuration. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-03-15mkimage: Allow a FIT to include an image of any typeSimon Glass1-5/+28
At present FIT images are set up by providing a device tree source file which is a file with a .its extension. We want to support automatically creating this file based on the image supplied to mkimage. This means that even though the final file type is always IH_TYPE_FLATDT, the image inside may be something else. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-03-14mkimage: Make 'params' staticSimon Glass1-1/+1
This is not used outside mkimage.c, so make this variable static. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-03-14mkimage: Show an error message when usage() is calledSimon Glass1-8/+9
Sometimes incorrect arguments are supplied but the reason is not obvious to the user. Add some helpful messages. Signed-off-by: Simon Glass <sjg@chromium.org>