summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* Release 2023.11.0HEADv2023.11.0nextmasterRoland Hieber2023-11-244-4/+27
| | | | Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* libdt: prefer first found disk when looking for block devicesAhmad Fatoum2023-11-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | Recent rework introduced a regression for state located in the eMMC user area described by DT fixed partitions. Whereas before, the first device with type "disk" was taken, dt-utils will now iterate over all devices to try to find a matching GPT partition. If it doesn't find any, it will instead take the last device with type "disk", which will be the second boot partition for eMMC devices leading barebox-state to access /dev/mmcblkXboot1 instead of /dev/mmcblkX. Let's fix this regression by restoring the old behavior of preferring the first disk. This may not be totally future proof, but it worked ok for years and a better solution can always be added later with a regular release. Reported-by: Leonard Göhrs <l.goehrs@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Tested-by: Leonard Göhrs <lgo@pengutronix.de> [lxa,stm32mp157c-tac-gen1] Tested-by: Roland Hieber <rhi@pengutronix.de> [riot,imx6s-riotboard] Link: https://lore.pengutronix.de/oss-tools/20231106110405.3209233-1-a.fatoum@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* meson: align libdt-utils version with autotools'Ahmad Fatoum2023-11-241-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Makefile.am has following defines for libtool versioning: LIBDT_CURRENT=6 LIBDT_REVISION=0 LIBDT_AGE=0 along with a comment on how the values were chosen. Copy the comment and the values into the meson.build as well, so appropriate symlinks pointing at the versioned library are created. We forego the extra complexity of having a common file that's read from both build systems as we are intent on phasing out autotools anyway, once wrinkles such as what's fixed here are ironed out. The translation from libtool versioning to major/minor/revision as expected by meson is taken from GNOME's gcab[1]. More information about libtool versioning is available in its documentation[2]. [1]: https://gitlab.gnome.org/GNOME/gcab/-/commit/2c8048f74ec8c088397 [2]: https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html Reported-by: Enrico Jörns <e.joerns@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20231106134907.859194-1-a.fatoum@pengutronix.de Reviewed-by: Roland Hieber <rhi@pengutronix.de> Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* README: provide git format.subjectPrefix line to copyAhmad Fatoum2023-11-241-2/+4
| | | | | | | | | | | | | | | The oss-tools list is shared between a number of projects, so we should always use a subject prefix to make it clear where the patch applies. The README already notes that and references the git man page, but it's more convenient to just provide a command line that can be directly copied and pasted. Cc: Bastian Krause <bst@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Reviewed-by: Roland Hieber <rhi@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20231106112953.3994614-1-a.fatoum@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* Release 2023.08.0v2023.08.0Roland Hieber2023-08-014-3/+126
| | | | Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* Makefile: include meson files in the dist tarballRoland Hieber2023-08-011-0/+8
| | | | | | | | | | Currently the dist tarball still needs to be built by autotools because it adds all the generated files in build-aux/ and m4/ needed for configure, and the pre-built configure script and Makefile as well. However add all the files needed for meson build as well so the tarball can be used with both build systems. Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* Makefile: include missing files in the dist tarballRoland Hieber2023-08-011-2/+8
| | | | Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* README: mention compatibility with the REUSE specificationRoland Hieber2023-07-311-0/+4
| | | | | | Acked-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230731091131.3696307-10-rhi@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* DCO: add SPDX license informationRoland Hieber2023-07-312-0/+4
| | | | | | | | There is nothing prefabricated yet, so use a custom LicenseRef instead. Acked-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230731091131.3696307-9-rhi@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* treewide: add trivial copyright headersRoland Hieber2023-07-3158-0/+67
| | | | | | | | | | 'reuse lint' warns about files without copyright information, and refuses to give us the spec compliance checkmark. Add trivial copyright lines to all remaining files that don't have any yet. Acked-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230731091131.3696307-8-rhi@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* treewide: add GPL-2.0-only SPDX identifiers to files without licenseRoland Hieber2023-07-3150-0/+54
| | | | | | | | | | | | The dt-utils project license has effectively been GPL-2.0-only since commit 2b39a389428224d96bbb (2014-11-27, Sascha Hauer: "COPYING: Change to GPLv2"). Reflect this in the file headers so the license stays with the code in case files get copied around. Link: https://git.pengutronix.de/cgit/tools/dt-utils/commit/?id=2b39a389428224d96bbb Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230731091131.3696307-7-rhi@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* treewide: add CC0-1.0 SPDX identifiers for trivial filesRoland Hieber2023-07-3110-0/+130
| | | | | | | | | | Add license text from the SPDX website [1]. [1]: https://spdx.org/licenses/CC0-1.0.html Acked-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230731091131.3696307-6-rhi@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* treewide: add SPDX identifier to file with Zlib licenseRoland Hieber2023-07-312-1/+20
| | | | | | | | | | | | We don't have any zlib.h anyway, so the line in src/crc32.c is meaningless. Add Zlib license from the SPDX website [1]. [1]: https://spdx.org/licenses/Zlib.html Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230731091131.3696307-5-rhi@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* treewide: add SPDX identifiers to files with GPL-3.0-or-later licenseRoland Hieber2023-07-312-1/+673
| | | | | | | | | | | Use GPL-3.0-or-later license text from the SPDX website [1], and add the boilerplate headers. [1]: https://spdx.org/licenses/GPL-3.0-or-later Acked-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230731091131.3696307-4-rhi@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* treewide: add SPDX identifiers to files with GPL-2.0-or-later licenseRoland Hieber2023-07-318-2/+358
| | | | | | | | | Use the same license text as for GPL-2.0-only, but with different boilerplate headers. Acked-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230731091131.3696307-3-rhi@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* treewide: add SPDX identifiers to files with GPL-2.0-only licenseRoland Hieber2023-07-3118-284/+367
| | | | | | | | | | | | | | | | | | | | | Move the GPL-2.0 license text to the new LICENSES folder, where it will reside next to all other licenses. Add the rest of the license too (see FSF FAQ [1]) and clean up the hard page breaks in the process. Add the standard license dedication and warranty disclaimer too for completeness sake, so we can easily reference the full license terms by using its SPDX identifier, and don't have to carry around the boilerplate headers in the future. However, keep the already existing license headers in files, as recommended in the REUSE FAQ [2]. "COPYING" is probably still referenced somewhere, so make it point to the new location of the GPL. Link: [1] https://www.gnu.org/licenses/gpl-faq.html#GPLOmitPreamble Link: [2] https://reuse.software/faq/#edit-copyright-and-licensing Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230731091131.3696307-2-rhi@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* README: clarify the need for "real names" with the DCO processRoland Hieber2023-07-311-2/+2
| | | | | | | | | | | | | | | The Linux kernel recently changed the wording of "real names" to "known identities" (see commit d4563201f33a022fc035, 2023-02-26, Linus Torvalds: "Documentation: simplify and clarify DCO contribution example language"). In fact, we already credit contributors in our Git history by names that are probably not their "real names". Follow the reasoning in the kernel guidelines in that regard, and adapt our wording accordingly. Link: https://git.kernel.org/torvalds/c/d4563201f33a022fc035 Acked-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230731085129.3688624-1-rhi@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* README: fix Git repository URLRoland Hieber2023-07-311-3/+3
| | | | Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* meson: set optimization level to -O2 by defaultAhmad Fatoum2023-07-311-0/+1
| | | | | | | | | | We shouldn't expect users to override optimization levels, so let's have a sensible default. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Reviewed-by: Roland Hieber <rhi@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230612120754.896995-3-a.fatoum@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* test: add test case with non-existent /dev/fileAhmad Fatoum2023-07-311-0/+26
| | | | | | | | | | | | | | | | When backend points at a device that couldn't be resolved, barebox-state should fail instead of taking another device. This is meant to address issues like the one fixed by commit e7d71f099659 ("libdt: fix of_get_devicepath looking up sibling if device unavailable"), but the error case there can't be reproduced exactly, because loop devices have no common parent. Still one test is better than no test until we start testing in Qemu. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Reviewed-by: Roland Hieber <rhi@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230612120754.896995-2-a.fatoum@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* meson: options: use defaults of type boolean for boolean optionsAhmad Fatoum2023-07-311-4/+4
| | | | | | | | | | | Building with newer meson versions alerts us that specifying defaults with a string type for non-string types is deprecated. This type confusion was not intentional, so fix that. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Reviewed-by: Roland Hieber <rhi@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230612120754.896995-1-a.fatoum@pengutronix.de Signed-off-by: Roland Hieber <rhi@pengutronix.de>
* test: add barebox-state loop block device testsAhmad Fatoum2023-07-3119-0/+1569
| | | | | | | | | | | | | | | | | | | | | | | There's certainly more unit tests to be had, but the biggest ROI is probably feeding barebox-state device trees and verifying that they work. This same use case exists with RAUC too, where sharness (shell test harness) is used to test the rauc executable. Let's import it from there and follow the structure of the RAUC tests to do some basic testing of barebox-state's block device handling. The basic testing flow is: - mount loop devices - compile and supply device tree snippet describing state on loop device to the barebox-state utility - barebox-state is called with verbose output to report which device it uses - tests check correct device was used and basic state reading and writing works. Tested-by: Roland Hieber <rhi@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230531153125.1408092-6-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* libdt: add CONFIG_TEST_LOOPBACKAhmad Fatoum2023-07-314-4/+46
| | | | | | | | | | | | | | We have quite a bit of tricky udev and device tree parsing code that is only tested manually. Best case we would have tests for this in QEMU, but until we do, let's test it with loop devices: The downside is that we can only test block devices and that we need a tiny bit of code that's not used normally, but on the upside, we have tests. :-) Tested-by: Roland Hieber <rhi@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230531153125.1408092-5-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* meson: add simple integration testAhmad Fatoum2023-07-314-0/+47
| | | | | | | | | | It's straight forward to use meson as test runner, so let's compile a very simple test application that links against libdt-utils and verifies crc32 behaves as one would expect. Tested-by: Roland Hieber <rhi@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230531153125.1408092-4-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: add option to lock device nodeAhmad Fatoum2023-07-315-12/+53
| | | | | | | | | | | | Even if /run exists, it may not be world-writable. This is the case on NixOS. Add an alternative option to lock the device node instead. This should eventually be made the default when it has enjoyed more testing. Tested-by: Roland Hieber <rhi@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230531153125.1408092-3-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* Add meson as build systemAhmad Fatoum2023-07-317-0/+293
| | | | | | | | | This adds experimental support for building dt-utils with meson. The hope is that the alternative meson.build will be easier to maintain. Tested-by: Roland Hieber <rhi@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230531153125.1408092-2-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: allow lookup of barebox state partition by Type GUIDAhmad Fatoum2023-07-316-1/+147
| | | | | | | | | | | | | | | | | | The backend device tree property so far always pointed at a partition. Let's allow pointing it at GPT storage devices directly and lookup the correct barebox state partition by the well-known type GUID: 4778ed65-bf42-45fa-9c5b-287a1dc4aab1 The implementation is not as neat as hoped for, because lifetime for barebox cdev and libudev udev_device are quite different and libdt doesn't yet get the latter right. Once we make sure not to leak libudev objects and add cdev_unref stubs to barebox, this can be further simplified by sticking the struct udev_device into struct cdev and determining extra information on demand. Link: https://lore.pengutronix.de/oss-tools/20230607121628.3180139-9-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* libdt: use of_find_device_by_uuid for partuuid lookupAhmad Fatoum2023-07-311-10/+14
| | | | | | | | | | | | With the addition of of_find_device_by_uuid as part of the support for barebox,storage-by-uuid, we don't need to rely on the device symlinks created by 60-persistent-storage.rules and instead can just use libudev directly, which we do elsewhere anyway. This has the added benefit that we unify with the other code paths, where we determine the device path through the struct udev_device. Link: https://lore.pengutronix.de/oss-tools/20230607121628.3180139-8-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: align with barebox use of of_cdev_findAhmad Fatoum2023-07-315-7/+69
| | | | | | | | | | | | | As part of barebox-state by GPT partition type GUID lookup support, state code in barebox needs direct interaction with the cdev, so it can enumerate the child partitions. We have recently added __of_cdev_find with internal linkage, so lets export of_cdev_find with external linkage for outside use. Unlike __of_cdev_find, the new external function will return dynamically allocated memory to avoid consumer code having to know the struct cdev layout. Link: https://lore.pengutronix.de/oss-tools/20230607121628.3180139-7-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* libdt: use block device partition instead of parent if foundAhmad Fatoum2023-07-311-15/+45
| | | | | | | | | | | | | | | | | Linux doesn't parse MTD fixed-partitions described in the device tree for block devices and EEPROMs. For block devices, The dt-utils work around this by doing the lookup in userspace and then arrive at the parent block device along with an offset that is passed along. We can do better though: If there's a partition block device that contains the region we are interested in, we should just be using that. This avoids the issue of triggering a reread of the partition table after writing barebox state because udev is notified that we had been opening the whole block device writable. Tested-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230607121628.3180139-6-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* libdt: factor out __of_cdev_find helperAhmad Fatoum2023-07-311-30/+52
| | | | | | | | | | | | | of_get_devicepath is an exported symbol by libdt, so we shouldn't change its signature or its semantics. Yet, we will want to export more information out of the udev'ification code in future. <dt/dt.h> already declares an opaque struct cdev, so let's add a __of_cdev_find helper that can populate it with the same information that of_get_devicepath would return. In later commits we will define helpers that return and process a struct cdev placed in dynamic memory. Link: https://lore.pengutronix.de/oss-tools/20230607121628.3180139-5-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* libdt: drop broken if-branchAhmad Fatoum2023-07-311-5/+2
| | | | | | | | | | | | | device_find_block_device returns 0 on success, so the way the else if clause is now, only if there is a block device, the code falls through. If there is none, a 0 is returned, but devpath is not populated breaking the contract of the function. Just drop the branch for now and add it back later in a way that works. Fixes: 929ed64cb42f ("of_get_devicepath: make partition finding more robust") Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230607121628.3180139-4-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* libdt: factor out u64 sysattr parsing into helperAhmad Fatoum2023-07-311-7/+35
| | | | | | | | | | We will need to parse two more sysattrs in a follow-up patch, so factor this out for reuse. While at it switch to 64-bit strtoull: This may be more useful for future users and unlike atol doesn't invoke undefined behavior when parsing fails. Link: https://lore.pengutronix.de/oss-tools/20230607121628.3180139-3-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: backend: direct: open block device in read-only mode if possibleAhmad Fatoum2023-07-314-7/+9
| | | | | | | | | | | | | We unconditionally open the device backing a direct bucket in read-write mode. The barebox_state utility already populates struct state_backend_storage::readonly though, which we could consult at device open time. Do so. This could possibly be done for MTD as well, but until that's tested, for now, we do it only for the direct backend meant for use with block devices. Tested-by: Ulrich Ölmann <u.oelmann@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230607121628.3180139-2-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* libdt: fix of_get_devicepath looking up sibling if device unavailableAhmad Fatoum2023-07-311-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of_get_devicepath code flow is split into two: A) Either the device tree node in question has a direct udev_device associated with it B) Or we assume it's a partition and lookup udev_device for the parent first, before finding a child udev_device or setting a partition offset within the parent udev_device. Since v2017.03.0, we have had a fallthrough from case A into case B: If we have a udev_device, but it's neither a EEPROMs, MTDs or block device, we just consider it a partition. This is problematic, because this may result in us pointing at a very different device: - backend points at a SD-Card host. Host is enabled, but SD-Card is not inserted, so no block device - case A fails, so it's assumed it's a partition and case B uses parent SoC bus to lookup appropriate device - We fall through into the second device_find_block_device, which will take the first matching block device across the SoC. So we could end up with the eMMC: a completely different device than what was pointed at. Fixes: 929ed64cb42f ("of_get_devicepath: make partition finding more robust") Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230607080818.715192-1-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* libdt: generalize of_find_device_by_uuid for scoped lookup of all UUIDsAhmad Fatoum2023-07-311-11/+19
| | | | | | | | | | | | | Despite the generic name, of_find_device_by_uuid only handled ID_PART_TABLE_UUID (diskuuid) and ID_PART_ENTRY_UUID (partuuid), but not ID_PART_ENTRY_TYPE (GPT Partition Type UUID). In preparation for doing Type UUID lookups, adjust of_find_device_by_uuid to support all three types of GPT UUIDs. Reviewed-by: Roland Hieber <rhi@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20230605143236.738735-1-a.fatoum@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* libdt: add of_property_write_strings supportMarco Felsch2023-07-313-0/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The function is copied from barebox and based on commit | commit 09cbc3fbdab5f3118062ceeefb0c1b043a75b3fb | Author: Ahmad Fatoum <a.fatoum@pengutronix.de> | Date: Wed Sep 30 14:53:01 2020 +0200 | | of: implement of_property_write_strings for multiple strings | | The current way to set a property with multiple values (e.g. compatible | strings) is to have | | char properties[] = "st,stm32mp157c-dk2\0st,stm32mp157"; | of_set_property(np, "compatible", properties, sizeof(properties), 1); | | Add a new helper to make this easier at the cost of one runtime | reallocation: | | of_property_write_strings(np, "compatible, | "st,stm32mp157c-dk2", "st,stm32mp157", NULL); | | Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20221014164204.3812506-13-m.felsch@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* common: xstrdup: don't panic on xstrdup(NULL)Marco Felsch2023-07-311-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | This ports the following barebox commit | commit bf6ddd6c4dccf01c4a27761c5f73918db578f8d6 | Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | Date: Fri Sep 9 08:37:22 2016 +0200 | | xstrdup: don't panic on xstrdup(NULL) | | Instead return just NULL. This matches the behaviour of kstrdup in the | kernel and xstrdup in busybox. | | This fixes a panic with CONFIG_CMD_MAGICVAR=y and | CONFIG_CMD_MAGICVAR_HELP unset in magicvar_add() where description is | always NULL. | | Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> It is required to have the same logic for the code shared with barebox. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20221014164204.3812506-12-m.felsch@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: fix typos found with codespellMarco Felsch2023-07-311-1/+1
| | | | | | | | | | | | | | | | | This ports the following barebox commit | commit 157e861aa6e93a72018c408e82863a3253550a4d | Author: Yegor Yefremov <yegorslists@googlemail.com> | Date: Fri Mar 20 10:41:19 2020 +0100 | | common: fix typos found with codespell | | Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com> | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20221014164204.3812506-11-m.felsch@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: add SPDX-License-Identifier for files without explicit licenseMarco Felsch2023-07-311-0/+2
| | | | | | | | | | | | | | | | | | | | | This ports the following barebox commit | commit 79cd45e6eb62c0599d82c768fbfe226eaf750340 | Author: Ahmad Fatoum <a.fatoum@pengutronix.de> | Date: Mon Jan 3 13:05:39 2022 +0100 | | treewide: add SPDX-License-Identifier for files without explicit license | | Record GPL-2.0-only as license for all files lacking an explicit license | statement. | | Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> | Link: https://lore.barebox.org/20220103120539.1730644-12-a.fatoum@pengutronix.de | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20221014164204.3812506-10-m.felsch@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: propagate failure to fixup enum32 into DTMarco Felsch2023-07-311-0/+2
| | | | | | | | | | | | | | | | | | | | | This ports the following barebox commit | commit 2628c8a8e1eee3cf6727c0c8a99ff5eec8ba4d1e | Author: Ahmad Fatoum <a.fatoum@pengutronix.de> | Date: Mon Sep 5 11:55:35 2022 +0200 | | state: propagate failure to fixup enum32 into DT | | We assign to ret, but don't use the value anywhere laments the static | analyzer. Remedy that. | | Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> | Link: https://lore.barebox.org/20220905095557.596891-11-a.fatoum@pengutronix.de | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20221014164204.3812506-9-m.felsch@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: remove unused functionMarco Felsch2023-07-311-13/+0
| | | | | | | | | | | | | | | | | | This ports the following barebox commit | commit 418769972dca8ff6af08eabcf47cfe70aaa3cd43 | Author: Sascha Hauer <s.hauer@pengutronix.de> | Date: Mon Nov 19 09:34:19 2018 +0100 | | state: remove unused function | | state_find_type() is unused and doesn't have a prototype. Remove it. | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20221014164204.3812506-8-m.felsch@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: remove param member from state_uint32, state_enum32, state_macMarco Felsch2023-07-312-11/+8
| | | | | | | | | | | | | | | | | | | This ports the following barebox commit | commit 8718fd1f0508ed694569df212333fff9a22b5303 | Author: Christian Eggers <ceggers@arri.de> | Date: Thu Jan 23 13:20:43 2020 +0100 | | state: remove param member from state_uint32, state_enum32, state_mac | | After adding the parameter, the pointer isn't required anymore. | | Signed-off-by: Christian Eggers <ceggers@arri.de> | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20221014164204.3812506-7-m.felsch@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: remove param member from struct state_stringMarco Felsch2023-07-312-4/+4
| | | | | | | | | | | | | | | | | | | This ports the following barebox commit | commit 4f4d6fc426a466109b7f8b20fb2fdfaad9130aa3 | Author: Christian Eggers <ceggers@arri.de> | Date: Thu Jan 23 13:20:41 2020 +0100 | | state: remove param member from struct state_string | | After adding the parameter, the pointer isn't required anymore. | | Signed-off-by: Christian Eggers <ceggers@arri.de> | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20221014164204.3812506-6-m.felsch@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: treat state with all-invalid buckets as dirtyMarco Felsch2023-07-311-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This ports the following barebox commit | commit f41e5160c8618455064a4ff4227105010cd56aaa | Author: Ahmad Fatoum <a.fatoum@pengutronix.de> | Date: Thu Mar 5 08:40:32 2020 +0100 | | state: treat state with all-invalid buckets as dirty | | The state.dirty flag controls whether state_save will actually | persist state. It is cleared when we successfully load or save | state and set on writing a state parameter. | | When the state however becomes corrupt during barebox runtime and | state.dirty == 0, reinitializing the state to defaults is quite | cumbersome: | | 1. We reset twice. After the first reset, the dirty flag is reset | and before the second, state_save will reinitialize to defaults | 2. We write any state variable and then run the state -s command | | Both workarounds are quite obscure, improve the user experience | by having state -l set the dirty flag when it fails, so a subsequent | state -s may persist the default values to state. | | Steps to reproduce: | | barebox$ state -l | state: Using bucket 0@0x00000000 | barebox$ memcpy -s /dev/zero -d /dev/eeprom0.state 0 0 0x400 | barebox$ state -s | barebox$ state -l | ERROR: state: No meta data header found | ERROR: state: No meta data header found | ERROR: state: No meta data header found | ERROR: state: Failed to find any valid state copy in any bucket | ERROR: state: Failed to read state with format raw, -2 | state: No such file or directory | | Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20221014164204.3812506-5-m.felsch@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: backend_storage: deal gracefully with runtime bucket corruptionMarco Felsch2023-07-311-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This ports the following barebox commit | commit dc5100e6ba686fafd5570ce6d972383f047c7313 | Author: Ahmad Fatoum <a.fatoum@pengutronix.de> | Date: Thu Mar 5 08:40:31 2020 +0100 | | state: backend_storage: deal gracefully with runtime bucket corruption | | Corrupting an already selected bucket and then reading it again will | crash barebox when it attempts the refresh: | | barebox$ state -l | barebox$ mw -d /dev/eeprom0.state 0 0x42 | barebox$ state -l | ERROR: state: No meta data header found | state: Using bucket 1@0x00000040 | unable to handle NULL pointer dereference at address 0x00000000 | pc : [<4fe4f1ea>] lr : [<4fe0bcb1>] | sp : 4ffefd5c ip : 00000000 fp : 2ff68f04 | r10: 4ffefdc8 r9 : 4b434d63 r8 : 30155f50 | r7 : 00000024 r6 : 2ff68b60 r5 : 2ff68e90 r4 : 00000000 | r3 : 00000024 r2 : 00000024 r1 : 30155f50 r0 : 00000000 | Flags: Nzcv IRQs off FIQs off Mode SVC_32 | WARNING: [<4fe4f1ea>] (memcmp+0x14/0x1a) from [<4fe0bcb1>] (bucket_refresh.isra.0+0x4d/0x78) | WARNING: [<4fe0bcb1>] (bucket_refresh.isra.0+0x4d/0x78) from [<4fe0be1d>] (state_storage_read+0xd1/0x104) | WARNING: [<4fe0be1d>] (state_storage_read+0xd1/0x104) from [<4fe0a5bd>] (state_do_load+0x1d/0x78) | WARNING: [<4fe0a5bd>] (state_do_load+0x1d/0x78) from [<4fe04137>] (execute_command+0x23/0x4c) | | The memcmp called here is an optimization to skip I/O if the used bucket | and the one to be refreshed compare equal. Unfortunately, if the now | corrupt bucket was previously the used one, bucket->len will hold the | old value and we'll run into a NULL pointer dereference. | | While this is quite inconvenient, it appears it doesn't affect | correctness: after the reset, the corrupt bucket will be refreshed | as expected. | | Improve upon this by setting the length to zero when we are NULLing the | buffer. The zero length of the corrupted bucket will then compare unequal | to used_bucket->len in bucket_refresh() and ensure we will always refresh | the buffer if it becomes corrupted without an intermittent reset. | | Fixes: 238008b4bd8f ("state: Drop cache bucket") | Cc: Enrico Jörns <ejo@pengutronix.de> | Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20221014164204.3812506-4-m.felsch@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: backend_raw: fix ignoring unpack failuresMarco Felsch2023-07-311-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | This ports the following barebox commit | commit 9866966ef9b38bf49276c67f7e258bc2a8df55eb | Author: Marco Felsch <m.felsch@pengutronix.de> | Date: Wed Aug 25 16:49:04 2021 +0200 | | state: backend_raw: fix ignoring unpack failures | | This is required to inform the state framework that the state variable | set have changed and we need to write the new variable set. Without this | fix the new variable set is never written since the state never sets | dirty=1 and so state_save() will return early without saving the new | variable set. | | Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> | Link: https://lore.barebox.org/20210825144904.4929-1-m.felsch@pengutronix.de | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20221014164204.3812506-3-m.felsch@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: Remove duplicate incudesMarco Felsch2023-07-311-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This ports the following barebox commit | commit 870a96a80ba69f2e7d0312a84adecb70bd11ae4a | Author: Alexander Shiyan <eagle.alexander923@gmail.com> | Date: Tue Jun 7 08:19:57 2022 +0300 | | treewide: Remove duplicate incudes | | Fix warning fwterated by checkincludes.pl: | ./net/nfs.c: libgen.h is included more than once. | ./net/ifup.c: globalvar.h is included more than once. | ./crypto/rsa.c: asm/types.h is included more than once. | ./lib/decompress_unlz4.c: linux/decompress/mm.h is included more than once. | ./scripts/stb_image.h: stdio.h is included more than once. | ./scripts/kwbimage.c: unistd.h is included more than once. | ./scripts/common.c: sys/types.h is included more than once. | ./scripts/bareboximd.c: sys/types.h is included more than once. | ./scripts/bareboximd.c: sys/mman.h is included more than once. | ./fs/pstore/ram_core.c: linux/rslib.h is included more than once. | ./fs/pstore/fs.c: fs.h is included more than once. | ./fs/pstore/fs.c: linux/pstore.h is included more than once. | ./fs/nfs.c: fs.h is included more than once. | ./fs/uimagefs.c: fs.h is included more than once. | ./fs/fs.c: command.h is included more than once. | ./arch/sandbox/board/hostfile.c: linux/err.h is included more than once. | ./arch/sandbox/board/devices.c: mach/linux.h is included more than once. | ./arch/sandbox/os/common.c: signal.h is included more than once. | ./arch/arm/boards/zii-imx51-rdu1/board.c: envfs.h is included more than once. | ./arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c: generated/mach-types.h is | ./arch/arm/mach-stm32mp/ddrctrl.c: mach/stm32.h is included more than once. | ./arch/arm/mach-imx/cpu_init.c: common.h is included more than once. | ./arch/arm/mach-imx/imx8m.c: mach/imx8m-ccm-regs.h is included more than once. | ./common/efi/payload/init.c: efi.h is included more than once. | ./common/state/backend_format_raw.c: common.h is included more than once. | ./common/state/backend_format_raw.c: crc.h is included more than once. | ./common/hush.c: libbb.h is included more than once. | ./drivers/spi/atmel-quadspi.c: linux/clk.h is included more than once. | ./drivers/spi/atmel-quadspi.c: linux/err.h is included more than once. | ./drivers/net/virtio.c: net.h is included more than once. | ./drivers/net/phy/phy.c: linux/phy.h is included more than once. | ./drivers/net/cpsw.c: net.h is included more than once. | ./drivers/virtio/virtio_pci_common.h: linux/list.h is included more than once. | ./drivers/usb/host/ohci-hcd.c: dma.h is included more than once. | ./drivers/usb/gadget/fsl_udc.c: dma.h is included more than once. | ./drivers/nvmem/eeprom_93xx46.c: spi/spi.h is included more than once. | ./drivers/nvmem/eeprom_93xx46.c: of.h is included more than once. | ./drivers/video/imx-ipu-v3/imx-ldb.c: linux/clk.h is included more than once. | ./drivers/video/imx-ipu-v3/imx-hdmi.c: linux/clk.h is included more than once. | ./drivers/video/omap.c: common.h is included more than once. | ./drivers/mtd/nand/nand_s3c24xx.c: asm/sections.h is included more than once. | ./drivers/clk/imx/clk-imx6sx.c: linux/clk.h is included more than once. | ./drivers/clk/imx/clk-imx6sl.c: linux/clk.h is included more than once. | ./commands/bootm.c: of.h is included more than once. | | Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com> | Link: https://lore.barebox.org/20220607051957.2497-1-eagle.alexander923@gmail.com | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20221014164204.3812506-2-m.felsch@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* state: automatically find state.dtb in the ESPMichael Olbrich2023-07-311-0/+25
| | | | | | | | | | | | | Systemd mounts the EFI System Partition (ESP) to /boot or /efi. So look there for the state.dtb when the devicetree in sysfs/procfs is not available. This way barebox-state can be used on EFI systems without manually specifying the devicetree file. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20220511082125.4187531-4-m.olbrich@pengutronix.de Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* libdt: add support for barebox,storage-by-uuidMichael Olbrich2023-07-311-5/+64
| | | | | | | | Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> Tested-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.pengutronix.de/oss-tools/20220511082125.4187531-3-m.olbrich@pengutronix.de [afa: removed ultimately unused ret, outpath variables] Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>