b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From 91e81150d38842b58133ce1a5d70c88e8f1cf7c1 Mon Sep 17 00:00:00 2001 |
| 2 | From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= <noltari@gmail.com> |
| 3 | Date: Mon, 15 Jun 2020 11:17:40 +0200 |
| 4 | Subject: [PATCH] mtd: parsers: bcm63xx: simplify CFE detection |
| 5 | MIME-Version: 1.0 |
| 6 | Content-Type: text/plain; charset=UTF-8 |
| 7 | Content-Transfer-Encoding: 8bit |
| 8 | |
| 9 | Instead of trying to parse CFE version string, which is customized by some |
| 10 | vendors, let's just check that "CFE1" was passed on argument 3. |
| 11 | |
| 12 | Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> |
| 13 | Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com> |
| 14 | Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> |
| 15 | Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> |
| 16 | Link: https://lore.kernel.org/linux-mtd/20200615091740.2958303-1-noltari@gmail.com |
| 17 | --- |
| 18 | drivers/mtd/parsers/bcm63xxpart.c | 32 ++++++++++++------------------- |
| 19 | 1 file changed, 12 insertions(+), 20 deletions(-) |
| 20 | |
| 21 | --- a/drivers/mtd/parsers/bcm63xxpart.c |
| 22 | +++ b/drivers/mtd/parsers/bcm63xxpart.c |
| 23 | @@ -22,6 +22,11 @@ |
| 24 | #include <linux/mtd/partitions.h> |
| 25 | #include <linux/of.h> |
| 26 | |
| 27 | +#ifdef CONFIG_MIPS |
| 28 | +#include <asm/bootinfo.h> |
| 29 | +#include <asm/fw/cfe/cfe_api.h> |
| 30 | +#endif /* CONFIG_MIPS */ |
| 31 | + |
| 32 | #define BCM963XX_CFE_BLOCK_SIZE SZ_64K /* always at least 64KiB */ |
| 33 | |
| 34 | #define BCM963XX_CFE_MAGIC_OFFSET 0x4e0 |
| 35 | @@ -32,28 +37,15 @@ |
| 36 | #define STR_NULL_TERMINATE(x) \ |
| 37 | do { char *_str = (x); _str[sizeof(x) - 1] = 0; } while (0) |
| 38 | |
| 39 | -static int bcm63xx_detect_cfe(struct mtd_info *master) |
| 40 | +static inline int bcm63xx_detect_cfe(void) |
| 41 | { |
| 42 | - char buf[9]; |
| 43 | - int ret; |
| 44 | - size_t retlen; |
| 45 | - |
| 46 | - ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen, |
| 47 | - (void *)buf); |
| 48 | - buf[retlen] = 0; |
| 49 | - |
| 50 | - if (ret) |
| 51 | - return ret; |
| 52 | - |
| 53 | - if (strncmp("cfe-v", buf, 5) == 0) |
| 54 | - return 0; |
| 55 | + int ret = 0; |
| 56 | |
| 57 | - /* very old CFE's do not have the cfe-v string, so check for magic */ |
| 58 | - ret = mtd_read(master, BCM963XX_CFE_MAGIC_OFFSET, 8, &retlen, |
| 59 | - (void *)buf); |
| 60 | - buf[retlen] = 0; |
| 61 | +#ifdef CONFIG_MIPS |
| 62 | + ret = (fw_arg3 == CFE_EPTSEAL); |
| 63 | +#endif /* CONFIG_MIPS */ |
| 64 | |
| 65 | - return strncmp("CFE1CFE1", buf, 8); |
| 66 | + return ret; |
| 67 | } |
| 68 | |
| 69 | static int bcm63xx_read_nvram(struct mtd_info *master, |
| 70 | @@ -138,7 +130,7 @@ static int bcm63xx_parse_cfe_partitions( |
| 71 | struct bcm963xx_nvram *nvram = NULL; |
| 72 | int ret; |
| 73 | |
| 74 | - if (bcm63xx_detect_cfe(master)) |
| 75 | + if (!bcm63xx_detect_cfe()) |
| 76 | return -EINVAL; |
| 77 | |
| 78 | nvram = vzalloc(sizeof(*nvram)); |