Skip to contentSkip to conversation

mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled

PATCH In review Sebastien Decourriere 2 participants 5 messages Jan 18, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled

The purpose of this patch is to enable the software address endianness swapping only when the in SoC EBU endianness swapping is disabled. To perform this check, I look at Bit 30 of the EBU_CON_0 register. Actually, the driver expects that the in SoC swapping is disabled. This is the case with current bootloaders shuch as U-boot. But,

I have a router which uses a proprietary bootloader which keeps the in SoC swapping enabled. The SoC in this router is a vrx200 v1.2. In this SoC version, I can keep the in SoC swapping without any problem.

---
 drivers/mtd/maps/lantiq-flash.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/mtd/maps/lantiq-flash.c +10 -2
index c8febb3..a091efa 100644
@@ -151,6 +151,11 @@ ltq_mtd_probe(struct platform_device *pdev)
 	ltq_mtd->map->copy_to = ltq_copy_to;
 
 	ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
+	/* We swap the addresses only if the EBU endianness swap is disabled */
+	if (ltq_ebu_r32(LTQ_EBU_BUSCON0) & BIT(30))
+		ltq_mtd->map[i].map_priv_1 = LTQ_NOR_NORMAL;
+	else
+		ltq_mtd->map[i].map_priv_1 = LTQ_NOR_PROBING;
 	ltq_mtd->mtd = do_map_probe("cfi_probe", ltq_mtd->map);
 	ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
 
@@ -163,8 +168,11 @@ ltq_mtd_probe(struct platform_device *pdev)
 	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;
