Re: [PATCH 1/4] i2c: rockchip: fix i2c stop condition

2023-09-11 Thread Gerald Loacker
Am 08.09.2023 um 15:53 schrieb Sascha Hauer: > On Fri, Sep 08, 2023 at 12:16:46PM +0200, Gerald Loacker wrote: >> The i2c bus gets disabled without sending a stop condition. This violates >> i2c timing on the clock line. Fix this and include all related functions >> (rk_i2c_send_start_bit,

Re: [PATCH 5/5] commands: add stacksmash command for causing stack overflows

2023-09-11 Thread Thorsten Scherer
Hi Ahmad, On Mon, Sep 11, 2023 at 05:09:00PM +0200, Ahmad Fatoum wrote: > Now that we have two mechanisms for detecting stack overflows, add a > command to intentionally trigger stack frame and stack region overflow > to verify their correct operation. > > Signed-off-by: Ahmad Fatoum > --- >

[PATCH master] boards: qemu-virt: rescan aliases after merging DT fragment

2023-09-11 Thread Ahmad Fatoum
barebox now compiles an initially empty device tree that's combined with the device tree passed by Qemu. That device tree can hold the FIT public key or if CONFIG_EXTERNAL_DTS_FRAGMENTS is enabled, device tree nodes passed at build time. If this device tree fragment adds an alias, it won't be

Re: [PATCH 3/3] ARM: boards: Add MyirTech MYD-YA15XC-T development board support

2023-09-11 Thread Ahmad Fatoum
Hi, On 30.08.23 16:41, Ahmad Fatoum wrote: > On 30.08.23 12:47, Alexander Shiyan wrote: >> + >> +len = (eeprom.sn[0] - '0'); >> +if ((len < 8) || (len > 64)) { >> +pr_err("Unable to get product serial\n"); >> +return -EINVAL; >> +} >> + >> +strncpy(str,

Re: [PATCH 3/3] ARM: boards: Add MyirTech MYD-YA15XC-T development board support

2023-09-11 Thread Ahmad Fatoum
On 05.09.23 10:25, Ahmad Fatoum wrote: > On 31.08.23 11:41, Alexander Shiyan wrote: +struct id_eeprom { + u8 hrcw_primary[0x10]; + u8 pn[64]; + u8 sn[64]; + u8 mac0[6]; + u8 mac1[6]; +} __packed; >>> >>> You could describe this as nvmem-cells

[PATCH 3/3] net: add generic MAC address derivation from machine ID

2023-09-11 Thread Ahmad Fatoum
From: Ahmad Fatoum Especially during development, devices often lack a MAC address. While a MAC address can be easily added to the environment: nv dev.eth0.ethaddr="aa:bb:cc:dd:ee:ff" It's easily lost when flashing complete new images, e.g. from CI. Make the development experience neater by

[PATCH 1/3] common: machine_id: support deriving app specific UUIDs

2023-09-11 Thread Ahmad Fatoum
libsystemd provides a sd_id128_get_machine_app_specific() function that allows deriving an application specific UUID without directly leaking the machine ID. Let's provide an equivalent for barebox that will be used in a following commit to generate a stable MAC instead of randomizing it.

[PATCH 2/3] net: import Linux eth_addr_inc/dec/add helpers

2023-09-11 Thread Ahmad Fatoum
Linux has a number of helpers to do arithmetic on Ethernet addresses, which are useful for generating sequential MAC addresses. Import them. Signed-off-by: Ahmad Fatoum --- include/net.h | 71 +++ 1 file changed, 71 insertions(+) diff --git

[PATCH] fixup! lib: add stackprotector support

2023-09-11 Thread Ahmad Fatoum
lib: stackprotector: add prompt text to option Kconfig rightfully complains about it: lib/Kconfig.hardening:66:warning: choice value must have a prompt So add it. Signed-off-by: Ahmad Fatoum --- lib/Kconfig.hardening | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git

[PATCH v2 4/7] tlsf: give malloc 8-byte alignment on 32-bit as well

2023-09-11 Thread Ahmad Fatoum
The current alignment of 4 bytes is too low. Access to 64-bit data via ldrd/strd requires at least an eight byte alignment: | Prior to ARMv6, if the memory address is not 64-bit aligned, the | data read from memory is UNPREDICTABLE. Alignment checking (taking | a data abort), and support

[PATCH v2 3/7] tlsf: fix sizeof(size_t) == sizeof(void *) assumption

2023-09-11 Thread Ahmad Fatoum
TLSF struct block_header_t doesn't describe a single block, but instead its first member covers the previous block: .~~~. | prev_phys_block | End of previous block --> |———| <-- Start of a free block

[PATCH v2 6/7] test: self: refactor to allow alignment check

2023-09-11 Thread Ahmad Fatoum
Have The expect_alloc_* functions currently only know whether the pointer is NULL or not. Have them get the full pointer value and return it instead. No functional change. Signed-off-by: Ahmad Fatoum --- test/self/malloc.c | 82 +- 1 file changed, 59

[PATCH v2 0/7] tlsf: use 8-byte alignment for normal malloc allocations

2023-09-11 Thread Ahmad Fatoum
TLSF currently uses only 4-byte alignment on 32-bit platforms, which isn't enough for ldrd/strd on ARMv7. This series reworks TLSF a bit, so we always have at least 8 byte alignment. dlmalloc already has 8 byte alignment minimum, so nothing to do there. This has the added benefit of giving TLSF

[PATCH v2 5/7] common: malloc: ensure alignment is always at least 8 byte

2023-09-11 Thread Ahmad Fatoum
We used to have following alignments: 32-bit CPU 64-bit CPU dummy8 bytes 8 bytes dlmalloc 8 bytes 16 bytes tlsf 4 bytes 8 bytes With recent change to TLSF, we now always have at least 8 bytes as alignment. To make this

[PATCH v2 7/7] test: self: malloc: fix memory leaks

2023-09-11 Thread Ahmad Fatoum
The test shouldn't leak memory, even if it fails. Fix the leaks. Signed-off-by: Ahmad Fatoum --- test/self/malloc.c | 14 +++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/self/malloc.c b/test/self/malloc.c index 6b3002ff0996..47c225ac6a10 100644 ---

[PATCH v2 2/7] tlsf: ensure malloc pool is aligned

2023-09-11 Thread Ahmad Fatoum
The struct control_t describing a pool is allocated at its very start and then directly followed by the first block. To ensure the first block is suitably aligned, align_up the size in tlsf_size(). So far, TLSF on 32-bit and 64-bit happened to be aligned, so this introduces no functional change

[PATCH v2 1/7] tlsf: turn static const variables into compiletime constant expressions

2023-09-11 Thread Ahmad Fatoum
static const is not a compiletime expression in C, unlike C++ and treating them the same just means that we just restrict where we can use the constants, e.g. they are not appropriate for static_assert. Turn them into proper macros to fix this. To keep the code easier to sync with other TLSF

[PATCH 2/5] ARM: mark early C setup functions as __prereloc

2023-09-11 Thread Ahmad Fatoum
In preparation for adding stack protector support, we need to start marking functions run before the C environment is completely set up. Introduce a __prereloc attribute for this use case and an even stronger no noinstr (no instrumentation) attribute and start adding it at enough places for

[PATCH 0/5] add stack protector and guard page support

2023-09-11 Thread Ahmad Fatoum
GCC's strong stack protector feature is increasingly used as default in many distros, because of comparatively low overhead. This series adds support in barebox to catch stack frame overflow as well as a guard page feature to catch stack region overflow. Ahmad Fatoum (5): include: move PAGE_

[PATCH 3/5] lib: add stackprotector support

2023-09-11 Thread Ahmad Fatoum
GCC's "stack-protector" puts, at the beginning of functions, a canary value on the stack just before the return address, and validates the value just before actually returning. Stack based buffer overflows (that need to overwrite this return address) now also overwrite the canary, which gets

[PATCH 4/5] ARM: mmu: catch stack overflowing into TTB with stack guard page

2023-09-11 Thread Ahmad Fatoum
While barebox stack is often quite generous, due to its default of 32K, bugs can make it overflow and on ARM, this clobbers the page tables leading to even harder to debug problems than usual. Let's add a 4K buffer zone between the page tables and the stack and configure the MMU to trap all

[PATCH 5/5] commands: add stacksmash command for causing stack overflows

2023-09-11 Thread Ahmad Fatoum
Now that we have two mechanisms for detecting stack overflows, add a command to intentionally trigger stack frame and stack region overflow to verify their correct operation. Signed-off-by: Ahmad Fatoum --- commands/Kconfig | 6 + commands/Makefile | 1 + commands/stacksmash.c |

[PATCH 1/5] include: move PAGE_ definitions into linux/pagemap.h

2023-09-11 Thread Ahmad Fatoum
is a fat header and we shouldn't need to include it just to get a definition for PAGE_SIZE. In Linux PAGE_SIZE is defined per architecture, but in barebox we only have 4K pages so far, so let's move it into . Signed-off-by: Ahmad Fatoum --- include/common.h| 6 +-

[PATCH 1/4] ARM: unwind: don't allocate while printing stack trace

2023-09-11 Thread Ahmad Fatoum
Calling dump_stack() in response to failing assertions can be useful to pinpoint where things started going awry. This is also done in TLSF code, but dump_stack actually calls malloc, because it uses the logging functions instead of printing directly to console. To avoid circular dependencies and

[PATCH 2/4] ARM64: backtrace: print stacktrace to stderr

2023-09-11 Thread Ahmad Fatoum
Rule of thumb is to print interactive output to stdout and status messages to stderr. A stack dump falls into the latter category and part of the stack trace is already printed to stderr, because of use of the logging functions, which always prints there. Signed-off-by: Ahmad Fatoum ---

[PATCH 3/4] KASan: only print to stderr

2023-09-11 Thread Ahmad Fatoum
Part of KASan output, like the stack trace, is already printed to stderr, while some others are printed to stdout. Let's print everything to stderr as not to complicate debugging when stdout and stderr go to different consoles. Signed-off-by: Ahmad Fatoum --- lib/kasan/report.c | 2 +- 1 file

[PATCH 0/4] KASan: print output directly to stderr

2023-09-11 Thread Ahmad Fatoum
I recently hunted down a heap memory corruption and this was somewhat complicated by KASan and dump_stack() themselves allocating memory off the heap. This series switches them to directly write to the consoles associated with stderr, while skipping the log. Ahmad Fatoum (4): ARM: unwind: don't

[PATCH 4/4] KASan: don't allocate memory while printing report

2023-09-11 Thread Ahmad Fatoum
The logging functions call the pr_* family of functions, which not only add pretty-colored prefix, but also allocate memory appending to the log. While KASAN protects against recursion while printing the log, this can falsify debugging results, so let's ensure, we only print to stderr and nothing

Re: [PATCH v2] aiodev: imx_thermal: fix breakage after device tree sync

2023-09-11 Thread Marco Felsch
On 23-09-11, Ahmad Fatoum wrote: > fsl,tempmon-data is a deprecated property that has been replaced > upstream by a NVMEM cell pointing at the calibration value and so > made it into barebox breaking the driver. > > Switch to using the new property to fix the regression. > > We do not keep

[PATCH v2] aiodev: imx_thermal: fix breakage after device tree sync

2023-09-11 Thread Ahmad Fatoum
fsl,tempmon-data is a deprecated property that has been replaced upstream by a NVMEM cell pointing at the calibration value and so made it into barebox breaking the driver. Switch to using the new property to fix the regression. We do not keep support for the old binding around as it would be

Re: [PATCH master] aiodev: imx_thermal: fix breakage after device tree sync

2023-09-11 Thread Marco Felsch
On 23-09-11, Ahmad Fatoum wrote: > On 11.09.23 14:35, Marco Felsch wrote: > > On 23-09-11, Ahmad Fatoum wrote: > >> fsl,tempmon-data is a deprecated property that has been replaced > >> upstream by a NVMEM cell pointing at the calibration value and so > >> made it into barebox breaking the driver.

Re: [PATCH] Documentation: dt-bindings: ocotp: deprecate barebox,provide-mac-address

2023-09-11 Thread Marco Felsch
On 23-09-11, Ahmad Fatoum wrote: > On 11.09.23 14:29, Marco Felsch wrote: > > On 23-09-11, Ahmad Fatoum wrote: > >> While we'll continue to support barebox,provide-mac-address, new boards > >> should prefer using the upstream NVMEM binding for describing the MAC > >> address. > >> > >> Add an

Re: [PATCH master] aiodev: imx_thermal: fix breakage after device tree sync

2023-09-11 Thread Ahmad Fatoum
On 11.09.23 14:35, Marco Felsch wrote: > On 23-09-11, Ahmad Fatoum wrote: >> fsl,tempmon-data is a deprecated property that has been replaced >> upstream by a NVMEM cell pointing at the calibration value and so >> made it into barebox breaking the driver. >> >> Switch to using the new property to

Re: [PATCH] Documentation: dt-bindings: ocotp: deprecate barebox,provide-mac-address

2023-09-11 Thread Ahmad Fatoum
On 11.09.23 14:29, Marco Felsch wrote: > On 23-09-11, Ahmad Fatoum wrote: >> While we'll continue to support barebox,provide-mac-address, new boards >> should prefer using the upstream NVMEM binding for describing the MAC >> address. >> >> Add an example to the documentation. >> >> Signed-off-by:

Re: [PATCH master] aiodev: imx_thermal: fix breakage after device tree sync

2023-09-11 Thread Marco Felsch
On 23-09-11, Ahmad Fatoum wrote: > fsl,tempmon-data is a deprecated property that has been replaced > upstream by a NVMEM cell pointing at the calibration value and so > made it into barebox breaking the driver. > > Switch to using the new property to fix the regression. The Linux driver code

Re: [PATCH] Documentation: dt-bindings: ocotp: deprecate barebox,provide-mac-address

2023-09-11 Thread Marco Felsch
On 23-09-11, Ahmad Fatoum wrote: > While we'll continue to support barebox,provide-mac-address, new boards > should prefer using the upstream NVMEM binding for describing the MAC address. > > Add an example to the documentation. > > Signed-off-by: Ahmad Fatoum > --- >

[PATCH] fs: ext4: initialize variable to silence GCC false-positive

2023-09-11 Thread Ahmad Fatoum
GCC complains about ino not being defined in some cases, which appears to be a false positive. Nevertheless, initialize it to the same fallback value used in ext4fs_get_ino, which is called below. Signed-off-by: Ahmad Fatoum --- fs/ext4/ext_barebox.c | 2 +- 1 file changed, 1 insertion(+), 1

[PATCH] Documentation: dt-bindings: ocotp: deprecate barebox,provide-mac-address

2023-09-11 Thread Ahmad Fatoum
While we'll continue to support barebox,provide-mac-address, new boards should prefer using the upstream NVMEM binding for describing the MAC address. Add an example to the documentation. Signed-off-by: Ahmad Fatoum --- .../bindings/misc/fsl,imx-ocotp.rst | 25 --- 1

[PATCH master] aiodev: imx_thermal: fix breakage after device tree sync

2023-09-11 Thread Ahmad Fatoum
fsl,tempmon-data is a deprecated property that has been replaced upstream by a NVMEM cell pointing at the calibration value and so made it into barebox breaking the driver. Switch to using the new property to fix the regression. Fixes: abef60363d8e ("dts: update to v5.8-rc1") Signed-off-by:

[PATCH] lib: random: make linux/hw_random.h header self-contained

2023-09-11 Thread Ahmad Fatoum
struct hwrng defined in the file embeds a struct device, so inclusion of the header defining it is in order. Signed-off-by: Ahmad Fatoum --- include/linux/hw_random.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h index

[PATCH] KAsan: support including header from PBL

2023-09-11 Thread Ahmad Fatoum
It can be sometimes useful to add manual poisoning with KASAN to track down errant accesses. This is complicated a bit, because some files are build for both PBL and barebox proper. To make such debugging easier, let's allow to be included from PBL code. Signed-off-by: Ahmad Fatoum ---

[PATCH master 1/2] mci: sdhci: unmap the DMA buffers actually used

2023-09-11 Thread Ahmad Fatoum
At the end of sdhci_transfer_data_dma, sdhci_set_sdma_addr is called to set the next DMA address. Recently, the computation of the next DMA address was changed and instead of storing the next SDMA address into a dedicated local variable as before, it was stored into the existing `dma' variable.

[PATCH master 2/2] mci: sdhci: hardcode SDMA boundary for DMA

2023-09-11 Thread Ahmad Fatoum
Given that we are not using the feature, there's no reason to compute the boundary when polling for DMA completion. Therefore let's assume the initial default of 512K remains unchanged. The sdhci::sdma_boundary member is still left in place as the i.MX eSDHC driver sets it to zero to affect what

[PATCH master 0/2] mci: sdhci: fix memory corruption on DMA

2023-09-11 Thread Ahmad Fatoum
Recent changes to teach SDHCI 64-bit support inadvertently changed the address used for cache maintenance away from the DMA buffer address with the result that unrelated cache lines were dropped and memory corruption. This series fixes this. I must admit I don't understand how the SDMA boundary

Re: [PATCH v2 3/3] net: ksz9477: Add mdio bus slice dependency to i2c/spi device

2023-09-11 Thread Gerald Loacker
Am 08.09.2023 um 15:11 schrieb Sascha Hauer: > On mdio busses the attached phys check for link status in a poller. > Add a slice dependency from the mdio bus to the I2C/SPI controller > so that we do not end up doing bus accesses while we are in a > I2C/SPI access on the same bus already. > >

Re: [PATCH v2 2/3] spi: Add slices for SPI controllers

2023-09-11 Thread Gerald Loacker
Am 08.09.2023 um 15:11 schrieb Sascha Hauer: > Add a slice for SPI controllers so that devices using SPI in the background > can check if a SPI bus is busy. > > Signed-off-by: Sascha Hauer Tested-by: Gerald Loacker > --- > > Notes: > Changes since v1: > - Add forgotten

Re: [PATCH v2 1/3] i2c: Add slices for I2C adapters

2023-09-11 Thread Gerald Loacker
Am 08.09.2023 um 15:11 schrieb Sascha Hauer: > Add a slice for I2C adapters so that devices using I2C in the background > can check if a I2C bus is busy. > > Signed-off-by: Sascha Hauer Tested-by: Gerald Loacker > --- > > Notes: > Changes since v1: > - Add forgotten slice_init() >

Re: [PATCH 2/4] i2c: rockchip: ignore i2c transfers when another transfer is running

2023-09-11 Thread Gerald Loacker
Hi Sascha, Am 08.09.2023 um 15:13 schrieb Sascha Hauer: > On Fri, Sep 08, 2023 at 01:55:40PM +0200, Sascha Hauer wrote: >> On Fri, Sep 08, 2023 at 01:51:32PM +0200, Sascha Hauer wrote: >>> On Fri, Sep 08, 2023 at 12:16:47PM +0200, Gerald Loacker wrote: It may happen that an i2c transfer is

Re: [PATCH] ARM: i.MX8M: don't print TF-A version

2023-09-11 Thread Marco Felsch
On 23-09-11, Ahmad Fatoum wrote: > In usual configurations, TF-A already prints its version on startup, so > printing it in barebox again is unnecessary and less informational than > the TF-A print and complicates running barebox without TF-A. > Thus just drop it. > > Signed-off-by: Ahmad Fatoum

[PATCH] include: linux/kernel.h: define PTR_ALIGN_DOWN/PTR_IS_ALIGNED

2023-09-11 Thread Ahmad Fatoum
Pointer casts to integers are a common cause of 64-bit incompatibilities. Import PTR_ALIGN_DOWN/PTR_IS_ALIGNED macros from Linux to hide the cast. Signed-off-by: Ahmad Fatoum --- include/linux/kernel.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/kernel.h

[PATCH] ARM: i.MX8M: don't print TF-A version

2023-09-11 Thread Ahmad Fatoum
In usual configurations, TF-A already prints its version on startup, so printing it in barebox again is unnecessary and less informational than the TF-A print and complicates running barebox without TF-A. Thus just drop it. Signed-off-by: Ahmad Fatoum --- arch/arm/mach-imx/imx8m.c | 11