summaryrefslogtreecommitdiff
path: root/tools/kwbimage.c
AgeCommit message (Collapse)AuthorFilesLines
2022-01-14tools: kwbimage: Fix mkimage/dumpimage -l argumentPali Rohár1-1/+2
Do not check for kwbimage configuration file when just showing information about existing kwbimage file. The check for kwbimage configuration file is required only when creating kwbimage, not when showing information about image or when extracting data from image. With this change, it is possible to call mkimage -l and dumpimage -l also for existing kwbimage file. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage: Extract main data image without -p arg for dumpimagePali Rohár1-27/+40
When there is no -p argument for dumpimage tool specified, extract the main data image from kwbimage file. This makes dumpimage consistent with other image formats. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage/kwboot: Check ext field for non-zero valuePali Rohár1-1/+1
Despite the official specification, BootROM does not look at the lowest bit of ext field but rather checks if ext field is non-zero. Moreover original Marvell doimage tool puts into the mhdr->ext field the number of extended headers, so basically it sets ext filed to non-zero value if some extended header is present. Fix U-Boot dumpimage and kwboot tools to parse correctly also kwbimage files created by Marvell doimage tool, in the same way as the BootROM is doing it when booting these images. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage: Dump kwbimage config file on '-p -1' optionPali Rohár1-0/+176
To regenerate kwbimage from existing image, it is needed to have kwbimage config file. Add a new option to generate kwbimage config file from existing kwbimage when '-p 1' option is given. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage: Show binary image offset in mkimage -l, in addition to sizePali Rohár1-1/+4
For debugging purposes it is good to know where the binary image would be loaded and also it is needed to know if printed size is image size or the size of header together with image. Make it unambiguous by showing that printed size is not the size of the whole header, but only the size of executable code, and print also the executable offset of this binary image. Load/execute address is the offset relative to the base address (either 0x40004000 or 0x40000000). Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage: Add missing check for maximal value for DATA_DELAYPali Rohár1-0/+4
Data delay is stored as 8-bit number in kwbimage structure. Ensure the given value is at most 255. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage: Enforce 128-bit boundary alignment only for Sheeva CPUPali Rohár1-4/+8
This alignment is required only for platforms based on Sheeva CPU core which are A370 and AXP. Now when U-Boot build system correctly propagates LOAD_ADDRESS there is no need to have enabled 128-bit boundary alignment on platforms which do not need it. Previously it was required because load address was implicitly rounded to 128-bit boundary and U-Boot build system expected it and misused it. Now with explicit setting of LOAD_ADDRESS there is no guessing for load address anymore. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage: Check for maximal kwbimage header sizePali Rohár1-0/+5
BootROM loads kwbimage header to L2-SRAM and BootROM reserve only 192 kB for it. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage: Check the return value of image_headersz_v1()Pali Rohár1-0/+4
Function image_headersz_v1() may return zero on fatal errors. In this case the function already printed an error message. Check the return value of image_headersz_v1() in kwbimage_generate(), and exit on zero value with EXIT_FAILURE. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage: Add support for specifying LOAD_ADDRESS for BINARY commandPali Rohár1-16/+93
ARM executable code included in kwbimage binary header, which is not position independent, needs to be loaded and executed by BootROM at the correct fixed address. Armada BootROMs load kwbimage header (in which the executable code is also stored) at fixed address 0x40004000 or 0x40000000 which is mapped to L2-SRAM (L2 Cache as SRAM). Address 0x40004000 is used on Armada platforms with Sheeva CPU core (A370 and AXP) where BootROM uses MMU with 0x4000 bytes for MMU translation table. Address 0x40000000 is used on all other platforms. Thus the only way to specify load and execute address of this executable code in binary kwbimage header is by filling dummy arguments into the binary header, using the same mechanism we already have for achieving 128-bit boundary alignment on A370 and AXP SoCs. Extend kwbimage config file parser to allow to specify load address as part of BINARY command with syntax: BINARY path_to_binary arg1 arg2 ... argN LOAD_ADDRESS address If the specified load address is invalid or cannot be used, mkimage will throw fatal error and exit. This will prevent generating kwbimage with invalid load address for non-position independent binary code. If no load address is specified, kwbimage will not fill any the dummy arguments, thus it will behave the same as before this change. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage: Add support for specifying CPU corePali Rohár1-0/+26
For other changes it is required to know if CPU core is Sheeva or not. Therefore add a new command CPU for specifying CPU. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage: Preserve order of BINARY, DATA and DATA_DELAY commandsPali Rohár1-20/+38
Preserve the order of BINARY, DATA and DATA_DELAY commands as they appear in the input file. They may depend on each other. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage: Fix generating image with multiple DATA_DELAY commandsPali Rohár1-3/+15
Register set header consists of sequence of DATA commands followed by exactly one DATA_DELAY command. Thus if we are generating image with multiple DATA_DELAY commands, we need to create more register set headers. Fix calculation of image size with multiple DATA_DELAY commands and correctly set pointer to struct register_set_hdr_v1 when initializing new register set header. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage: Deduplicate v1 regtype header finishingPali Rohár1-19/+22
Deduplicate code that finishes OPT_HDR_V1_REGISTER_TYPE header by extracing it into separate function. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-14tools: kwbimage: Mark all local functions as staticPali Rohár1-18/+19
Mark all local functions as static. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2022-01-05tools: kwbimage: Fix checksum calculation for v1 imagesPierre Bourdon1-3/+3
Recent changes caused fields in the image main header to be modified after the header checksum had already been computed. Move the checksum computation to once again be the last operation performed on the header. Fixes: 2b0980c24027 ("tools: kwbimage: Fill the real header size into the main header") Signed-off-by: Pierre Bourdon <delroth@gmail.com> Reviewed-by: Pali Rohár <pali@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
2021-12-26tools: avoid OpenSSL deprecation warningsHeinrich Schuchardt1-0/+2
Our Gitlab CI buildsystem is set up to treat warnings as errors. With OpenSSL 3.0 a lot of deprecation warnings occur. With the patch compatibility with OpenSSL 1.1.1 is declared. In the long run we should upgrade our code to use the current API. A -Wdiscarded-qualifiers warning is muted by casting. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2021-11-10tools: kwbimage: Properly set srcaddr in kwbimage v0Pali Rohár1-0/+22
Field srcaddr in kwbimage v0 needs to be adjusted similarly like in v1. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-11-10tools: kwbimage: Properly calculate and align kwbimage v0 header sizePali Rohár1-8/+16
Kwbimage v0 has similar alignment requirements as v1. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-11-10tools: kwbimage: Fill the real header size into the main headerPali Rohár1-0/+9
Fill the real header size without padding into the main header This allows to reduce final image when converting image to another format which does not need additional padding. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-11-10tools: kwbimage: Align kwbimage header to proper sizePali Rohár1-5/+22
Currently kwbimage header is always aligned to 4096 bytes. But it does not have to be aligned to such a high value. The header needs to be just 4-byte aligned, while some image types have additional alignment restrictions. This change reduces size of kwbimage binaries by removing extra padding between header and data part. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-11-10tools: kwbimage: Do not put final image padding to the image data sizePali Rohár1-9/+21
This change allows to convert image from one format to another without need to include unnecessary padding (e.g. when target image format has smaller alignment requirement as source image format). Do it by storing real image data size without padding to the kwbimage header. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-11-10tools: kwbimage: Align final UART image to 128 bytesPali Rohár1-0/+3
xmodem block size is 128 bytes, therefore it is possible to transfer only images with size multiple of 128 bytes. kwboot automatically pads image with zero bytes at the end to align it to 128 bytes boundary. Do this padding when generating image to allow uploading with other xmodem tools or older kwboot versions. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-11-10tools: kwbimage: Remove unused enums and prototypesPali Rohár1-1/+1
There are more unused enums and function prototypes. Remove them. The function kwbimage_check_params() does not return enum kwbimage_cmd_types, but a boolean value returned as int. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-11-10tools: kwbimage: Fix validation of kwbimage v0Pali Rohár1-37/+43
kwbimage v0 sldo has 32-bit data checksum at the end like kwbimage v1. Use same data checksum validation for both v0 and v1 image types. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-11-10tools: kwbimage: Set BOOT_FROM by default to SPIPali Rohár1-17/+15
kwbimage must have valid blockid member instead of zero value. Thus if config file does not contain BOOT_FROM command, use by default the value for SPI booting (which is probably the most common). Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-11-10tools: kwbimage: Explicitly set version also for kwbimage v0Pali Rohár1-0/+1
For documentation purposes update struct main_hdr_v0 to include information where version of the image must be stored. For kwbimage v0 it obviously must be 0. By default all image header memory is initialized to zero, therefore this change has no functional effect. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-11-10tools: kwbimage: Add support for new commands UART_PORT and UART_MPPPali Rohár1-1/+19
These two commands allow to specify custom setting of UART port used for printing BootROM messages. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-10-28tools: kwbimage: Add support for NAND_PAGE_SIZE command also for v1 imagesPali Rohár1-0/+3
The NAND_PAGE_SIZE command is already supported by mkimage for v0 images, but not for v1 images. A38x and A39x BootROM supports reading NAND flash page size from v1 image in the same way as Kirkwood BootROM from v0 image. It it documented in A38x and A39x Functional Specification. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
2021-10-28tools: kwbimage: Align BIN header executable code to 128-bit boundaryPali Rohár1-17/+34
ARM executable code inside the BIN header on some mvebu platforms (e.g. A370, AXP) must always be aligned with the 128-bit boundary. This requirement can be met by inserting dummy arguments into BIN header. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
2021-10-01tools: kwbimage: Update comments describing kwbimage v1 structuresPali Rohár1-1/+2
These structures are relevant for several other platforms, mention them all. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-10-01tools: kwbimage: Refactor kwbimage header size determinationMarek Behún1-22/+7
Add functions kwbheader_size() and kwbheader_size_for_csum(). Refactor code determining header size to use these functions. Refactor header checksum determining function. Remove stuff that is not needed anymore. This simplifies the code a little and fixes one instance of validating header size meant for checksum instead of whole header size. Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-10-01tools: kwbimage: Refactor image_version()Marek Behún1-4/+4
Rename this function to kwbimage_version() and don't cast argument if not needed. Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-10-01tools: kwbimage: Simplify iteration over version 1 optional headersMarek Behún1-67/+23
Create macro for_each_opt_hdr_v1 and functions opt_hdr_v1_size(), opt_hdr_v1_valid_size(), opt_hdr_v1_ext(), opt_hdr_v1_first() and opt_hdr_v1_next() to simplify iteration over version 1 optional headers. This prevents ugly code repetition and makes it nicer to read. Signed-off-by: Marek Behún <marek.behun@nic.cz>
2021-10-01tools: kwbimage: Fix printf format warningMarek Behún1-1/+1
On 32-bit ARM the compiler complains: tools/kwbimage.c:547: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘unsigned int’ Fix this by using %zu instead of %lu format specifier. Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-01tools: kwbimage: Remove comment about unimplemented register headers in v1 ↵Pali Rohár1-2/+0
images Support for register headers in v1 images was implemented in commit 02ba70ad6822 ("tools: kwbimage: Add support for DATA command also for v1 images"). So remove old comment. Signed-off-by: Pali Rohár <pali@kernel.org> Fixes: 02ba70ad6822 ("tools: kwbimage: Add support for DATA command also for v1 images") Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-01kwbimage: check return value of image_get_csk_indexHeinrich Schuchardt1-1/+1
image_get_csk_index() may return -1 in case of an error. Don't use this value as index. This resolves Coverity CID 338488 Memory - illegal accesses (NEGATIVE_RETURNS) Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Stefan Roese <sr@denx.de> Reviewed-by: Pali Rohár <pali@kernel.org>
2021-09-01kwbimage: check fopen() return valueHeinrich Schuchardt1-0/+11
Always check the return value of fopen(). This resolves Coverity CID 338491: Null pointer dereferences (NULL_RETURNS) Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Stefan Roese <sr@denx.de> Reviewed-by: Pali Rohár <pali@kernel.org>
2021-09-01tools: kwbimage: Use IBR_HDR_* constants instead of raw numbersPali Rohár1-11/+11
There are already IBR_HDR_* constants for these numbers, so use them. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-01tools: kwbimage: Verify size of image dataPali Rohár1-1/+1
Part of image data is 4 byte checksum, so every image must contain at least 4 bytes. Verify it to prevent memory corruptions. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-01tools: kwbimage: Verify size of v0 image headerPali Rohár1-0/+3
Check that extended image header size is not larger than file size. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-01tools: kwbimage: Verify supported image versionPali Rohár1-3/+3
Only image versions 0 and 1 are supported. Verify it in kwbimage_verify_header() function. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
2021-07-31kwbimage: Update help message about how to extract from an existing imagePali Rohár1-1/+1
Extracting is now supported by dumpimage, so mention it in help instead of `kwbimage -x`. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-07-31kwbimage: Add support for extracting images via dumpimage toolPali Rohár1-8/+64
The kwbimage library does not support extracting subimages. Implement it. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-07-31tools: kwbimage: Remove v1 kwbimage SPL padding to CONFIG_SYS_U_BOOT_OFFS bytesPali Rohár1-13/+0
This padding depends on board config file and therefore it makes the mkimage binary tool board specific, which is not correct. One cannot use mkimage tool built as a result for board A to generate images for board B, even if both A and B are on the same platform. This CONFIG_SYS_U_BOOT_OFFS padding was needed when kwbimage v1 contained SPL code which loaded U-Boot proper based on CONFIG_SYS_U_BOOT_OFFS, instead of reading correct offset from kwbimage header. Now that SPL code parses kwbimage header and deterinate correct offset, there is no need for this CONFIG_SYS_U_BOOT_OFFS padding anymore. By removing it we also reduce the size of SPL code and therefore also decrease the final size of v1 kwbimage. This means there is more space for U-Boot proper binary. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Chris Packham <judge.packham@gmail.com> Reviewed-by: Stefan Roese <sr@denx.de>
2021-07-31tools: dumpimage: Show error message when trying to extract data from kwbimagePali Rohár1-0/+5
There is no code for extracting data from kwbimage, so show an error message when user tries this via e.g. dumpimage call: ./tools/dumpimage -T kwbimage -o /tmp/out u-boot-spl.kwb Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-07-31tools: dumpimage: Fix crashing when trying to extract data from kwbimagePali Rohár1-1/+1
Trying to call the following command causes NULL pointer dereference in strlen(): ./tools/dumpimage -T kwbimage -o /tmp/out u-boot-spl.kwb Fix it by checking whether params->imagename is non-NULL before calling strlen(). Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
2021-07-31tools: kwbimage: Do not hide usage of secure header under CONFIG_ARMADA_38XPali Rohár1-22/+0
The mkimage host tool can be used to generate kwbimage v1 image with secure header on host system for A38x plaform also when U-Boot is being compiled for different platform. So there is no reason to not allow compiling of mkimage/kwbimage with secure header support for e.g. x86-64 host. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Chris Packham <judge.packham@gmail.com> Reviewed-by: Stefan Roese <sr@denx.de> Tested-by: Chris Packham <judge.packham@gmail.com>
2021-07-31tools: kwbimage: Add support for a new DATA_DELAY commandPali Rohár1-1/+23
This command is supported only by v1 images and specifies a milliseconds delay after executing some set of DATA commands. The special string value SDRAM_SETUP instructs BootROM to setup SDRAM controller instead of executing delay. SDRAM_SETUP may be specified only once and after the last DATA command. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Chris Packham <judge.packham@gmail.com> Reviewed-by: Stefan Roese <sr@denx.de> Tested-by: Chris Packham <judge.packham@gmail.com>
2021-07-31tools: kwbimage: Add support for DATA command also for v1 imagesPali Rohár1-1/+31
The DATA command is already supported by mkimage for v0 images, but not for v1 images. BootROM code which executes v1 images also supports DATA command via an optional extended v1 header OPT_HDR_V1_REGISTER_TYPE. Implement support for DATA command for v1 images. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Chris Packham <judge.packham@gmail.com> Reviewed-by: Stefan Roese <sr@denx.de> Tested-by: Chris Packham <judge.packham@gmail.com>