+	/* We swap the addresses only if the EBU endianness swap is disabled */
+	if (!(ltq_ebu_r32(LTQ_EBU_BUSCON0) & BIT(30))) {
+		cfi->addr_unlock1 ^= 1;
+		cfi->addr_unlock2 ^= 1;
+	}
 
 	err = mtd_device_register(ltq_mtd->mtd, NULL, 0);
 	if (err) {
Signature · 1 line
2.1.4
#1 lore raw

Hi Sebastien,

thanks, comments inline

Quoted 20 lines · Sebastien Decourriere

The purpose of this patch is to enable the software address endianness swapping only when the in SoC EBU endianness swapping is disabled. To perform this check, I look at Bit 30 of the EBU_CON_0 register. Actually, the driver expects that the in SoC swapping is disabled. This is the case with current bootloaders shuch as U-boot. But,

I have a router which uses a proprietary bootloader which keeps the in SoC swapping enabled. The SoC in this router is a vrx200 v1.2. In this SoC version, I can keep the in SoC swapping without any problem.

---
 drivers/mtd/maps/lantiq-flash.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/mtd/maps/lantiq-flash.c +0 -0
index c8febb3..a091efa 100644

drivers/mtd/maps/lantiq-flash.c ltq_mtd_probe(struct platform_device *pdev) · line 153

Quoted 3 lines
drivers/mtd/maps/lantiq-flash.c +0 -0
@@ -151,6 +151,11 @@ ltq_mtd_probe(struct platform_device *pdev)
 	ltq_mtd->map->copy_to = ltq_copy_to;
 
 	ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;

this line should be dropped

drivers/mtd/maps/lantiq-flash.c ltq_mtd_probe(struct platform_device *pdev) · line 155

Quoted 2 lines
drivers/mtd/maps/lantiq-flash.c +2 -0
+	/* We swap the addresses only if the EBU endianness swap is disabled */
+	if (ltq_ebu_r32(LTQ_EBU_BUSCON0) & BIT(30))

add a define for BIT(30) please and we should really check if this a v1.2 or newer. if my memory is correct this was a silicon bug inside v1.0 and v1.1

John

Quoted 21 lines
drivers/mtd/maps/lantiq-flash.c +8 -2
+		ltq_mtd->map[i].map_priv_1 = LTQ_NOR_NORMAL;
+	else
+		ltq_mtd->map[i].map_priv_1 = LTQ_NOR_PROBING;
 	ltq_mtd->mtd = do_map_probe("cfi_probe", ltq_mtd->map);
 	ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
 
@@ -163,8 +168,11 @@ ltq_mtd_probe(struct platform_device *pdev)
 	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;
+	/* We swap the addresses only if the EBU endianness swap is disabled */
+	if (!(ltq_ebu_r32(LTQ_EBU_BUSCON0) & BIT(30))) {
+		cfi->addr_unlock1 ^= 1;
+		cfi->addr_unlock2 ^= 1;
+	}
 
 	err = mtd_device_register(ltq_mtd->mtd, NULL, 0);
 	if (err) {
author
#2 lore raw

Hi John,

Quoted 4 lines
Quoted 2 lines
      ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;

this line should be dropped

Yes, I noticed this mistake. I fixed it but forgotten to add thix fix to my commit -_-

Quoted 6 lines

drivers/mtd/maps/lantiq-flash.c ltq_mtd_probe(struct platform_device *pdev) · line 155

Quoted 2 lines
drivers/mtd/maps/lantiq-flash.c +2 -0
+     /* We swap the addresses only if the EBU endianness swap is disabled */
+     if (ltq_ebu_r32(LTQ_EBU_BUSCON0) & BIT(30))

add a define for BIT(30) please and we should really check if this a v1.2 or newer. if my memory is correct this was a silicon bug inside v1.0 and v1.1

In my kernel (OpenWrt) boot log I have :

[    0.000000] Linux version 4.4.14 (qa@serveurQA) (gcc version 5.3.0
(OpenWrt GCC 5.3.0 50020) ) #150 SMP Tue Jan 17 09:18:24 UTC 2017
[    0.000000] SoC: xRX200 rev 1.2
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 00019556 (MIPS 34Kc)

It would be better to ensure that the SoC version is >= 1.2 (as this bug was fixed in this version).

You can get more informations in my OpenWrt pull request :

https://github.com/openwrt/openwrt/pull/321

Regards,

Sebastien.

#3 lore raw
Quoted 20 lines · Seb

Hi John,

Quoted 4 lines
Quoted 2 lines
      ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;

this line should be dropped

Yes, I noticed this mistake. I fixed it but forgotten to add thix fix to my commit -_-

Quoted 6 lines

drivers/mtd/maps/lantiq-flash.c ltq_mtd_probe(struct platform_device *pdev) · line 155

Quoted 2 lines
drivers/mtd/maps/lantiq-flash.c +2 -0
+     /* We swap the addresses only if the EBU endianness swap is disabled */
+     if (ltq_ebu_r32(LTQ_EBU_BUSCON0) & BIT(30))

add a define for BIT(30) please and we should really check if this a v1.2 or newer. if my memory is correct this was a silicon bug inside v1.0 and v1.1

In my kernel (OpenWrt) boot log I have :

Quoted 8 lines
[    0.000000] Linux version 4.4.14 (qa@serveurQA) (gcc version 5.3.0
(OpenWrt GCC 5.3.0 50020) ) #150 SMP Tue Jan 17 09:18:24 UTC 2017
[    0.000000] SoC: xRX200 rev 1.2
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 00019556 (MIPS 34Kc)

It would be better to ensure that the SoC version is >= 1.2 (as this bug was fixed in this version).

the bug is also fixed on the 300 and 500 series chips, so we would want to check for that aswell.

John

Quoted 9 lines

You can get more informations in my OpenWrt pull request :

https://github.com/openwrt/openwrt/pull/321

Regards,

Sebastien.

author
#4 lore raw
Quoted 3 lines

the bug is also fixed on the 300 and 500 series chips, so we would want to check for that aswell.

I added this to the begin of "ltq_mtd_probe" function:

bool mtd_addr_swap;

        if ( ltq_ebu_r32(LTQ_EBU_BUSCON0) & EBU_ENDIAN_SWAP ) {
                switch (ltq_soc_type()) {
                        case SOC_TYPE_VR9_2 :
                        case SOC_TYPE_AR10 :
                                mtd_addr_swap = false;
                                break;
                        default :
                                mtd_addr_swap = true;
                }
        } else mtd_addr_swap = true;

It's easier to add other architectures as needed. I tried it on my OpenWrt release, and got it working fine. Is it correct in this way ?