Skip to contentSkip to conversation

mtd: parsers: bcm63xx: simplify CFE detection

PATCH Superseded Álvaro Fernández Rojas 6 participants 29 messages Jun 8, 2020 – Oct 12, 2020

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

cover mtd: parsers: bcm63xx: simplify CFE detection

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

Álvaro Fernández Rojas (2):
MIPS: BCM63xx: add helper function to detect CFE
mtd: parsers: bcm63xx: simplify CFE detection

 .../include/asm/mach-bcm63xx/bcm63xx_board.h  |  6 ++++
 drivers/mtd/parsers/bcm63xxpart.c             | 28 ++-----------------
 2 files changed, 9 insertions(+), 25 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/2 MIPS: BCM63xx: add helper function to detect CFE

CFE passes argument 3 as "CFE1".

---
 arch/mips/include/asm/mach-bcm63xx/bcm63xx_board.h | 6 ++++++
 1 file changed, 6 insertions(+)
arch/mips/include/asm/mach-bcm63xx/bcm63xx_board.h +6 -0
index 1d19a726f86c..5af07796e8c7 100644
@@ -2,6 +2,8 @@
 #ifndef BCM63XX_BOARD_H_
 #define BCM63XX_BOARD_H_
 
+#include <asm/bootinfo.h>
+
 const char *board_get_name(void);
 
 void board_prom_init(void);
@@ -10,4 +12,8 @@ void board_setup(void);
 
 int board_register_devices(void);
 
+static inline bool bcm63xx_is_cfe_present(void) {
+	return fw_arg3 == 0x43464531;
+}
+
 #endif /* ! BCM63XX_BOARD_H_ */
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/2 mtd: parsers: bcm63xx: simplify CFE detection

In reply to Álvaro Fernández Rojas

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
 drivers/mtd/parsers/bcm63xxpart.c | 28 +++-------------------------
 1 file changed, 3 insertions(+), 25 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +3 -25
index 78f90c6c18fd..06b69e905a42 100644
@@ -22,6 +22,8 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
+#include <asm/mach-bcm63xx/bcm63xx_board.h>
+
 #define BCM963XX_CFE_BLOCK_SIZE		SZ_64K	/* always at least 64KiB */
 
 #define BCM963XX_CFE_MAGIC_OFFSET	0x4e0
@@ -32,30 +34,6 @@
 #define STR_NULL_TERMINATE(x) \
 	do { char *_str = (x); _str[sizeof(x) - 1] = 0; } while (0)
 
