summaryrefslogtreecommitdiffstats
path: root/common/imd.c
Commit message (Collapse)AuthorAgeFilesLines
* scripts: bareboximd: Fix -c optionSascha Hauer2022-02-281-2/+5
| | | | | | | | | | | | | | | | | Using mmap in read_file doesn't work when the same file is written afterwards with write_file. This problem was fixed in 738601e125 ("scripts/common: fix write_file when opened with mmap"). Using mmap in read_file was removed in 07b87a0908 ("scripts/common: Do not mmap in read_file_2()") but then re-introduced for bareboximd in 013e8ea757 ("scripts: bareboximd: Use mmap when possible"). I'll put my brown paper bag on for this :( This patch fixes the issue by explicitly avoiding mmap when the file is written later as done with the -c option to bareboximd Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reported-by: Andrej Picej <andrej.picej@norik.com> Tested-by: Andrej Picej <andrej.picej@norik.com>
* scripts: bareboximd: Use mmap when possibleSascha Hauer2022-02-111-1/+6
| | | | | | | | | Using mmap() in read_file_2 was dropped in the last patch, bring it back in a bareboximd specific function here. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20220211094230.1807262-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: reuse imd_is_crc32()Antony Pavlov2021-11-011-1/+1
| | | | | | Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Link: https://lore.barebox.org/20211028012816.929611-3-antonynpavlov@gmail.com Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bareboximd: Use mmap when possiblySascha Hauer2021-04-141-1/+5
| | | | | | | | | It's hard to believe but there are systems out there that are so sparse with memory that they can't afford 1MiB of RAM to read a file into. Use mmap when possible and fall back to reading into an allocated buffer otherwise. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: change disabled checksum tag info to debugSteffen Trumtrar2021-01-131-1/+1
| | | | | | | | | | | When the checksum tag is disabled the CRC is most likely invalid. And if the checksum tag is disabled and the CRC is actually invalid the user doesn't care for it anyway. This information only confuses the user so make it a debug message. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/spdx'Sascha Hauer2020-12-111-11/+1
|\
| * common: replace license statements with SPDX-License-IdentifiersAhmad Fatoum2020-11-271-11/+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>
* | imd command: Bail out when crc generation/check failsSascha Hauer2020-12-071-4/+9
|/ | | | | | | Generating a IMD crc can fail, so bail out with an error when it fails. Also, when checking a IMD crc the result should be told to the caller. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: add buildsystem version to metadataSteffen Trumtrar2020-09-281-0/+3
| | | | | | | | To have information about the exact state of a barebox binary from userspace, add the buildsystem version to the IMD. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: imd_calculate_crc32: initialize imd_crc to NULLHubert Feurstein2020-09-141-0/+1
| | | | | | | | This fixes a dereference of an uninitialized pointer when imd-crc-token is not found. Signed-off-by: Hubert Feurstein <h.feurstein@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: imd: handle error in imd_write_crc32Steffen Trumtrar2020-05-051-1/+6
| | | | | | | Don't just ignore the return value of write_file. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: remove references to CREDITSUwe Kleine-König2020-04-271-3/+0
| | | | | | | | The CREDITS file was removed from barebox in 2015 by commit 6570288f2d97 ("Remove the CREDITS file"). Remove references to it from several files. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: Use %zu for printing size_tSascha Hauer2020-04-011-1/+1
| | | | | | To avoid compiler warnings Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: add support for checksum generation/verificationSteffen Trumtrar2020-02-101-1/+151
| | | | | | | | | | Add a new imd type "checksum". This type consists of the CRC32 checksum of the whole barebox image minus the checksum itself. The checksum can be written to the imd field with the bareboximd host-tool. It can be verified with said tool or with "imd" on the target. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: replace magicvalue with sizeof(struct)Steffen Trumtrar2020-01-281-3/+3
| | | | | | | Instead of using "8" as the size of an imd_header, use the sizeof operator. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: fix memory leakUlrich Ölmann2019-10-141-6/+14
| | | | | | | Each invocation of 'imd' ate up to 1MB of RAM. Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: Make all pointers into image constSascha Hauer2018-01-301-13/+14
| | | | | | | The IMD code should be readonly and never modify any pointers. Make all pointers const so that const pointers can be passed in to IMD. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: make it work on big-endian machinesAntony Pavlov2016-05-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The commit commit 5e335773e0814173b40873a891964a7858d64688 Author: Sascha Hauer <s.hauer@pengutronix.de> Date: Tue Mar 29 10:06:46 2016 +0200 imd: use struct imd_header * as argument introduces additional imd type checks like this if (!imd_is_string(imd->type)) return NULL; These checks work incorrectly on any big-endian machine because the imd->type field needs addition conversion to little-endian byteorder before use. Here is the imd command output on big-endian qemu-malta: barebox:/ imd /dev/nor0.barebox release: <NULL> build: <NULL> This patch fixes the problem by adding necessary conversion via imd_read_type(). Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* stdio: replace fprintf(stderr,...) with eprintfSascha Hauer2016-04-151-2/+2
| | | | | | | We have a shortcut for fprintf(stderr, so use it. This is done to be able to remove fprintf in the next step. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: Add function to read parametersSascha Hauer2016-04-011-0/+31
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: export functionsSascha Hauer2016-04-011-3/+27
| | | | | | | To make the image metadata API usable for external users export some functions. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: rename imd_search_validate to imd_getSascha Hauer2016-04-011-13/+11
| | | | | | | The name is more suitable for what the function does. Also let the function return a pointer to the imd data found in the buffer. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: string returned from imd_string_data should be constSascha Hauer2016-04-011-6/+10
| | | | | | | imd_string_data() returns the original data, so the string should be const. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: use struct imd_header * as argumentSascha Hauer2016-03-291-15/+16
| | | | | | | | imd_concat_strings() and imd_string_data() are easier to handle when they take a struct imd_header * instead of a struct imd_entry_string *. Change this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imd: provide dummy imd_command_setenvLucas Stach2015-02-121-0/+7
| | | | | | | | | | | | | | If CONFIG_CMD_IMD is not set there is no imd_command_setenv in the barebox binary that can be linked to. Although the whole imd infrastructure will be removed by the linker later in the build process as soon as it figures out that nothing inside barebox is using it, we still have to provide a dummy function to keep the build going. Fixes: In function `imd_command': undefined reference to `imd_command_setenv' Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Add support for metadata in barebox imagesSascha Hauer2014-08-071-0/+322
It's often useful to get some information about a barebox image before starting or flashing it. This patch introduces barebox Image MetaData (IMD). When enabled a barebox image will contain a list of tags containing the desired information. We have tags for: - the barebox release (2014.07.0-00160-g035de50-dirty) - the build timestamp (#741 Mon Jul 28 15:08:54 CEST 2014) - the board model the image is intended for - the device tree toplevel compatible property Also there is an additional generic key-value store which stores parameters for which no dedicated tag exists. In this patch it is used for the memory size an image supports. Since there is no fixed offset in a barebox image which can be used for storing the information, the metadata is stored somewhere in the image and found by iterating over the image. This works for most image types, but obviously not for SoC images which are encoded or encrypted in some way. There is a 'imd' tool compiled from the same sources for barebox, for the compile host and for the target, so the metadata information is available whereever needed. For device tree boards the model and of_compatible tags are automatically generated. Example output of the imd tool for a Phytec phyFLEX image: build: #889 Wed Jul 30 16:08:54 CEST 2014 release: 2014.07.0-00167-g6b2070d-dirty parameter: memsize=1024 of_compatible: phytec,imx6x-pbab01 phytec,imx6dl-pfla02 fsl,imx6dl model: Phytec phyFLEX-i.MX6 Duallite Carrier-Board Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>