[OSS-Tools] [PATCH 4/5] libdt: add CONFIG_TEST_LOOPBACK

2023-05-31 Thread Ahmad Fatoum
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

[OSS-Tools] [PATCH 2/5] state: add option to lock device node

2023-05-31 Thread Ahmad Fatoum
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. Signed-off-by: Ahmad Fatoum --- configure.ac | 9 +

[OSS-Tools] [PATCH 1/5] Add meson as build system

2023-05-31 Thread Ahmad Fatoum
This adds experimental support for building dt-utils with meson. The hope is that the alternative meson.build will be easier to maintain. Signed-off-by: Ahmad Fatoum --- .gitignore| 1 + README| 20 ++ check-news.sh | 82 meson.build

[OSS-Tools] [PATCH 3/5] meson: add simple integration test

2023-05-31 Thread Ahmad Fatoum
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. Signed-off-by: Ahmad Fatoum --- README | 1 + meson.build | 2 ++ test/crc32.c | 18

[OSS-Tools] [PATCH 5/5] test: add barebox-state loop block device tests

2023-05-31 Thread Ahmad Fatoum
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

[OSS-Tools] [PATCH 0/5] Add meson support and first test suite

2023-05-31 Thread Ahmad Fatoum
The barebox,state binding is quite complex and we have a lot of udev parsing code that can only be exercised by manually running barebox-state on the target. Make development less error prone, by adding tests for the block device bindings. EEPROM and MTD can follow later. Tests are executed by

[OSS-Tools] [PATCH 5/8] libdt: use block device partition instead of parent if found

2023-05-31 Thread Ahmad Fatoum
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

[OSS-Tools] [PATCH 6/8] state: align with barebox use of of_cdev_find

2023-05-31 Thread Ahmad Fatoum
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

[OSS-Tools] [PATCH 2/8] libdt: factor out u64 sysattr parsing into helper

2023-05-31 Thread Ahmad Fatoum
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. Signed-off-by: Ahmad Fatoum --- src/libdt.c | 42

[OSS-Tools] [PATCH 0/8] state: allow lookup of barebox state partition by Type GUID

2023-05-31 Thread Ahmad Fatoum
This implements the binding extension introduced to barebox here: https://lore.barebox.org/barebox/20230531145927.1399282-1-a.fat...@pengutronix.de/T/#t With this, barebox,state backend can optionally point at a device instead of a partition. If this device is GPT-partitioned and has a partition

[OSS-Tools] [PATCH 8/8] state: allow lookup of barebox state partition by Type GUID

2023-05-31 Thread Ahmad Fatoum
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,

[OSS-Tools] [PATCH 4/8] libdt: factor out __of_cdev_find helper

2023-05-31 Thread Ahmad Fatoum
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. already declares an opaque struct cdev, so let's add a __of_cdev_find helper that can populate it with

[OSS-Tools] [PATCH 1/8] state: backend: direct: open block device in read-only mode if possible

2023-05-31 Thread Ahmad Fatoum
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

[OSS-Tools] [PATCH 7/8] libdt: use of_find_device_by_uuid for partuuid lookup

2023-05-31 Thread Ahmad Fatoum
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

[OSS-Tools] [PATCH 3/8] libdt: drop broken if-branch

2023-05-31 Thread Ahmad Fatoum
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 back it later in

Re: [OSS-Tools] [PATCH v4 2/3] libdt: add support for barebox, storage-by-uuid

2023-05-31 Thread Ahmad Fatoum
Hello Michael, On 11.05.22 10:21, Michael Olbrich wrote: > Signed-off-by: Michael Olbrich Tested-by: Ahmad Fatoum I'd squash the two fixups I just sent when I apply this. Thanks, Ahmad > --- > > changes in v3: > uuid comparison fixed: > - compare the correct uuids > - don't crash when no

[OSS-Tools] [PATCH fixup 2/2] libdt: fix possible use of uninitialized variable

2023-05-31 Thread Ahmad Fatoum
property may not be always defined. So let's skip trying to do something with it in that case. Signed-off-by: Ahmad Fatoum --- src/libdt.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libdt.c b/src/libdt.c index 302ca7a76375..ca0502ac9483 100644 --- a/src/libdt.c +++ b/src/libdt.c

[OSS-Tools] [PATCH fixup 1/2] libdt: remove ultimately unused variables

2023-05-31 Thread Ahmad Fatoum
These variables were recently added, but are unused. Drop them. Signed-off-by: Ahmad Fatoum --- src/libdt.c | 7 ++- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libdt.c b/src/libdt.c index 44491a5e739b..302ca7a76375 100644 --- a/src/libdt.c +++ b/src/libdt.c @@ -2365,7

[OSS-Tools] [PATCH 3/5] libdt: use memcpy instead of strncpy

2023-05-31 Thread Ahmad Fatoum
Despite the name, GCC objects at the strncpy use in safe_strncpy on safety grounds. While that seems to be a false positive, we could just be using memcpy instead and side step this altogether. Signed-off-by: Ahmad Fatoum --- src/dt/common.h | 34 ++ 1 file

[OSS-Tools] [PATCH 4/5] libdt: don't use old-style function definition

2023-05-31 Thread Ahmad Fatoum
Increasing the warning level has GCC warn us, so let's heed the warning. Signed-off-by: Ahmad Fatoum --- src/dt/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dt/common.h b/src/dt/common.h index 69a264cfc1a9..62776c0bb027 100644 --- a/src/dt/common.h +++

[OSS-Tools] [PATCH 1/5] configure: pass -fno-strict-aliasing to GCC

2023-05-31 Thread Ahmad Fatoum
Like the Linux kernel, barebox is built with -fno-strict-aliasing, and code is written to take advantage of that. As dt-utils imports code from barebox, we may import code that assumes aliasing to be non-strict, so we better compile it with the same rules. Signed-off-by: Ahmad Fatoum ---

[OSS-Tools] [PATCH 2/5] libdt: fix issues of external function without prototype

2023-05-31 Thread Ahmad Fatoum
When increasing warning level, we see that of_find_device_by_node_path lacks a prototype despite having external linkage and being exported in the symbols file. On the other hand, scan_proc_dir has external linkage, but is only ever needed internally, so let's give it internal linkage.

[OSS-Tools] [PATCH 5/5] barebox-state: fix use after free in error path

2023-05-31 Thread Ahmad Fatoum
blob_bin is freed a few lines above unconditionally, so freeing it again in the error path will cause a double free. Signed-off-by: Ahmad Fatoum --- src/keystore-blob.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/keystore-blob.c b/src/keystore-blob.c index