-static int bcm63xx_detect_cfe(struct mtd_info *master)
-{
-	char buf[9];
-	int ret;
-	size_t retlen;
-
-	ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	if (ret)
-		return ret;
-
-	if (strncmp("cfe-v", buf, 5) == 0)
-		return 0;
-
-	/* very old CFE's do not have the cfe-v string, so check for magic */
-	ret = mtd_read(master, BCM963XX_CFE_MAGIC_OFFSET, 8, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	return strncmp("CFE1CFE1", buf, 8);
-}
-
 static int bcm63xx_read_nvram(struct mtd_info *master,
 	struct bcm963xx_nvram *nvram)
 {
@@ -138,7 +116,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
 	struct bcm963xx_nvram *nvram = NULL;
 	int ret;
 
-	if (bcm63xx_detect_cfe(master))
+	if (!bcm63xx_is_cfe_present())
 		return -EINVAL;
 
 	nvram = vzalloc(sizeof(*nvram));
Signature · 1 line
2.26.2
#3 lore raw
Thank you for the patch! Yet something to improve:

Hi "Álvaro,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.7 next-20200605]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/lvaro-Fern-ndez-Rojas/mtd-parsers-bcm63xx-simplify-CFE-detection/20200608-174326
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git af7b4801030c07637840191c69eb666917e4135d
config: x86_64-allyesconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project e429cffd4f228f70c1d9df0e5d77c08590dd9766)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> drivers/mtd/parsers/bcm63xxpart.c:25:10: fatal error: 'asm/mach-bcm63xx/bcm63xx_board.h' file not found

#include <asm/mach-bcm63xx/bcm63xx_board.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

vim +25 drivers/mtd/parsers/bcm63xxpart.c

    24	
  > 25	#include <asm/mach-bcm63xx/bcm63xx_board.h>
    26	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#4 lore raw

PATCH v2 1/1 mtd: parsers: bcm63xx: simplify CFE detection

In reply to Álvaro Fernández Rojas

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
v2: use CFE_EPTSEAL definition and avoid using an additional funtion.

 drivers/mtd/parsers/bcm63xxpart.c | 29 ++++-------------------------
 1 file changed, 4 insertions(+), 25 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +4 -25
index 78f90c6c18fd..493a75b2f266 100644
@@ -22,6 +22,9 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>
+
 #define BCM963XX_CFE_BLOCK_SIZE		SZ_64K	/* always at least 64KiB */
 
 #define BCM963XX_CFE_MAGIC_OFFSET	0x4e0
@@ -32,30 +35,6 @@
 #define STR_NULL_TERMINATE(x) \
 	do { char *_str = (x); _str[sizeof(x) - 1] = 0; } while (0)
 
-static int bcm63xx_detect_cfe(struct mtd_info *master)
-{
-	char buf[9];
-	int ret;
-	size_t retlen;
-
-	ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	if (ret)
-		return ret;
-
-	if (strncmp("cfe-v", buf, 5) == 0)
-		return 0;
-
-	/* very old CFE's do not have the cfe-v string, so check for magic */
-	ret = mtd_read(master, BCM963XX_CFE_MAGIC_OFFSET, 8, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	return strncmp("CFE1CFE1", buf, 8);
-}
-
 static int bcm63xx_read_nvram(struct mtd_info *master,
 	struct bcm963xx_nvram *nvram)
 {
@@ -138,7 +117,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
 	struct bcm963xx_nvram *nvram = NULL;
 	int ret;
 
-	if (bcm63xx_detect_cfe(master))
+	if (fw_arg3 != CFE_EPTSEAL)
 		return -EINVAL;
 
 	nvram = vzalloc(sizeof(*nvram));
Signature · 1 line
2.26.2
maintainer
#5 lore raw

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Mon, 8 Jun 2020 18:06:49 +0200:

Quoted 16 lines

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
v2: use CFE_EPTSEAL definition and avoid using an additional funtion.

 drivers/mtd/parsers/bcm63xxpart.c | 29 ++++-------------------------
 1 file changed, 4 insertions(+), 25 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +0 -0
index 78f90c6c18fd..493a75b2f266 100644

drivers/mtd/parsers/bcm63xxpart.c line 26

Quoted 5 lines
drivers/mtd/parsers/bcm63xxpart.c +2 -0
@@ -22,6 +22,9 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>

Are you sure both includes are needed?

I don't think it is a good habit to include asm/ headers, are you sure there is not another header doing it just fine?

Quoted 44 lines
drivers/mtd/parsers/bcm63xxpart.c +2 -25
+
 #define BCM963XX_CFE_BLOCK_SIZE		SZ_64K	/* always at least 64KiB */
 
 #define BCM963XX_CFE_MAGIC_OFFSET	0x4e0
@@ -32,30 +35,6 @@
 #define STR_NULL_TERMINATE(x) \
 	do { char *_str = (x); _str[sizeof(x) - 1] = 0; } while (0)
 
-static int bcm63xx_detect_cfe(struct mtd_info *master)
-{
-	char buf[9];
-	int ret;
-	size_t retlen;
-
-	ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	if (ret)
-		return ret;
-
-	if (strncmp("cfe-v", buf, 5) == 0)
-		return 0;
-
-	/* very old CFE's do not have the cfe-v string, so check for magic */
-	ret = mtd_read(master, BCM963XX_CFE_MAGIC_OFFSET, 8, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	return strncmp("CFE1CFE1", buf, 8);
-}
-
 static int bcm63xx_read_nvram(struct mtd_info *master,
 	struct bcm963xx_nvram *nvram)
 {
@@ -138,7 +117,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
 	struct bcm963xx_nvram *nvram = NULL;
 	int ret;
 
-	if (bcm63xx_detect_cfe(master))
+	if (fw_arg3 != CFE_EPTSEAL)
 		return -EINVAL;
 
 	nvram = vzalloc(sizeof(*nvram));
#6 lore raw

Hi Miquel,

Quoted 26 lines · Miquel Raynal

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Mon, 8 Jun 2020 18:06:49 +0200:

Quoted 19 lines

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
v2: use CFE_EPTSEAL definition and avoid using an additional funtion.

drivers/mtd/parsers/bcm63xxpart.c | 29 ++++-------------------------

1 file changed, 4 insertions(+), 25 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +0 -0
index 78f90c6c18fd..493a75b2f266 100644
@@ -22,6 +22,9 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
Quoted 4 lines

drivers/mtd/parsers/bcm63xxpart.c line 26

Quoted 2 lines
drivers/mtd/parsers/bcm63xxpart.c +2 -0
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>

Are you sure both includes are needed?

asm/bootinfo.h is needed for fw_arg3 and asm/fw/cfe/cfe_api.h is needed for CFE_EPTSEAL.

Quoted 3 lines

I don't think it is a good habit to include asm/ headers, are you sure there is not another header doing it just fine?

Both are needed unless you want to add another definition of CFE_EPTSEAL value.
There are currently two CFE magic definitions, the one in asm/fw/cfe/cfe_api.h and another one in bcm47xxpart.c:
https://github.com/torvalds/linux/blob/master/arch/mips/include/asm/fw/cfe/cfe_api.h#L28
https://github.com/torvalds/linux/blob/master/drivers/mtd/parsers/bcm47xxpart.c#L33

Quoted 40 lines
Quoted 40 lines
drivers/mtd/parsers/bcm63xxpart.c +1 -24
+
 #define BCM963XX_CFE_BLOCK_SIZE		SZ_64K	/* always at least 64KiB */
 
 #define BCM963XX_CFE_MAGIC_OFFSET	0x4e0
@@ -32,30 +35,6 @@
 #define STR_NULL_TERMINATE(x) \
 	do { char *_str = (x); _str[sizeof(x) - 1] = 0; } while (0)
 
-static int bcm63xx_detect_cfe(struct mtd_info *master)
-{
-	char buf[9];
-	int ret;
-	size_t retlen;
-
-	ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	if (ret)
-		return ret;
-
-	if (strncmp("cfe-v", buf, 5) == 0)
-		return 0;
-
-	/* very old CFE's do not have the cfe-v string, so check for magic */
-	ret = mtd_read(master, BCM963XX_CFE_MAGIC_OFFSET, 8, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	return strncmp("CFE1CFE1", buf, 8);
-}
-
 static int bcm63xx_read_nvram(struct mtd_info *master,
 	struct bcm963xx_nvram *nvram)
 {
@@ -138,7 +117,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
 	struct bcm963xx_nvram *nvram = NULL;
 	int ret;
 
Quoted 5 lines

drivers/mtd/parsers/bcm63xxpart.c static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, · line 123

Quoted 5 lines
drivers/mtd/parsers/bcm63xxpart.c +1 -1
-	if (bcm63xx_detect_cfe(master))
+	if (fw_arg3 != CFE_EPTSEAL)
 		return -EINVAL;
 
 	nvram = vzalloc(sizeof(*nvram));

Best regards,
Álvaro.

#7 lore raw
Quoted 36 lines · Álvaro Fernández Rojas

Hi Miquel,

Quoted 26 lines · Miquel Raynal

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Mon, 8 Jun 2020 18:06:49 +0200:

Quoted 19 lines

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
v2: use CFE_EPTSEAL definition and avoid using an additional funtion.

drivers/mtd/parsers/bcm63xxpart.c | 29 ++++-------------------------

1 file changed, 4 insertions(+), 25 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +0 -0
index 78f90c6c18fd..493a75b2f266 100644
@@ -22,6 +22,9 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
Quoted 4 lines

drivers/mtd/parsers/bcm63xxpart.c line 26

Quoted 2 lines
drivers/mtd/parsers/bcm63xxpart.c +2 -0
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>

Are you sure both includes are needed?

asm/bootinfo.h is needed for fw_arg3 and asm/fw/cfe/cfe_api.h is needed for CFE_EPTSEAL.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

I don't think it is a good habit to include asm/ headers, are you sure there is not another header doing it just fine?

Both are needed unless you want to add another definition of CFE_EPTSEAL value.
There are currently two CFE magic definitions, the one in asm/fw/cfe/cfe_api.h and another one in bcm47xxpart.c:
https://github.com/torvalds/linux/blob/master/arch/mips/include/asm/fw/cfe/cfe_api.h#L28
https://github.com/torvalds/linux/blob/master/drivers/mtd/parsers/bcm47xxpart.c#L33

The caveat with that approach is that this reduces the compilation surface to MIPS and BMIPS_GENERIC and BCM63XX only, which is a bit small. If we could move the CFE definitions to a shared header, and consolidate the value used by bcm47xxpart.c as well, that would allow us to build the bcm63xxpart.c file with COMPILE_TEST on other architectures. This does not really have functional value, but for maintainers like Miquel, it allows them to quickly test their entire drivers/mtd/ directory.

Signature · 1 line
Florian
maintainer
#8 lore raw

Florian Fainelli <[email protected]> wrote on Thu, 11 Jun 2020 08:42:42 -0700:

Quoted 45 lines · Álvaro Fernández Rojas
Quoted 36 lines

Hi Miquel,

Quoted 26 lines · Miquel Raynal

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Mon, 8 Jun 2020 18:06:49 +0200:

Quoted 19 lines

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
v2: use CFE_EPTSEAL definition and avoid using an additional funtion.

drivers/mtd/parsers/bcm63xxpart.c | 29 ++++-------------------------

1 file changed, 4 insertions(+), 25 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +0 -0
index 78f90c6c18fd..493a75b2f266 100644
@@ -22,6 +22,9 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
Quoted 4 lines

drivers/mtd/parsers/bcm63xxpart.c line 26

Quoted 2 lines
drivers/mtd/parsers/bcm63xxpart.c +2 -0
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>  

Are you sure both includes are needed?

asm/bootinfo.h is needed for fw_arg3 and asm/fw/cfe/cfe_api.h is needed for CFE_EPTSEAL.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

I don't think it is a good habit to include asm/ headers, are you sure there is not another header doing it just fine?

Both are needed unless you want to add another definition of CFE_EPTSEAL value.
There are currently two CFE magic definitions, the one in asm/fw/cfe/cfe_api.h and another one in bcm47xxpart.c:
https://github.com/torvalds/linux/blob/master/arch/mips/include/asm/fw/cfe/cfe_api.h#L28
https://github.com/torvalds/linux/blob/master/drivers/mtd/parsers/bcm47xxpart.c#L33

Quoted 8 lines

The caveat with that approach is that this reduces the compilation surface to MIPS and BMIPS_GENERIC and BCM63XX only, which is a bit small. If we could move the CFE definitions to a shared header, and consolidate the value used by bcm47xxpart.c as well, that would allow us to build the bcm63xxpart.c file with COMPILE_TEST on other architectures. This does not really have functional value, but for maintainers like Miquel, it allows them to quickly test their entire drivers/mtd/ directory.

Absolutely!

#9 lore raw
In reply to Florian Fainelli

Hi Florian,

Quoted 49 lines · Florian Fainelli
Quoted 36 lines · Álvaro Fernández Rojas

Hi Miquel,

Quoted 26 lines · Miquel Raynal

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Mon, 8 Jun 2020 18:06:49 +0200:

Quoted 19 lines

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
v2: use CFE_EPTSEAL definition and avoid using an additional funtion.

drivers/mtd/parsers/bcm63xxpart.c | 29 ++++-------------------------

1 file changed, 4 insertions(+), 25 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +0 -0
index 78f90c6c18fd..493a75b2f266 100644
@@ -22,6 +22,9 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
Quoted 4 lines

drivers/mtd/parsers/bcm63xxpart.c line 26

Quoted 2 lines
drivers/mtd/parsers/bcm63xxpart.c +2 -0
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>

Are you sure both includes are needed?

asm/bootinfo.h is needed for fw_arg3 and asm/fw/cfe/cfe_api.h is needed for CFE_EPTSEAL.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

I don't think it is a good habit to include asm/ headers, are you sure there is not another header doing it just fine?

Both are needed unless you want to add another definition of CFE_EPTSEAL value.
There are currently two CFE magic definitions, the one in asm/fw/cfe/cfe_api.h and another one in bcm47xxpart.c:
https://github.com/torvalds/linux/blob/master/arch/mips/include/asm/fw/cfe/cfe_api.h#L28
https://github.com/torvalds/linux/blob/master/drivers/mtd/parsers/bcm47xxpart.c#L33

Quoted 8 lines

The caveat with that approach is that this reduces the compilation surface to MIPS and BMIPS_GENERIC and BCM63XX only, which is a bit small. If we could move the CFE definitions to a shared header, and consolidate the value used by bcm47xxpart.c as well, that would allow us to build the bcm63xxpart.c file with COMPILE_TEST on other architectures. This does not really have functional value, but for maintainers like Miquel, it allows them to quickly test their entire drivers/mtd/ directory.

I don’t think fw_arg3 available on non mips archs, is it?
I’m happy to move it to a shared header (which would be a good location for this?), but if I’m right it would still be restricted to MIPS.

Quoted 2 lines
Signature · 1 line
Florian
maintainer
#10 lore raw

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Thu, 11 Jun 2020 18:14:20 +0200:

Quoted 60 lines

Hi Florian,

Quoted 49 lines · Florian Fainelli
Quoted 36 lines · Álvaro Fernández Rojas

Hi Miquel,

Quoted 26 lines · Miquel Raynal

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Mon, 8 Jun 2020 18:06:49 +0200:

Quoted 19 lines

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
v2: use CFE_EPTSEAL definition and avoid using an additional funtion.

drivers/mtd/parsers/bcm63xxpart.c | 29 ++++-------------------------

1 file changed, 4 insertions(+), 25 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +0 -0
index 78f90c6c18fd..493a75b2f266 100644
@@ -22,6 +22,9 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
Quoted 4 lines

drivers/mtd/parsers/bcm63xxpart.c line 26

Quoted 2 lines
drivers/mtd/parsers/bcm63xxpart.c +2 -0
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>  

Are you sure both includes are needed?

asm/bootinfo.h is needed for fw_arg3 and asm/fw/cfe/cfe_api.h is needed for CFE_EPTSEAL.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

I don't think it is a good habit to include asm/ headers, are you sure there is not another header doing it just fine?

Both are needed unless you want to add another definition of CFE_EPTSEAL value.
There are currently two CFE magic definitions, the one in asm/fw/cfe/cfe_api.h and another one in bcm47xxpart.c:
https://github.com/torvalds/linux/blob/master/arch/mips/include/asm/fw/cfe/cfe_api.h#L28
https://github.com/torvalds/linux/blob/master/drivers/mtd/parsers/bcm47xxpart.c#L33

Quoted 8 lines

The caveat with that approach is that this reduces the compilation surface to MIPS and BMIPS_GENERIC and BCM63XX only, which is a bit small. If we could move the CFE definitions to a shared header, and consolidate the value used by bcm47xxpart.c as well, that would allow us to build the bcm63xxpart.c file with COMPILE_TEST on other architectures. This does not really have functional value, but for maintainers like Miquel, it allows them to quickly test their entire drivers/mtd/ directory.

Quoted 2 lines

I don’t think fw_arg3 available on non mips archs, is it?
I’m happy to move it to a shared header (which would be a good location for this?), but if I’m right it would still be restricted to MIPS.

Restricting a definition to MIPS, even if it makes sense for you is very limiting for me. I need to be able to build as much drivers as I can from my laptop and verify they at least compile correctly. If I need a MIPS toolchain, an ARC toolchain, a PowerPC, an ARM, an ARM64 and whatever other funky toolchain to do just that in X steps: it's very painful. We have been adding COMPILE_TEST dependencies on as much drivers as we could and we want to continue moving forward. Using such include would need to drop the COMPILE_TEST condition from Kconfig and this is not something I am willing to do.

Thanks for your understanding :)
Miquèl

#11 lore raw

Hi Miquèl,

Quoted 70 lines · Miquel Raynal

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Thu, 11 Jun 2020 18:14:20 +0200:

Quoted 60 lines

Hi Florian,

Quoted 49 lines · Florian Fainelli
Quoted 36 lines · Álvaro Fernández Rojas

Hi Miquel,

Quoted 26 lines · Miquel Raynal

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Mon, 8 Jun 2020 18:06:49 +0200:

Quoted 19 lines

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
v2: use CFE_EPTSEAL definition and avoid using an additional funtion.

drivers/mtd/parsers/bcm63xxpart.c | 29 ++++-------------------------

1 file changed, 4 insertions(+), 25 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +0 -0
index 78f90c6c18fd..493a75b2f266 100644
@@ -22,6 +22,9 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
Quoted 4 lines

drivers/mtd/parsers/bcm63xxpart.c line 26

Quoted 2 lines
drivers/mtd/parsers/bcm63xxpart.c +2 -0
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>  

Are you sure both includes are needed?

asm/bootinfo.h is needed for fw_arg3 and asm/fw/cfe/cfe_api.h is needed for CFE_EPTSEAL.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

I don't think it is a good habit to include asm/ headers, are you sure there is not another header doing it just fine?

Both are needed unless you want to add another definition of CFE_EPTSEAL value.
There are currently two CFE magic definitions, the one in asm/fw/cfe/cfe_api.h and another one in bcm47xxpart.c:
https://github.com/torvalds/linux/blob/master/arch/mips/include/asm/fw/cfe/cfe_api.h#L28
https://github.com/torvalds/linux/blob/master/drivers/mtd/parsers/bcm47xxpart.c#L33

Quoted 8 lines

The caveat with that approach is that this reduces the compilation surface to MIPS and BMIPS_GENERIC and BCM63XX only, which is a bit small. If we could move the CFE definitions to a shared header, and consolidate the value used by bcm47xxpart.c as well, that would allow us to build the bcm63xxpart.c file with COMPILE_TEST on other architectures. This does not really have functional value, but for maintainers like Miquel, it allows them to quickly test their entire drivers/mtd/ directory.

Quoted 2 lines

I don’t think fw_arg3 available on non mips archs, is it?
I’m happy to move it to a shared header (which would be a good location for this?), but if I’m right it would still be restricted to MIPS.

Quoted 9 lines

Restricting a definition to MIPS, even if it makes sense for you is very limiting for me. I need to be able to build as much drivers as I can from my laptop and verify they at least compile correctly. If I need a MIPS toolchain, an ARC toolchain, a PowerPC, an ARM, an ARM64 and whatever other funky toolchain to do just that in X steps: it's very painful. We have been adding COMPILE_TEST dependencies on as much drivers as we could and we want to continue moving forward. Using such include would need to drop the COMPILE_TEST condition from Kconfig and this is not something I am willing to do.

I totally understand and agree with your point, but I still think that there could be a solution which would be valid for both of us.

Quoted 2 lines

Thanks for your understanding :)

The current way of detecting CFE isn’t the proper one. Thank you for understanding that too.

Quoted 1 line

Miquèl

Best regards,
Álvaro.

maintainer
#12 lore raw

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Fri, 12 Jun 2020 09:30:27 +0200:

Quoted 82 lines

Hi Miquèl,

Quoted 70 lines · Miquel Raynal

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Thu, 11 Jun 2020 18:14:20 +0200:

Quoted 60 lines

Hi Florian,

Quoted 49 lines · Florian Fainelli
Quoted 36 lines · Álvaro Fernández Rojas

Hi Miquel,

Quoted 26 lines · Miquel Raynal

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Mon, 8 Jun 2020 18:06:49 +0200:

Quoted 19 lines

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
v2: use CFE_EPTSEAL definition and avoid using an additional funtion.

drivers/mtd/parsers/bcm63xxpart.c | 29 ++++-------------------------

1 file changed, 4 insertions(+), 25 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +0 -0
index 78f90c6c18fd..493a75b2f266 100644
@@ -22,6 +22,9 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
Quoted 4 lines

drivers/mtd/parsers/bcm63xxpart.c line 26

Quoted 2 lines
drivers/mtd/parsers/bcm63xxpart.c +2 -0
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>    

Are you sure both includes are needed?

asm/bootinfo.h is needed for fw_arg3 and asm/fw/cfe/cfe_api.h is needed for CFE_EPTSEAL.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

I don't think it is a good habit to include asm/ headers, are you sure there is not another header doing it just fine?

Both are needed unless you want to add another definition of CFE_EPTSEAL value.
There are currently two CFE magic definitions, the one in asm/fw/cfe/cfe_api.h and another one in bcm47xxpart.c:
https://github.com/torvalds/linux/blob/master/arch/mips/include/asm/fw/cfe/cfe_api.h#L28
https://github.com/torvalds/linux/blob/master/drivers/mtd/parsers/bcm47xxpart.c#L33

Quoted 8 lines

The caveat with that approach is that this reduces the compilation surface to MIPS and BMIPS_GENERIC and BCM63XX only, which is a bit small. If we could move the CFE definitions to a shared header, and consolidate the value used by bcm47xxpart.c as well, that would allow us to build the bcm63xxpart.c file with COMPILE_TEST on other architectures. This does not really have functional value, but for maintainers like Miquel, it allows them to quickly test their entire drivers/mtd/ directory.

Quoted 2 lines

I don’t think fw_arg3 available on non mips archs, is it?
I’m happy to move it to a shared header (which would be a good location for this?), but if I’m right it would still be restricted to MIPS.

Quoted 9 lines

Restricting a definition to MIPS, even if it makes sense for you is very limiting for me. I need to be able to build as much drivers as I can from my laptop and verify they at least compile correctly. If I need a MIPS toolchain, an ARC toolchain, a PowerPC, an ARM, an ARM64 and whatever other funky toolchain to do just that in X steps: it's very painful. We have been adding COMPILE_TEST dependencies on as much drivers as we could and we want to continue moving forward. Using such include would need to drop the COMPILE_TEST condition from Kconfig and this is not something I am willing to do.

Quoted 1 line

I totally understand and agree with your point, but I still think that there could be a solution which would be valid for both of us.

What do you suggest?

Quoted 6 lines
Quoted 3 lines

Thanks for your understanding :)

The current way of detecting CFE isn’t the proper one. Thank you for understanding that too.

Of course, I'm not saying I don't want this change, I'm just saying we should find another way to handle it, the below idea is totally fine by me.

Thanks,
Miquèl

#13 lore raw

Hi Miquèl,

Quoted 89 lines · Miquel Raynal

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Fri, 12 Jun 2020 09:30:27 +0200:

Quoted 82 lines

Hi Miquèl,

Quoted 79 lines · Miquel Raynal

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Thu, 11 Jun 2020 18:14:20 +0200:

Quoted 60 lines

Hi Florian,

Quoted 49 lines · Florian Fainelli
Quoted 36 lines · Álvaro Fernández Rojas

Hi Miquel,

Quoted 26 lines · Miquel Raynal

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Mon, 8 Jun 2020 18:06:49 +0200:

Quoted 19 lines

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
v2: use CFE_EPTSEAL definition and avoid using an additional funtion.

drivers/mtd/parsers/bcm63xxpart.c | 29 ++++-------------------------

1 file changed, 4 insertions(+), 25 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +0 -0
index 78f90c6c18fd..493a75b2f266 100644
@@ -22,6 +22,9 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
Quoted 4 lines

drivers/mtd/parsers/bcm63xxpart.c line 26

Quoted 2 lines
drivers/mtd/parsers/bcm63xxpart.c +2 -0
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>    

Are you sure both includes are needed?

asm/bootinfo.h is needed for fw_arg3 and asm/fw/cfe/cfe_api.h is needed for CFE_EPTSEAL.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

I don't think it is a good habit to include asm/ headers, are you sure there is not another header doing it just fine?

Both are needed unless you want to add another definition of CFE_EPTSEAL value.
There are currently two CFE magic definitions, the one in asm/fw/cfe/cfe_api.h and another one in bcm47xxpart.c:
https://github.com/torvalds/linux/blob/master/arch/mips/include/asm/fw/cfe/cfe_api.h#L28
https://github.com/torvalds/linux/blob/master/drivers/mtd/parsers/bcm47xxpart.c#L33

Quoted 8 lines

The caveat with that approach is that this reduces the compilation surface to MIPS and BMIPS_GENERIC and BCM63XX only, which is a bit small. If we could move the CFE definitions to a shared header, and consolidate the value used by bcm47xxpart.c as well, that would allow us to build the bcm63xxpart.c file with COMPILE_TEST on other architectures. This does not really have functional value, but for maintainers like Miquel, it allows them to quickly test their entire drivers/mtd/ directory.

Quoted 2 lines

I don’t think fw_arg3 available on non mips archs, is it?
I’m happy to move it to a shared header (which would be a good location for this?), but if I’m right it would still be restricted to MIPS.

Restricting a definition to MIPS, even if it makes sense for you is very limiting for me. I need to be able to build as much drivers as I can from my laptop and verify they at least compile correctly. If I need a MIPS toolchain, an ARC toolchain, a PowerPC, an ARM, an ARM64 and whatever other funky toolchain to do just that in X steps: it's very painful. We have been adding COMPILE_TEST dependencies on as much drivers as we could and we want to continue moving forward. Using such include would need to drop the COMPILE_TEST condition from Kconfig and this is not something I am willing to do.

Quoted 3 lines
Quoted 1 line

I totally understand and agree with your point, but I still think that there could be a solution which would be valid for both of us.

What do you suggest?

I’ve just sent v3 with my suggestion.
If this isn’t valid then I’m out of ideas...

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Thanks for your understanding :)

The current way of detecting CFE isn’t the proper one. Thank you for understanding that too.

Quoted 7 lines

Of course, I'm not saying I don't want this change, I'm just saying we should find another way to handle it, the below idea is totally fine by me.

Thanks,
Miquèl

Regards,
Álvaro.

#14 lore raw

PATCH v3 1/1 mtd: parsers: bcm63xx: simplify CFE detection

In reply to Álvaro Fernández Rojas

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
v3: keep COMPILE_TEST compatibility by adding a new function that only checks
fw_arg3 when CONFIG_MIPS is defined.
v2: use CFE_EPTSEAL definition and avoid using an additional function.

 drivers/mtd/parsers/bcm63xxpart.c | 34 +++++++++++--------------------
 1 file changed, 12 insertions(+), 22 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +12 -22
index 78f90c6c18fd..c514c04789af 100644
@@ -22,6 +22,11 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
+#ifdef CONFIG_MIPS
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>
+#endif /* CONFIG_MIPS */
+
 #define BCM963XX_CFE_BLOCK_SIZE		SZ_64K	/* always at least 64KiB */
 
 #define BCM963XX_CFE_MAGIC_OFFSET	0x4e0
@@ -32,28 +37,13 @@
 #define STR_NULL_TERMINATE(x) \
 	do { char *_str = (x); _str[sizeof(x) - 1] = 0; } while (0)
 
-static int bcm63xx_detect_cfe(struct mtd_info *master)
+static inline int bcm63xx_detect_cfe(void)
 {
-	char buf[9];
-	int ret;
-	size_t retlen;
-
-	ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	if (ret)
-		return ret;
-
-	if (strncmp("cfe-v", buf, 5) == 0)
-		return 0;
-
-	/* very old CFE's do not have the cfe-v string, so check for magic */
-	ret = mtd_read(master, BCM963XX_CFE_MAGIC_OFFSET, 8, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	return strncmp("CFE1CFE1", buf, 8);
+#ifdef CONFIG_MIPS
+	return (fw_arg3 == CFE_EPTSEAL);
+#else
+	return 0;
+#endif /* CONFIG_MIPS */
 }
 
 static int bcm63xx_read_nvram(struct mtd_info *master,
@@ -138,7 +128,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
 	struct bcm963xx_nvram *nvram = NULL;
 	int ret;
 
-	if (bcm63xx_detect_cfe(master))
+	if (!bcm63xx_detect_cfe())
 		return -EINVAL;
 
 	nvram = vzalloc(sizeof(*nvram));
Signature · 1 line
2.26.2
maintainer
#15 lore raw

Hi Álvaro,

Álvaro Fernández Rojas <[email protected]> wrote on Fri, 12 Jun 2020 09:35:49 +0200:

Quoted 51 lines

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
v3: keep COMPILE_TEST compatibility by adding a new function that only checks
fw_arg3 when CONFIG_MIPS is defined.
v2: use CFE_EPTSEAL definition and avoid using an additional function.

 drivers/mtd/parsers/bcm63xxpart.c | 34 +++++++++++--------------------
 1 file changed, 12 insertions(+), 22 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +6 -16
index 78f90c6c18fd..c514c04789af 100644
@@ -22,6 +22,11 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
+#ifdef CONFIG_MIPS
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>
+#endif /* CONFIG_MIPS */
+
 #define BCM963XX_CFE_BLOCK_SIZE		SZ_64K	/* always at least 64KiB */
 
 #define BCM963XX_CFE_MAGIC_OFFSET	0x4e0
@@ -32,28 +37,13 @@
 #define STR_NULL_TERMINATE(x) \
 	do { char *_str = (x); _str[sizeof(x) - 1] = 0; } while (0)
 
-static int bcm63xx_detect_cfe(struct mtd_info *master)
+static inline int bcm63xx_detect_cfe(void)
 {
-	char buf[9];
-	int ret;
-	size_t retlen;
-
-	ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	if (ret)
-		return ret;
-
-	if (strncmp("cfe-v", buf, 5) == 0)
-		return 0;
-
-	/* very old CFE's do not have the cfe-v string, so check for magic */

drivers/mtd/parsers/bcm63xxpart.c line 46

Quoted 10 lines
drivers/mtd/parsers/bcm63xxpart.c +5 -5
-	ret = mtd_read(master, BCM963XX_CFE_MAGIC_OFFSET, 8, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	return strncmp("CFE1CFE1", buf, 8);
+#ifdef CONFIG_MIPS
+	return (fw_arg3 == CFE_EPTSEAL);
+#else
+	return 0;
+#endif /* CONFIG_MIPS */

What about:

	ret = 0;
#ifdef CONFIG_MIPS
	ret = (fw_arg3 == CFE_EPTSEAL)

#endif

	return ret;

This is for shortening the conditional part.

drivers/mtd/parsers/bcm63xxpart.c static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, · line 134

Quoted 12 lines
drivers/mtd/parsers/bcm63xxpart.c +1 -1
 }
 
 static int bcm63xx_read_nvram(struct mtd_info *master,
@@ -138,7 +128,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
 	struct bcm963xx_nvram *nvram = NULL;
 	int ret;
 
-	if (bcm63xx_detect_cfe(master))
+	if (!bcm63xx_detect_cfe())
 		return -EINVAL;
 
 	nvram = vzalloc(sizeof(*nvram));

Thanks,
Miquèl

#16 lore raw

PATCH v4 1/1 mtd: parsers: bcm63xx: simplify CFE detection

In reply to Álvaro Fernández Rojas

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

---
v4: shorten conditional compilation part as suggested by Miquèl.
v3: keep COMPILE_TEST compatibility by adding a new function that only checks
fw_arg3 when CONFIG_MIPS is defined.
v2: use CFE_EPTSEAL definition and avoid using an additional function.

 drivers/mtd/parsers/bcm63xxpart.c | 32 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 20 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +12 -20
index 78f90c6c18fd..b15bdadaedb5 100644
@@ -22,6 +22,11 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
+#ifdef CONFIG_MIPS
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>
+#endif /* CONFIG_MIPS */
+
 #define BCM963XX_CFE_BLOCK_SIZE		SZ_64K	/* always at least 64KiB */
 
 #define BCM963XX_CFE_MAGIC_OFFSET	0x4e0
@@ -32,28 +37,15 @@
 #define STR_NULL_TERMINATE(x) \
 	do { char *_str = (x); _str[sizeof(x) - 1] = 0; } while (0)
 
-static int bcm63xx_detect_cfe(struct mtd_info *master)
+static inline int bcm63xx_detect_cfe(void)
 {
-	char buf[9];
-	int ret;
-	size_t retlen;
+	int ret = 0;
 
-	ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
+#ifdef CONFIG_MIPS
+	ret = (fw_arg3 == CFE_EPTSEAL);
+#endif /* CONFIG_MIPS */
 
-	if (ret)
-		return ret;
-
-	if (strncmp("cfe-v", buf, 5) == 0)
-		return 0;
-
-	/* very old CFE's do not have the cfe-v string, so check for magic */
-	ret = mtd_read(master, BCM963XX_CFE_MAGIC_OFFSET, 8, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	return strncmp("CFE1CFE1", buf, 8);
+	return ret;
 }
 
 static int bcm63xx_read_nvram(struct mtd_info *master,
@@ -138,7 +130,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
 	struct bcm963xx_nvram *nvram = NULL;
 	int ret;
 
-	if (bcm63xx_detect_cfe(master))
+	if (!bcm63xx_detect_cfe())
 		return -EINVAL;
 
 	nvram = vzalloc(sizeof(*nvram));
Signature · 1 line
2.27.0
maintainer Applied
#18 lore raw
In reply to Álvaro Fernández Rojas
Quoted 6 lines · On Mon, 2020-06-15 at 09:17:40 UTC, =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Rojas?…

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

#19 lore raw
In reply to Álvaro Fernández Rojas
Quoted 6 lines · Álvaro Fernández Rojas

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

mips:allmodconfig:

ERROR: modpost: "fw_arg3" [drivers/mtd/parsers/bcm63xxpart.ko] undefined!

This is not surprising, since fw_arg3 is not exported.

Guenter

Quoted 69 lines

---
v4: shorten conditional compilation part as suggested by Miquèl.
v3: keep COMPILE_TEST compatibility by adding a new function that only checks
fw_arg3 when CONFIG_MIPS is defined.
v2: use CFE_EPTSEAL definition and avoid using an additional function.

 drivers/mtd/parsers/bcm63xxpart.c | 32 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 20 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +12 -20
index 78f90c6c18fd..b15bdadaedb5 100644
@@ -22,6 +22,11 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
+#ifdef CONFIG_MIPS
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>
+#endif /* CONFIG_MIPS */
+
 #define BCM963XX_CFE_BLOCK_SIZE		SZ_64K	/* always at least 64KiB */
 
 #define BCM963XX_CFE_MAGIC_OFFSET	0x4e0
@@ -32,28 +37,15 @@
 #define STR_NULL_TERMINATE(x) \
 	do { char *_str = (x); _str[sizeof(x) - 1] = 0; } while (0)
 
-static int bcm63xx_detect_cfe(struct mtd_info *master)
+static inline int bcm63xx_detect_cfe(void)
 {
-	char buf[9];
-	int ret;
-	size_t retlen;
+	int ret = 0;
 
-	ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
+#ifdef CONFIG_MIPS
+	ret = (fw_arg3 == CFE_EPTSEAL);
+#endif /* CONFIG_MIPS */
 
-	if (ret)
-		return ret;
-
-	if (strncmp("cfe-v", buf, 5) == 0)
-		return 0;
-
-	/* very old CFE's do not have the cfe-v string, so check for magic */
-	ret = mtd_read(master, BCM963XX_CFE_MAGIC_OFFSET, 8, &retlen,
-		       (void *)buf);
-	buf[retlen] = 0;
-
-	return strncmp("CFE1CFE1", buf, 8);
+	return ret;
 }
 
 static int bcm63xx_read_nvram(struct mtd_info *master,
@@ -138,7 +130,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
 	struct bcm963xx_nvram *nvram = NULL;
 	int ret;
 
-	if (bcm63xx_detect_cfe(master))
+	if (!bcm63xx_detect_cfe())
 		return -EINVAL;
 
 	nvram = vzalloc(sizeof(*nvram));
#20 lore raw
Quoted 9 lines · Guenter Roeck
Quoted 6 lines · Álvaro Fernández Rojas

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

We still see mips: allmodconfig build failure on Linus tree

make -sk KBUILD_BUILD_USER=TuxBuild -C/linux ARCH=mips CROSS_COMPILE=mips-linux-gnu- HOSTCC=gcc CC="sccache mips-linux-gnu-gcc" O=build allmodconfig

make -sk KBUILD_BUILD_USER=TuxBuild -C/linux -j16 ARCH=mips CROSS_COMPILE=mips-linux-gnu- HOSTCC=gcc CC="sccache mips-linux-gnu-gcc" O=build

Quoted 3 lines

mips:allmodconfig:

ERROR: modpost: "fw_arg3" [drivers/mtd/parsers/bcm63xxpart.ko] undefined!

ERROR: modpost: "fw_arg3" [drivers/mtd/parsers/bcm63xxpart.ko] undefined!

Full build link,
https://builds.tuxbuild.com/Sm59_9tjFMpIvT27qf5kNA/build.log

Quoted 74 lines

This is not surprising, since fw_arg3 is not exported.

Guenter

Quoted 69 lines

---
v4: shorten conditional compilation part as suggested by Miquèl.
v3: keep COMPILE_TEST compatibility by adding a new function that only checks
fw_arg3 when CONFIG_MIPS is defined.
v2: use CFE_EPTSEAL definition and avoid using an additional function.

 drivers/mtd/parsers/bcm63xxpart.c | 32 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 20 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +12 -20
index 78f90c6c18fd..b15bdadaedb5 100644
@@ -22,6 +22,11 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
+#ifdef CONFIG_MIPS
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>
+#endif /* CONFIG_MIPS */
+
 #define BCM963XX_CFE_BLOCK_SIZE              SZ_64K  /* always at least 64KiB */
 
 #define BCM963XX_CFE_MAGIC_OFFSET    0x4e0
@@ -32,28 +37,15 @@
 #define STR_NULL_TERMINATE(x) \
      do { char *_str = (x); _str[sizeof(x) - 1] = 0; } while (0)
 
-static int bcm63xx_detect_cfe(struct mtd_info *master)
+static inline int bcm63xx_detect_cfe(void)
 {
-     char buf[9];
-     int ret;
-     size_t retlen;
+     int ret = 0;
 
-     ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen,
-                    (void *)buf);
-     buf[retlen] = 0;
+#ifdef CONFIG_MIPS
+     ret = (fw_arg3 == CFE_EPTSEAL);
+#endif /* CONFIG_MIPS */
 
-     if (ret)
-             return ret;
-
-     if (strncmp("cfe-v", buf, 5) == 0)
-             return 0;
-
-     /* very old CFE's do not have the cfe-v string, so check for magic */
-     ret = mtd_read(master, BCM963XX_CFE_MAGIC_OFFSET, 8, &retlen,
-                    (void *)buf);
-     buf[retlen] = 0;
-
-     return strncmp("CFE1CFE1", buf, 8);
+     return ret;
 }
 
 static int bcm63xx_read_nvram(struct mtd_info *master,
@@ -138,7 +130,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
      struct bcm963xx_nvram *nvram = NULL;
      int ret;
 
-     if (bcm63xx_detect_cfe(master))
+     if (!bcm63xx_detect_cfe())
              return -EINVAL;
 
      nvram = vzalloc(sizeof(*nvram));
#21 lore raw
Quoted 6 lines · Naresh Kamboju
Quoted 5 lines · Guenter Roeck
Quoted 3 lines · Álvaro Fernández Rojas

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

We still see mips: allmodconfig build failure on Linus tree

Yes, same here.

Guenter

Quoted 94 lines

make -sk KBUILD_BUILD_USER=TuxBuild -C/linux ARCH=mips CROSS_COMPILE=mips-linux-gnu- HOSTCC=gcc CC="sccache mips-linux-gnu-gcc" O=build allmodconfig

make -sk KBUILD_BUILD_USER=TuxBuild -C/linux -j16 ARCH=mips CROSS_COMPILE=mips-linux-gnu- HOSTCC=gcc CC="sccache mips-linux-gnu-gcc" O=build

Quoted 3 lines

mips:allmodconfig:

ERROR: modpost: "fw_arg3" [drivers/mtd/parsers/bcm63xxpart.ko] undefined!

ERROR: modpost: "fw_arg3" [drivers/mtd/parsers/bcm63xxpart.ko] undefined!

Full build link,
https://builds.tuxbuild.com/Sm59_9tjFMpIvT27qf5kNA/build.log

Quoted 74 lines

This is not surprising, since fw_arg3 is not exported.

Guenter

Quoted 69 lines

---
v4: shorten conditional compilation part as suggested by Miquèl.
v3: keep COMPILE_TEST compatibility by adding a new function that only checks
fw_arg3 when CONFIG_MIPS is defined.
v2: use CFE_EPTSEAL definition and avoid using an additional function.

 drivers/mtd/parsers/bcm63xxpart.c | 32 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 20 deletions(-)
drivers/mtd/parsers/bcm63xxpart.c +12 -20
index 78f90c6c18fd..b15bdadaedb5 100644
@@ -22,6 +22,11 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 
+#ifdef CONFIG_MIPS
+#include <asm/bootinfo.h>
+#include <asm/fw/cfe/cfe_api.h>
+#endif /* CONFIG_MIPS */
+
 #define BCM963XX_CFE_BLOCK_SIZE              SZ_64K  /* always at least 64KiB */
 
 #define BCM963XX_CFE_MAGIC_OFFSET    0x4e0
@@ -32,28 +37,15 @@
 #define STR_NULL_TERMINATE(x) \
      do { char *_str = (x); _str[sizeof(x) - 1] = 0; } while (0)
 
-static int bcm63xx_detect_cfe(struct mtd_info *master)
+static inline int bcm63xx_detect_cfe(void)
 {
-     char buf[9];
-     int ret;
-     size_t retlen;
+     int ret = 0;
 
-     ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen,
-                    (void *)buf);
-     buf[retlen] = 0;
+#ifdef CONFIG_MIPS
+     ret = (fw_arg3 == CFE_EPTSEAL);
+#endif /* CONFIG_MIPS */
 
-     if (ret)
-             return ret;
-
-     if (strncmp("cfe-v", buf, 5) == 0)
-             return 0;
-
-     /* very old CFE's do not have the cfe-v string, so check for magic */
-     ret = mtd_read(master, BCM963XX_CFE_MAGIC_OFFSET, 8, &retlen,
-                    (void *)buf);
-     buf[retlen] = 0;
-
-     return strncmp("CFE1CFE1", buf, 8);
+     return ret;
 }
 
 static int bcm63xx_read_nvram(struct mtd_info *master,
@@ -138,7 +130,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
      struct bcm963xx_nvram *nvram = NULL;
      int ret;
 
-     if (bcm63xx_detect_cfe(master))
+     if (!bcm63xx_detect_cfe())
              return -EINVAL;
 
      nvram = vzalloc(sizeof(*nvram));
maintainer
#22 lore raw

Hello,

Guenter Roeck <[email protected]> wrote on Mon, 21 Sep 2020 20:26:19 -0700:

Quoted 12 lines · Naresh Kamboju
Quoted 11 lines · Guenter Roeck
Quoted 9 lines · Álvaro Fernández Rojas
Quoted 6 lines

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

Quoted 4 lines
Quoted 2 lines

We still see mips: allmodconfig build failure on Linus tree

Yes, same here.

Perhaps this check should be done by an exported helper so that we do not blindly export the variable?

Alvaro, Jonas, can one of you try to address this issue please?

Thanks,
Miquèl

#23 lore raw
Quoted 20 lines · Miquel Raynal

Hello,

Guenter Roeck <[email protected]> wrote on Mon, 21 Sep 2020 20:26:19 -0700:

Quoted 15 lines · Naresh Kamboju
Quoted 13 lines · Guenter Roeck
Quoted 9 lines · Álvaro Fernández Rojas
Quoted 6 lines

Instead of trying to parse CFE version string, which is customized by some vendors, let's just check that "CFE1" was passed on argument 3.

We still see mips: allmodconfig build failure on Linus tree

Quoted 6 lines
Quoted 1 line

Yes, same here.

Perhaps this check should be done by an exported helper so that we do not blindly export the variable?

Alvaro, Jonas, can one of you try to address this issue please?

We should probably just make the parser 'bool' there is no much point building this as a module, it will not improve compile time coverage, and it will most likely not help with the kernel image size on the platforms that require the parser to be there anyway.

Signature · 1 line
Florian
#24 lore raw

PATCH 1/1 mtd: parsers: bcm63xx: Do not make it modular

In reply to Miquel Raynal

With commit 91e81150d388 ("mtd: parsers: bcm63xx: simplify CFE detection"), we generate a reference to fw_arg3 which is the fourth firmware/command line argument on MIPS platforms. That symbol is not exported and would cause a linking failure.

The parser is typically necessary to boot a BCM63xx-based system anyway so having it be part of the kernel image makes sense, therefore make it 'bool' instead of 'tristate'.

Fixes 91e81150d388 ("mtd: parsers: bcm63xx: simplify CFE detection")
---
 drivers/mtd/parsers/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/parsers/Kconfig +1 -1
index f98363c9b363..e72354322f62 100644
@@ -12,7 +12,7 @@ config MTD_BCM47XX_PARTS
 	  boards.
 
 config MTD_BCM63XX_PARTS
-	tristate "BCM63XX CFE partitioning parser"
+	bool "BCM63XX CFE partitioning parser"
 	depends on BCM63XX || BMIPS_GENERIC || COMPILE_TEST
 	select CRC32
 	select MTD_PARSER_IMAGETAG
Signature · 1 line
2.25.1
maintainer Applied
#25 lore raw

Re: [PATCH] mtd: parsers: bcm63xx: Do not make it modular

Quoted 11 lines · Florian Fainelli

With commit 91e81150d388 ("mtd: parsers: bcm63xx: simplify CFE detection"), we generate a reference to fw_arg3 which is the fourth firmware/command line argument on MIPS platforms. That symbol is not exported and would cause a linking failure.

The parser is typically necessary to boot a BCM63xx-based system anyway so having it be part of the kernel image makes sense, therefore make it 'bool' instead of 'tristate'.

Fixes 91e81150d388 ("mtd: parsers: bcm63xx: simplify CFE detection")

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

#26 lore raw

Re: [PATCH] mtd: parsers: bcm63xx: Do not make it modular

In reply to Florian Fainelli
Quoted 11 lines · Florian Fainelli

With commit 91e81150d388 ("mtd: parsers: bcm63xx: simplify CFE detection"), we generate a reference to fw_arg3 which is the fourth firmware/command line argument on MIPS platforms. That symbol is not exported and would cause a linking failure.

The parser is typically necessary to boot a BCM63xx-based system anyway so having it be part of the kernel image makes sense, therefore make it 'bool' instead of 'tristate'.

Fixes 91e81150d388 ("mtd: parsers: bcm63xx: simplify CFE detection")

What happened with this patch ? The build failure is still seen in mainline and in next-20201009.

Guenter

Quoted 20 lines
---
 drivers/mtd/parsers/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/parsers/Kconfig +1 -1
index f98363c9b363..e72354322f62 100644
@@ -12,7 +12,7 @@ config MTD_BCM47XX_PARTS
 	  boards.
 
 config MTD_BCM63XX_PARTS
-	tristate "BCM63XX CFE partitioning parser"
+	bool "BCM63XX CFE partitioning parser"
 	depends on BCM63XX || BMIPS_GENERIC || COMPILE_TEST
 	select CRC32
 	select MTD_PARSER_IMAGETAG
Signature · 1 line
2.25.1
maintainer
#27 lore raw

Re: [PATCH] mtd: parsers: bcm63xx: Do not make it modular

Hi Guenter,

Guenter Roeck <[email protected]> wrote on Sun, 11 Oct 2020 07:14:47 -0700:

Quoted 10 lines · Florian Fainelli
Quoted 9 lines

With commit 91e81150d388 ("mtd: parsers: bcm63xx: simplify CFE detection"), we generate a reference to fw_arg3 which is the fourth firmware/command line argument on MIPS platforms. That symbol is not exported and would cause a linking failure.

The parser is typically necessary to boot a BCM63xx-based system anyway so having it be part of the kernel image makes sense, therefore make it 'bool' instead of 'tristate'.

Quoted 5 lines
Quoted 2 lines
Fixes 91e81150d388 ("mtd: parsers: bcm63xx: simplify CFE detection")

What happened with this patch ? The build failure is still seen in mainline and in next-20201009.

It has been applied on mtd/next:
https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git/log/?h=mtd/next
(I don't remember when though)

#28 lore raw

Re: [PATCH] mtd: parsers: bcm63xx: Do not make it modular

Quoted 18 lines · Miquel Raynal

Hi Guenter,

Guenter Roeck <[email protected]> wrote on Sun, 11 Oct 2020 07:14:47 -0700:

Quoted 13 lines · Florian Fainelli
Quoted 11 lines

With commit 91e81150d388 ("mtd: parsers: bcm63xx: simplify CFE detection"), we generate a reference to fw_arg3 which is the fourth firmware/command line argument on MIPS platforms. That symbol is not exported and would cause a linking failure.

The parser is typically necessary to boot a BCM63xx-based system anyway so having it be part of the kernel image makes sense, therefore make it 'bool' instead of 'tristate'.

Fixes 91e81150d388 ("mtd: parsers: bcm63xx: simplify CFE detection")
Quoted 6 lines
Quoted 2 lines

What happened with this patch ? The build failure is still seen in mainline and in next-20201009.

It has been applied on mtd/next:
https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git/log/?h=mtd/next
(I don't remember when though)

Hmm, lets see ...

Ah, I see: mips:allmodconfig now fails to build in -next for a different reason.

Error log:
In file included from <command-line>:
arch/mips/mm/init.c: In function 'mem_init':
include/linux/compiler_types.h:319:38: error: call to '__compiletime_assert_331'

	declared with attribute error: BUILD_BUG_ON failed: IS_ENABLED(CONFIG_32BIT) && (_PFN_SHIFT > PAGE_SHIFT)

I'll send a separate report on that (if it wasn't reported before).

Anyway, any reason for not applying this fix to mainline, ie why the mips:allmodconfig build failure was not fixed in v5.9 ?

Guenter