[PATCH 4/5] mtd: maps: lantiq-flash: honour the EBU's own endianness swap

From: Simon Wunderlich

Date: Sat Nov 14 2026 - 05:07:22 EST


The driver swaps address bit 1 while probing the chip and afterwards
swizzles the CFI unlock addresses, to compensate for the EBU/PCI
endianness swapping that boot loaders enable on Lantiq boards.

Boot loaders that instead enable the EBU's own endianness swapping for
the flash chip select (EBU_BUSCON0 bit 30) present the chip at its
unswapped addresses. With the driver's software swap on top, the CFI
query returns garbage and probing fails, leaving the board without MTD.
The bintec elmeg RS123 and RS353 (BOSS bootmonitor) are such boards.

Measured on the RS123, CFI ident at 0x10/0x11/0x12 with bit 30 set:

unswapped: 0051 0052 0059 ("QRY")
swapped: 8f5b 0000 3c11 (garbage)

Clearing bit 30 before probing is not an option either: probing then
succeeds, but all data comes back halfword-swapped relative to what the
boot loader wrote and reads (the firmware header shows up as
"LDTE CATseloyedE"), so neither the MAC address in the boot partition
nor a kernel image written from Linux would be usable.

Skip the software swap when the boot loader enabled the hardware swap.
The bit only works on VR9 (xRX200) from revision 1.2 and on AR10
(xRX300), so it is only read when the flash node carries
"lantiq,ebu-swap-check", as requested in the review of the 2017
submission of this fix. Falcon has no EBU of this kind, so the access
is compiled in only for XWAY SoCs.

Based on that patch by Sebastien Decourriere.

Link: https://lists.infradead.org/pipermail/linux-mtd/2017-January/071749.html
Link: https://lists.infradead.org/pipermail/linux-mtd/2017-January/071818.html
Signed-off-by: Simon Wunderlich <sw@xxxxxxxxxxxxxxxxxx>
---
drivers/mtd/maps/lantiq-flash.c | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c
index 5c2ace302b50..7ee447227425 100644
--- a/drivers/mtd/maps/lantiq-flash.c
+++ b/drivers/mtd/maps/lantiq-flash.c
@@ -29,8 +29,17 @@
* map. The workaround involves swapping all addresses whilst probing the chip.
* Once probing is complete we stop swapping the addresses but swizzle the
* unlock addresses to ensure that access to the NOR device works correctly.
+ *
+ * Some boot loaders instead enable the EBU's own endianness swapping for the
+ * flash chip select (EBU_BUSCON0 bit 30). The chip then answers at its
+ * unswapped addresses and none of the above is needed. The bit only works on
+ * VR9 from revision 1.2 and on AR10, so boards ask the driver to honour it
+ * with the "lantiq,ebu-swap-check" property. Falcon has no EBU of this kind,
+ * so the register is only read on XWAY SoCs.
*/

+#define EBU_ENDIAN_SWAP BIT(30)
+
enum {
LTQ_NOR_PROBING,
LTQ_NOR_NORMAL
@@ -105,11 +114,21 @@ ltq_copy_to(struct map_info *map, unsigned long to,
spin_unlock_irqrestore(&ebu_lock, flags);
}

+static bool ltq_mtd_ebu_swap(struct platform_device *pdev)
+{
+#ifdef CONFIG_SOC_TYPE_XWAY
+ if (of_property_read_bool(pdev->dev.of_node, "lantiq,ebu-swap-check"))
+ return ltq_ebu_r32(LTQ_EBU_BUSCON0) & EBU_ENDIAN_SWAP;
+#endif
+ return false;
+}
+
static int
ltq_mtd_probe(struct platform_device *pdev)
{
struct ltq_mtd *ltq_mtd;
struct cfi_private *cfi;
+ bool hw_swap;
int err;

ltq_mtd = devm_kzalloc(&pdev->dev, sizeof(struct ltq_mtd), GFP_KERNEL);
@@ -137,7 +156,9 @@ ltq_mtd_probe(struct platform_device *pdev)
ltq_mtd->map->copy_from = ltq_copy_from;
ltq_mtd->map->copy_to = ltq_copy_to;

- ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
+ hw_swap = ltq_mtd_ebu_swap(pdev);
+
+ ltq_mtd->map->map_priv_1 = hw_swap ? LTQ_NOR_NORMAL : LTQ_NOR_PROBING;
ltq_mtd->mtd = do_map_probe("cfi_probe", ltq_mtd->map);
ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;

@@ -149,9 +170,11 @@ ltq_mtd_probe(struct platform_device *pdev)
ltq_mtd->mtd->dev.parent = &pdev->dev;
mtd_set_of_node(ltq_mtd->mtd, pdev->dev.of_node);

- cfi = ltq_mtd->map->fldrv_priv;
- cfi->addr_unlock1 ^= 1;
- cfi->addr_unlock2 ^= 1;
+ if (!hw_swap) {
+ cfi = ltq_mtd->map->fldrv_priv;
+ cfi->addr_unlock1 ^= 1;
+ cfi->addr_unlock2 ^= 1;
+ }

err = mtd_device_register(ltq_mtd->mtd, NULL, 0);
if (err) {
--
2.47.3