From edf3363959d3c43235dac2e973851ad572f082ae Mon Sep 17 00:00:00 2001 From: Christian Marangi Date: Wed, 21 Sep 2022 10:43:55 +0200 Subject: [PATCH 01/16] kernel: backport mtd dynamic partition patch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backport upstream solution that permits to declare nvmem cells with dynamic partition defined by special parser. This provide an OF node for NVMEM and connect it to the defined dynamic partition. Signed-off-by: Christian Marangi Signed-off-by: Rafał Miłecki (cherry picked from commit 1a9ee367343edce263f82cc91a49d796c9d45ea3) --- ...ce-of-support-for-dynamic-partitions.patch | 106 ++++++++++++++++++ ...g-MTD-device-associated-with-a-speci.patch | 2 +- .../480-mtd-set-rootfs-to-be-root-dev.patch | 2 +- ...-mtd-core-add-get_mtd_device_by_node.patch | 2 +- ...or-support-mtd-name-from-device-tree.patch | 2 +- 5 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 target/linux/generic/backport-5.4/413-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch diff --git a/target/linux/generic/backport-5.4/413-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch b/target/linux/generic/backport-5.4/413-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch new file mode 100644 index 0000000000..475f72f272 --- /dev/null +++ b/target/linux/generic/backport-5.4/413-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch @@ -0,0 +1,106 @@ +From ad9b10d1eaada169bd764abcab58f08538877e26 Mon Sep 17 00:00:00 2001 +From: Christian Marangi +Date: Wed, 22 Jun 2022 03:06:28 +0200 +Subject: mtd: core: introduce of support for dynamic partitions + +We have many parser that register mtd partitions at runtime. One example +is the cmdlinepart or the smem-part parser where the compatible is defined +in the dts and the partitions gets detected and registered by the +parser. This is problematic for the NVMEM subsystem that requires an OF +node to detect NVMEM cells. + +To fix this problem, introduce an additional logic that will try to +assign an OF node to the MTD if declared. + +On MTD addition, it will be checked if the MTD has an OF node and if +not declared will check if a partition with the same label / node name is +declared in DTS. If an exact match is found, the partition dynamically +allocated by the parser will have a connected OF node. + +The NVMEM subsystem will detect the OF node and register any NVMEM cells +declared statically in the DTS. + +Signed-off-by: Christian Marangi +Signed-off-by: Miquel Raynal +Link: https://lore.kernel.org/linux-mtd/20220622010628.30414-4-ansuelsmth@gmail.com +--- + drivers/mtd/mtdcore.c | 61 +++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 61 insertions(+) + +--- a/drivers/mtd/mtdcore.c ++++ b/drivers/mtd/mtdcore.c +@@ -589,6 +589,66 @@ static int mtd_nvmem_add(struct mtd_info + return 0; + } + ++static void mtd_check_of_node(struct mtd_info *mtd) ++{ ++ struct device_node *partitions, *parent_dn, *mtd_dn = NULL; ++ const char *pname, *prefix = "partition-"; ++ int plen, mtd_name_len, offset, prefix_len; ++ struct mtd_info *parent; ++ bool found = false; ++ ++ /* Check if MTD already has a device node */ ++ if (dev_of_node(&mtd->dev)) ++ return; ++ ++ /* Check if a partitions node exist */ ++ parent = mtd_get_master(mtd); ++ parent_dn = dev_of_node(&parent->dev); ++ if (!parent_dn) ++ return; ++ ++ partitions = of_get_child_by_name(parent_dn, "partitions"); ++ if (!partitions) ++ goto exit_parent; ++ ++ prefix_len = strlen(prefix); ++ mtd_name_len = strlen(mtd->name); ++ ++ /* Search if a partition is defined with the same name */ ++ for_each_child_of_node(partitions, mtd_dn) { ++ offset = 0; ++ ++ /* Skip partition with no/wrong prefix */ ++ if (!of_node_name_prefix(mtd_dn, "partition-")) ++ continue; ++ ++ /* Label have priority. Check that first */ ++ if (of_property_read_string(mtd_dn, "label", &pname)) { ++ of_property_read_string(mtd_dn, "name", &pname); ++ offset = prefix_len; ++ } ++ ++ plen = strlen(pname) - offset; ++ if (plen == mtd_name_len && ++ !strncmp(mtd->name, pname + offset, plen)) { ++ found = true; ++ break; ++ } ++ } ++ ++ if (!found) ++ goto exit_partitions; ++ ++ /* Set of_node only for nvmem */ ++ if (of_device_is_compatible(mtd_dn, "nvmem-cells")) ++ mtd_set_of_node(mtd, mtd_dn); ++ ++exit_partitions: ++ of_node_put(partitions); ++exit_parent: ++ of_node_put(parent_dn); ++} ++ + /** + * add_mtd_device - register an MTD device + * @mtd: pointer to new MTD device info structure +@@ -672,6 +732,7 @@ int add_mtd_device(struct mtd_info *mtd) + mtd->dev.devt = MTD_DEVT(i); + dev_set_name(&mtd->dev, "mtd%d", i); + dev_set_drvdata(&mtd->dev, mtd); ++ mtd_check_of_node(mtd); + of_node_get(mtd_get_of_node(mtd)); + error = device_register(&mtd->dev); + if (error) diff --git a/target/linux/generic/backport-5.4/414-v6.1-mtd-allow-getting-MTD-device-associated-with-a-speci.patch b/target/linux/generic/backport-5.4/414-v6.1-mtd-allow-getting-MTD-device-associated-with-a-speci.patch index 6a78a675e0..f65fc6c8be 100644 --- a/target/linux/generic/backport-5.4/414-v6.1-mtd-allow-getting-MTD-device-associated-with-a-speci.patch +++ b/target/linux/generic/backport-5.4/414-v6.1-mtd-allow-getting-MTD-device-associated-with-a-speci.patch @@ -25,7 +25,7 @@ Signed-off-by: Srinivas Kandagatla --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c -@@ -1006,6 +1006,34 @@ int __get_mtd_device(struct mtd_info *mt +@@ -1067,6 +1067,34 @@ int __get_mtd_device(struct mtd_info *mt EXPORT_SYMBOL_GPL(__get_mtd_device); /** diff --git a/target/linux/generic/pending-5.4/480-mtd-set-rootfs-to-be-root-dev.patch b/target/linux/generic/pending-5.4/480-mtd-set-rootfs-to-be-root-dev.patch index 95863d6edb..1189ce0f89 100644 --- a/target/linux/generic/pending-5.4/480-mtd-set-rootfs-to-be-root-dev.patch +++ b/target/linux/generic/pending-5.4/480-mtd-set-rootfs-to-be-root-dev.patch @@ -20,7 +20,7 @@ Signed-off-by: Gabor Juhos #include #include -@@ -699,6 +700,15 @@ int add_mtd_device(struct mtd_info *mtd) +@@ -760,6 +761,15 @@ int add_mtd_device(struct mtd_info *mtd) of this try_ nonsense, and no bitching about it either. :) */ __module_get(THIS_MODULE); diff --git a/target/linux/generic/pending-5.4/495-mtd-core-add-get_mtd_device_by_node.patch b/target/linux/generic/pending-5.4/495-mtd-core-add-get_mtd_device_by_node.patch index d17106bfbc..a73775783e 100644 --- a/target/linux/generic/pending-5.4/495-mtd-core-add-get_mtd_device_by_node.patch +++ b/target/linux/generic/pending-5.4/495-mtd-core-add-get_mtd_device_by_node.patch @@ -17,7 +17,7 @@ Reviewed-by: Miquel Raynal --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c -@@ -1081,6 +1081,44 @@ out_unlock: +@@ -1142,6 +1142,44 @@ out_unlock: } EXPORT_SYMBOL_GPL(get_mtd_device_nm); diff --git a/target/linux/pistachio/patches-5.4/401-mtd-nor-support-mtd-name-from-device-tree.patch b/target/linux/pistachio/patches-5.4/401-mtd-nor-support-mtd-name-from-device-tree.patch index 69a8303d2b..ae2478fc1d 100644 --- a/target/linux/pistachio/patches-5.4/401-mtd-nor-support-mtd-name-from-device-tree.patch +++ b/target/linux/pistachio/patches-5.4/401-mtd-nor-support-mtd-name-from-device-tree.patch @@ -34,7 +34,7 @@ Signed-off-by: Abhimanyu Vishwakarma mtd->type = MTD_NORFLASH; --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c -@@ -779,6 +779,17 @@ out_error: +@@ -840,6 +840,17 @@ out_error: */ static void mtd_set_dev_defaults(struct mtd_info *mtd) { From 6564d3eec15d93b0d5879dca15f1043f9207bab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Wed, 21 Sep 2022 10:44:19 +0200 Subject: [PATCH 02/16] bcm53xx: update NVMEM driver for NVRAM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Include support for NVMEM cells. Signed-off-by: Rafał Miłecki (cherry picked from commit 2f50c53f1772f24e4687e960e21c5b392fb522f0) --- ...-parse-NVRAM-content-into-NVMEM-cell.patch | 146 ++++++++++++++++++ ...-find-Device-Tree-nodes-for-NVMEM-ce.patch | 38 +++++ ...-provide-NVMEM-content-to-the-NVRAM-.patch | 10 +- ...support-passing-DT-node-in-cell-info.patch | 41 +++++ 4 files changed, 230 insertions(+), 5 deletions(-) create mode 100644 target/linux/bcm53xx/patches-5.4/081-v5.18-nvmem-brcm_nvram-parse-NVRAM-content-into-NVMEM-cell.patch create mode 100644 target/linux/bcm53xx/patches-5.4/082-v5.19-nvmem-brcm_nvram-find-Device-Tree-nodes-for-NVMEM-ce.patch create mode 100644 target/linux/generic/backport-5.4/802-v5.19-nvmem-core-support-passing-DT-node-in-cell-info.patch diff --git a/target/linux/bcm53xx/patches-5.4/081-v5.18-nvmem-brcm_nvram-parse-NVRAM-content-into-NVMEM-cell.patch b/target/linux/bcm53xx/patches-5.4/081-v5.18-nvmem-brcm_nvram-parse-NVRAM-content-into-NVMEM-cell.patch new file mode 100644 index 0000000000..99781b3a7b --- /dev/null +++ b/target/linux/bcm53xx/patches-5.4/081-v5.18-nvmem-brcm_nvram-parse-NVRAM-content-into-NVMEM-cell.patch @@ -0,0 +1,146 @@ +From 6e977eaa8280e957b87904b536661550f2a6b3e8 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Fri, 25 Feb 2022 17:58:20 +0000 +Subject: [PATCH] nvmem: brcm_nvram: parse NVRAM content into NVMEM cells +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +NVRAM consist of header and NUL separated key-value pairs. Parse it and +create NVMEM cell for every key-value entry. + +Signed-off-by: Rafał Miłecki +Signed-off-by: Srinivas Kandagatla +Link: https://lore.kernel.org/r/20220225175822.8293-3-srinivas.kandagatla@linaro.org +Signed-off-by: Greg Kroah-Hartman +--- + drivers/nvmem/brcm_nvram.c | 90 ++++++++++++++++++++++++++++++++++++++ + 1 file changed, 90 insertions(+) + +--- a/drivers/nvmem/brcm_nvram.c ++++ b/drivers/nvmem/brcm_nvram.c +@@ -6,12 +6,26 @@ + #include + #include + #include ++#include + #include + #include ++#include ++ ++#define NVRAM_MAGIC "FLSH" + + struct brcm_nvram { + struct device *dev; + void __iomem *base; ++ struct nvmem_cell_info *cells; ++ int ncells; ++}; ++ ++struct brcm_nvram_header { ++ char magic[4]; ++ __le32 len; ++ __le32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */ ++ __le32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */ ++ __le32 config_ncdl; /* ncdl values for memc */ + }; + + static int brcm_nvram_read(void *context, unsigned int offset, void *val, +@@ -26,6 +40,75 @@ static int brcm_nvram_read(void *context + return 0; + } + ++static int brcm_nvram_add_cells(struct brcm_nvram *priv, uint8_t *data, ++ size_t len) ++{ ++ struct device *dev = priv->dev; ++ char *var, *value, *eq; ++ int idx; ++ ++ priv->ncells = 0; ++ for (var = data + sizeof(struct brcm_nvram_header); ++ var < (char *)data + len && *var; ++ var += strlen(var) + 1) { ++ priv->ncells++; ++ } ++ ++ priv->cells = devm_kcalloc(dev, priv->ncells, sizeof(*priv->cells), GFP_KERNEL); ++ if (!priv->cells) ++ return -ENOMEM; ++ ++ for (var = data + sizeof(struct brcm_nvram_header), idx = 0; ++ var < (char *)data + len && *var; ++ var = value + strlen(value) + 1, idx++) { ++ eq = strchr(var, '='); ++ if (!eq) ++ break; ++ *eq = '\0'; ++ value = eq + 1; ++ ++ priv->cells[idx].name = devm_kstrdup(dev, var, GFP_KERNEL); ++ if (!priv->cells[idx].name) ++ return -ENOMEM; ++ priv->cells[idx].offset = value - (char *)data; ++ priv->cells[idx].bytes = strlen(value); ++ } ++ ++ return 0; ++} ++ ++static int brcm_nvram_parse(struct brcm_nvram *priv) ++{ ++ struct device *dev = priv->dev; ++ struct brcm_nvram_header header; ++ uint8_t *data; ++ size_t len; ++ int err; ++ ++ memcpy_fromio(&header, priv->base, sizeof(header)); ++ ++ if (memcmp(header.magic, NVRAM_MAGIC, 4)) { ++ dev_err(dev, "Invalid NVRAM magic\n"); ++ return -EINVAL; ++ } ++ ++ len = le32_to_cpu(header.len); ++ ++ data = kcalloc(1, len, GFP_KERNEL); ++ memcpy_fromio(data, priv->base, len); ++ data[len - 1] = '\0'; ++ ++ err = brcm_nvram_add_cells(priv, data, len); ++ if (err) { ++ dev_err(dev, "Failed to add cells: %d\n", err); ++ return err; ++ } ++ ++ kfree(data); ++ ++ return 0; ++} ++ + static int brcm_nvram_probe(struct platform_device *pdev) + { + struct nvmem_config config = { +@@ -35,6 +118,7 @@ static int brcm_nvram_probe(struct platf + struct device *dev = &pdev->dev; + struct resource *res; + struct brcm_nvram *priv; ++ int err; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) +@@ -46,7 +130,13 @@ static int brcm_nvram_probe(struct platf + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + ++ err = brcm_nvram_parse(priv); ++ if (err) ++ return err; ++ + config.dev = dev; ++ config.cells = priv->cells; ++ config.ncells = priv->ncells; + config.priv = priv; + config.size = resource_size(res); + diff --git a/target/linux/bcm53xx/patches-5.4/082-v5.19-nvmem-brcm_nvram-find-Device-Tree-nodes-for-NVMEM-ce.patch b/target/linux/bcm53xx/patches-5.4/082-v5.19-nvmem-brcm_nvram-find-Device-Tree-nodes-for-NVMEM-ce.patch new file mode 100644 index 0000000000..a9eacd9419 --- /dev/null +++ b/target/linux/bcm53xx/patches-5.4/082-v5.19-nvmem-brcm_nvram-find-Device-Tree-nodes-for-NVMEM-ce.patch @@ -0,0 +1,38 @@ +From 207775f7e17b8fd0426a2ac4a5b81e4e1d71849e Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Fri, 29 Apr 2022 17:26:47 +0100 +Subject: [PATCH] nvmem: brcm_nvram: find Device Tree nodes for NVMEM cells +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +DT binding for Broadcom's NVRAM supports specifying NVMEM cells as NVMEM +device (provider) subnodes. Look for such subnodes when collecing NVMEM +cells. This allows NVMEM consumers to use NVRAM variables. + +Signed-off-by: Rafał Miłecki +Signed-off-by: Srinivas Kandagatla +Link: https://lore.kernel.org/r/20220429162701.2222-3-srinivas.kandagatla@linaro.org +Signed-off-by: Greg Kroah-Hartman +--- + drivers/nvmem/brcm_nvram.c | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/drivers/nvmem/brcm_nvram.c ++++ b/drivers/nvmem/brcm_nvram.c +@@ -8,6 +8,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -72,6 +73,7 @@ static int brcm_nvram_add_cells(struct b + return -ENOMEM; + priv->cells[idx].offset = value - (char *)data; + priv->cells[idx].bytes = strlen(value); ++ priv->cells[idx].np = of_get_child_by_name(dev->of_node, priv->cells[idx].name); + } + + return 0; diff --git a/target/linux/bcm53xx/patches-5.4/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch b/target/linux/bcm53xx/patches-5.4/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch index cf5952ad5f..ecc5f3974e 100644 --- a/target/linux/bcm53xx/patches-5.4/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch +++ b/target/linux/bcm53xx/patches-5.4/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch @@ -20,12 +20,12 @@ Signed-off-by: Rafał Miłecki #include #include #include -@@ -46,6 +47,8 @@ static int brcm_nvram_probe(struct platf - if (IS_ERR(priv->base)) - return PTR_ERR(priv->base); +@@ -136,6 +137,8 @@ static int brcm_nvram_probe(struct platf + if (err) + return err; + bcm47xx_nvram_init_from_iomem(priv->base, resource_size(res)); + config.dev = dev; - config.priv = priv; - config.size = resource_size(res); + config.cells = priv->cells; + config.ncells = priv->ncells; diff --git a/target/linux/generic/backport-5.4/802-v5.19-nvmem-core-support-passing-DT-node-in-cell-info.patch b/target/linux/generic/backport-5.4/802-v5.19-nvmem-core-support-passing-DT-node-in-cell-info.patch new file mode 100644 index 0000000000..c6da49ef88 --- /dev/null +++ b/target/linux/generic/backport-5.4/802-v5.19-nvmem-core-support-passing-DT-node-in-cell-info.patch @@ -0,0 +1,41 @@ +From dbc2f62061c6bfba0aee93161ee3194dcee84bd0 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Fri, 29 Apr 2022 17:26:46 +0100 +Subject: [PATCH] nvmem: core: support passing DT node in cell info +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Some hardware may have NVMEM cells described in Device Tree using +individual nodes. Let drivers pass such nodes to the NVMEM subsystem so +they can be later used by NVMEM consumers. + +Signed-off-by: Rafał Miłecki +Signed-off-by: Srinivas Kandagatla +Link: https://lore.kernel.org/r/20220429162701.2222-2-srinivas.kandagatla@linaro.org +Signed-off-by: Greg Kroah-Hartman +--- + drivers/nvmem/core.c | 1 + + include/linux/nvmem-consumer.h | 1 + + 2 files changed, 2 insertions(+) + +--- a/drivers/nvmem/core.c ++++ b/drivers/nvmem/core.c +@@ -141,6 +141,7 @@ static int nvmem_cell_info_to_nvmem_cell + + cell->bit_offset = info->bit_offset; + cell->nbits = info->nbits; ++ cell->np = info->np; + + if (cell->nbits) + cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset, +--- a/include/linux/nvmem-consumer.h ++++ b/include/linux/nvmem-consumer.h +@@ -25,6 +25,7 @@ struct nvmem_cell_info { + unsigned int bytes; + unsigned int bit_offset; + unsigned int nbits; ++ struct device_node *np; + }; + + /** From deaad2c8758dcc164478c430696182367611bcbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Wed, 21 Sep 2022 10:44:23 +0200 Subject: [PATCH 03/16] bcm4908: backport mtd parser for Broadcom's U-Boot partition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Broadcom's U-Boot contains environment data blocks. They need to be found (offsets aren't predefined) to access env variables. Signed-off-by: Rafał Miłecki (cherry picked from commit 137149847d0f374515f38952ce0986b03a97f2e4) --- target/linux/bcm4908/config-5.4 | 1 + ...parsers-add-Broadcom-s-U-Boot-parser.patch | 137 ++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 target/linux/bcm4908/patches-5.4/040-v6.1-mtd-parsers-add-Broadcom-s-U-Boot-parser.patch diff --git a/target/linux/bcm4908/config-5.4 b/target/linux/bcm4908/config-5.4 index a11cfc84ac..e051e900df 100644 --- a/target/linux/bcm4908/config-5.4 +++ b/target/linux/bcm4908/config-5.4 @@ -142,6 +142,7 @@ CONFIG_MEMFD_CREATE=y CONFIG_MFD_SYSCON=y CONFIG_MIGRATION=y CONFIG_MODULES_USE_ELF_RELA=y +CONFIG_MTD_BRCM_U_BOOT=y CONFIG_MTD_CMDLINE_PARTS=y CONFIG_MTD_NAND_BRCMNAND=y CONFIG_MTD_NAND_CORE=y diff --git a/target/linux/bcm4908/patches-5.4/040-v6.1-mtd-parsers-add-Broadcom-s-U-Boot-parser.patch b/target/linux/bcm4908/patches-5.4/040-v6.1-mtd-parsers-add-Broadcom-s-U-Boot-parser.patch new file mode 100644 index 0000000000..4d4059b17f --- /dev/null +++ b/target/linux/bcm4908/patches-5.4/040-v6.1-mtd-parsers-add-Broadcom-s-U-Boot-parser.patch @@ -0,0 +1,137 @@ +From 002181f5b150e60c77f21de7ad4dd10e4614cd91 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Mon, 11 Jul 2022 17:30:41 +0200 +Subject: [PATCH] mtd: parsers: add Broadcom's U-Boot parser +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Broadcom stores environment variables blocks inside U-Boot partition +itself. This driver finds & registers them. + +Signed-off-by: Rafał Miłecki +Signed-off-by: Miquel Raynal +Link: https://lore.kernel.org/linux-mtd/20220711153041.6036-2-zajec5@gmail.com +--- + drivers/mtd/parsers/Kconfig | 10 ++++ + drivers/mtd/parsers/Makefile | 1 + + drivers/mtd/parsers/brcm_u-boot.c | 84 +++++++++++++++++++++++++++++++ + 3 files changed, 95 insertions(+) + create mode 100644 drivers/mtd/parsers/brcm_u-boot.c + +--- a/drivers/mtd/parsers/Kconfig ++++ b/drivers/mtd/parsers/Kconfig +@@ -20,6 +20,16 @@ config MTD_BCM63XX_PARTS + This provides partition parsing for BCM63xx devices with CFE + bootloaders. + ++config MTD_BRCM_U_BOOT ++ tristate "Broadcom's U-Boot partition parser" ++ depends on ARCH_BCM4908 || COMPILE_TEST ++ help ++ Broadcom uses a custom way of storing U-Boot environment variables. ++ They are placed inside U-Boot partition itself at unspecified offset. ++ It's possible to locate them by looking for a custom header with a ++ magic value. This driver does that and creates subpartitions for ++ each found environment variables block. ++ + config MTD_CMDLINE_PARTS + tristate "Command line partition table parsing" + depends on MTD +--- a/drivers/mtd/parsers/Makefile ++++ b/drivers/mtd/parsers/Makefile +@@ -2,6 +2,7 @@ + obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o + obj-$(CONFIG_MTD_BCM47XX_PARTS) += bcm47xxpart.o + obj-$(CONFIG_MTD_BCM63XX_PARTS) += bcm63xxpart.o ++obj-$(CONFIG_MTD_BRCM_U_BOOT) += brcm_u-boot.o + obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o + obj-$(CONFIG_MTD_MYLOADER_PARTS) += myloader.o + obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o +--- /dev/null ++++ b/drivers/mtd/parsers/brcm_u-boot.c +@@ -0,0 +1,84 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++/* ++ * Copyright © 2022 Rafał Miłecki ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#define BRCM_U_BOOT_MAX_OFFSET 0x200000 ++#define BRCM_U_BOOT_STEP 0x1000 ++ ++#define BRCM_U_BOOT_MAX_PARTS 2 ++ ++#define BRCM_U_BOOT_MAGIC 0x75456e76 /* uEnv */ ++ ++struct brcm_u_boot_header { ++ __le32 magic; ++ __le32 length; ++} __packed; ++ ++static const char *names[BRCM_U_BOOT_MAX_PARTS] = { ++ "u-boot-env", ++ "u-boot-env-backup", ++}; ++ ++static int brcm_u_boot_parse(struct mtd_info *mtd, ++ const struct mtd_partition **pparts, ++ struct mtd_part_parser_data *data) ++{ ++ struct brcm_u_boot_header header; ++ struct mtd_partition *parts; ++ size_t bytes_read; ++ size_t offset; ++ int err; ++ int i = 0; ++ ++ parts = kcalloc(BRCM_U_BOOT_MAX_PARTS, sizeof(*parts), GFP_KERNEL); ++ if (!parts) ++ return -ENOMEM; ++ ++ for (offset = 0; ++ offset < min_t(size_t, mtd->size, BRCM_U_BOOT_MAX_OFFSET); ++ offset += BRCM_U_BOOT_STEP) { ++ err = mtd_read(mtd, offset, sizeof(header), &bytes_read, (uint8_t *)&header); ++ if (err && !mtd_is_bitflip(err)) { ++ pr_err("Failed to read from %s at 0x%zx: %d\n", mtd->name, offset, err); ++ continue; ++ } ++ ++ if (le32_to_cpu(header.magic) != BRCM_U_BOOT_MAGIC) ++ continue; ++ ++ parts[i].name = names[i]; ++ parts[i].offset = offset; ++ parts[i].size = sizeof(header) + le32_to_cpu(header.length); ++ i++; ++ pr_info("offset:0x%zx magic:0x%08x BINGO\n", offset, header.magic); ++ ++ if (i == BRCM_U_BOOT_MAX_PARTS) ++ break; ++ } ++ ++ *pparts = parts; ++ ++ return i; ++}; ++ ++static const struct of_device_id brcm_u_boot_of_match_table[] = { ++ { .compatible = "brcm,u-boot" }, ++ {}, ++}; ++MODULE_DEVICE_TABLE(of, brcm_u_boot_of_match_table); ++ ++static struct mtd_part_parser brcm_u_boot_mtd_parser = { ++ .parse_fn = brcm_u_boot_parse, ++ .name = "brcm_u-boot", ++ .of_match_table = brcm_u_boot_of_match_table, ++}; ++module_mtd_part_parser(brcm_u_boot_mtd_parser); ++ ++MODULE_LICENSE("GPL"); From 4c45c111e0bef4c991d38a2bb1a1c0032bebc8e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Wed, 21 Sep 2022 10:44:28 +0200 Subject: [PATCH 04/16] kernel: update U-Boot NVMEM driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Fix casting 2. Support DT-defined variables Signed-off-by: Rafał Miłecki (cherry picked from commit 5652f378c6c607f99a15e6472cdca46c9c4b6162) --- ...upport-passing-DT-node-in-cell-info.patch} | 0 ...handling-U-Boot-environment-variabl.patch} | 0 ...-find-Device-Tree-nodes-for-NVMEM-ce.patch | 29 ++++++++++++++++++ ...em-u-boot-env-fix-crc32-casting-type.patch | 30 +++++++++++++++++++ 4 files changed, 59 insertions(+) rename target/linux/generic/backport-5.4/{802-v5.19-nvmem-core-support-passing-DT-node-in-cell-info.patch => 801-v5.19-nvmem-core-support-passing-DT-node-in-cell-info.patch} (100%) rename target/linux/generic/backport-5.4/{801-v6.1-nvmem-add-driver-handling-U-Boot-environment-variabl.patch => 802-v6.1-0001-nvmem-add-driver-handling-U-Boot-environment-variabl.patch} (100%) create mode 100644 target/linux/generic/backport-5.4/802-v6.1-0002-nvmem-u-boot-env-find-Device-Tree-nodes-for-NVMEM-ce.patch create mode 100644 target/linux/generic/backport-5.4/802-v6.1-0003-nvmem-u-boot-env-fix-crc32-casting-type.patch diff --git a/target/linux/generic/backport-5.4/802-v5.19-nvmem-core-support-passing-DT-node-in-cell-info.patch b/target/linux/generic/backport-5.4/801-v5.19-nvmem-core-support-passing-DT-node-in-cell-info.patch similarity index 100% rename from target/linux/generic/backport-5.4/802-v5.19-nvmem-core-support-passing-DT-node-in-cell-info.patch rename to target/linux/generic/backport-5.4/801-v5.19-nvmem-core-support-passing-DT-node-in-cell-info.patch diff --git a/target/linux/generic/backport-5.4/801-v6.1-nvmem-add-driver-handling-U-Boot-environment-variabl.patch b/target/linux/generic/backport-5.4/802-v6.1-0001-nvmem-add-driver-handling-U-Boot-environment-variabl.patch similarity index 100% rename from target/linux/generic/backport-5.4/801-v6.1-nvmem-add-driver-handling-U-Boot-environment-variabl.patch rename to target/linux/generic/backport-5.4/802-v6.1-0001-nvmem-add-driver-handling-U-Boot-environment-variabl.patch diff --git a/target/linux/generic/backport-5.4/802-v6.1-0002-nvmem-u-boot-env-find-Device-Tree-nodes-for-NVMEM-ce.patch b/target/linux/generic/backport-5.4/802-v6.1-0002-nvmem-u-boot-env-find-Device-Tree-nodes-for-NVMEM-ce.patch new file mode 100644 index 0000000000..3a6b76a221 --- /dev/null +++ b/target/linux/generic/backport-5.4/802-v6.1-0002-nvmem-u-boot-env-find-Device-Tree-nodes-for-NVMEM-ce.patch @@ -0,0 +1,29 @@ +From d69efcf951df4dcc74a0e1554969c533aec8aa9b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Thu, 15 Sep 2022 22:06:29 +0200 +Subject: [PATCH] nvmem: u-boot-env: find Device Tree nodes for NVMEM cells +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +DT binding allows specifying NVMEM cells as NVMEM device (provider) +subnodes. Looks for such subnodes when building NVMEM cells. + +This allows NVMEM consumers to use U-Boot environment variables. + +Signed-off-by: Rafał Miłecki +Signed-off-by: Srinivas Kandagatla +--- + drivers/nvmem/u-boot-env.c | 1 + + 1 file changed, 1 insertion(+) + +--- a/drivers/nvmem/u-boot-env.c ++++ b/drivers/nvmem/u-boot-env.c +@@ -92,6 +92,7 @@ static int u_boot_env_add_cells(struct u + return -ENOMEM; + priv->cells[idx].offset = data_offset + value - data; + priv->cells[idx].bytes = strlen(value); ++ priv->cells[idx].np = of_get_child_by_name(dev->of_node, priv->cells[idx].name); + } + + if (WARN_ON(idx != priv->ncells)) diff --git a/target/linux/generic/backport-5.4/802-v6.1-0003-nvmem-u-boot-env-fix-crc32-casting-type.patch b/target/linux/generic/backport-5.4/802-v6.1-0003-nvmem-u-boot-env-fix-crc32-casting-type.patch new file mode 100644 index 0000000000..6b40557116 --- /dev/null +++ b/target/linux/generic/backport-5.4/802-v6.1-0003-nvmem-u-boot-env-fix-crc32-casting-type.patch @@ -0,0 +1,30 @@ +From 60bbaad38109684b156e21112322e0a922f92cde Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Thu, 18 Aug 2022 06:38:37 +0200 +Subject: [PATCH] nvmem: u-boot-env: fix crc32 casting type +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This fixes: +drivers/nvmem/u-boot-env.c:141:17: sparse: sparse: cast to restricted __le32 + +Reported-by: kernel test robot +Fixes: f955dc1445069 ("nvmem: add driver handling U-Boot environment variables") +Signed-off-by: Rafał Miłecki +Signed-off-by: Srinivas Kandagatla +--- + drivers/nvmem/u-boot-env.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/nvmem/u-boot-env.c ++++ b/drivers/nvmem/u-boot-env.c +@@ -139,7 +139,7 @@ static int u_boot_env_parse(struct u_boo + data_offset = offsetof(struct u_boot_env_image_redundant, data); + break; + } +- crc32 = le32_to_cpu(*(uint32_t *)(buf + crc32_offset)); ++ crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset)); + crc32_data_len = priv->mtd->size - crc32_data_offset; + data_len = priv->mtd->size - data_offset; + From f33b14d11672827e0d4867313d49a9e35b82f3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Wed, 21 Sep 2022 10:44:32 +0200 Subject: [PATCH 05/16] bcm4908: fix -EPROBE_DEFER support in bcm4908_enet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rafał Miłecki (cherry picked from commit 1722e23ffcf9038114142a2129c29eb3cdec8ff9) --- ...908_enet-reset-DMA-rings-sw-indexes.patch} | 4 +- ...4908_enet-handle-EPROBE_DEFER-when-g.patch | 61 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) rename target/linux/bcm4908/patches-5.4/{170-net-broadcom-bcm4908_enet-reset-DMA-rings-sw-indexes.patch => 077-v5.14-net-broadcom-bcm4908_enet-reset-DMA-rings-sw-indexes.patch} (89%) create mode 100644 target/linux/bcm4908/patches-5.4/078-v6.1-net-broadcom-bcm4908_enet-handle-EPROBE_DEFER-when-g.patch diff --git a/target/linux/bcm4908/patches-5.4/170-net-broadcom-bcm4908_enet-reset-DMA-rings-sw-indexes.patch b/target/linux/bcm4908/patches-5.4/077-v5.14-net-broadcom-bcm4908_enet-reset-DMA-rings-sw-indexes.patch similarity index 89% rename from target/linux/bcm4908/patches-5.4/170-net-broadcom-bcm4908_enet-reset-DMA-rings-sw-indexes.patch rename to target/linux/bcm4908/patches-5.4/077-v5.14-net-broadcom-bcm4908_enet-reset-DMA-rings-sw-indexes.patch index 7e82230f9a..02290c8e64 100644 --- a/target/linux/bcm4908/patches-5.4/170-net-broadcom-bcm4908_enet-reset-DMA-rings-sw-indexes.patch +++ b/target/linux/bcm4908/patches-5.4/077-v5.14-net-broadcom-bcm4908_enet-reset-DMA-rings-sw-indexes.patch @@ -1,5 +1,6 @@ +From ddeacc4f6494e07cbb6f033627926623f3e7a9d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= -Date: Tue, 22 Jun 2021 07:05:04 +0200 +Date: Tue, 22 Jun 2021 07:24:15 +0200 Subject: [PATCH] net: broadcom: bcm4908_enet: reset DMA rings sw indexes properly MIME-Version: 1.0 @@ -15,6 +16,7 @@ down & up sequence. Fixes: 4feffeadbcb2 ("net: broadcom: bcm4908enet: add BCM4908 controller driver") Signed-off-by: Rafał Miłecki +Signed-off-by: David S. Miller --- drivers/net/ethernet/broadcom/bcm4908_enet.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/target/linux/bcm4908/patches-5.4/078-v6.1-net-broadcom-bcm4908_enet-handle-EPROBE_DEFER-when-g.patch b/target/linux/bcm4908/patches-5.4/078-v6.1-net-broadcom-bcm4908_enet-handle-EPROBE_DEFER-when-g.patch new file mode 100644 index 0000000000..de13dcf663 --- /dev/null +++ b/target/linux/bcm4908/patches-5.4/078-v6.1-net-broadcom-bcm4908_enet-handle-EPROBE_DEFER-when-g.patch @@ -0,0 +1,61 @@ +From e93a766da57fff3273bcb618edf5dfca1fb86b89 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Thu, 15 Sep 2022 15:30:13 +0200 +Subject: [PATCH] net: broadcom: bcm4908_enet: handle -EPROBE_DEFER when + getting MAC +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Reading MAC from OF may return -EPROBE_DEFER if underlaying NVMEM device +isn't ready yet. In such case pass that error code up and "wait" to be +probed later. + +Signed-off-by: Rafał Miłecki +Link: https://lore.kernel.org/r/20220915133013.2243-1-zajec5@gmail.com +Signed-off-by: Jakub Kicinski +--- + drivers/net/ethernet/broadcom/bcm4908_enet.c | 13 +++++++++---- + 1 file changed, 9 insertions(+), 4 deletions(-) + +--- a/drivers/net/ethernet/broadcom/bcm4908_enet.c ++++ b/drivers/net/ethernet/broadcom/bcm4908_enet.c +@@ -716,10 +716,14 @@ static int bcm4908_enet_probe(struct pla + + SET_NETDEV_DEV(netdev, &pdev->dev); + mac = of_get_mac_address(dev->of_node); +- if (!IS_ERR(mac)) ++ if (!IS_ERR(mac)) { + ether_addr_copy(netdev->dev_addr, mac); +- else ++ } else if (PTR_ERR(mac) == -EPROBE_DEFER) { ++ err = -EPROBE_DEFER; ++ goto err_dma_free; ++ } else { + eth_hw_addr_random(netdev); ++ } + netdev->netdev_ops = &bcm4908_enet_netdev_ops; + netdev->min_mtu = ETH_ZLEN; + netdev->mtu = ETH_DATA_LEN; +@@ -728,14 +732,17 @@ static int bcm4908_enet_probe(struct pla + netif_napi_add(netdev, &enet->rx_ring.napi, bcm4908_enet_poll_rx, NAPI_POLL_WEIGHT); + + err = register_netdev(netdev); +- if (err) { +- bcm4908_enet_dma_free(enet); +- return err; +- } ++ if (err) ++ goto err_dma_free; + + platform_set_drvdata(pdev, enet); + + return 0; ++ ++err_dma_free: ++ bcm4908_enet_dma_free(enet); ++ ++ return err; + } + + static int bcm4908_enet_remove(struct platform_device *pdev) From 4e221757c45fa94bfbd191726bfdc5655e61c31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0tetiar?= Date: Tue, 30 Aug 2022 08:31:42 +0200 Subject: [PATCH 06/16] scripts: add xxdi.pl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit xxdi.pl is a Perl script that implements vim's 'xxd -i' mode so that packages do not have to use all of vim just to get this functionality. References: #10555 Source: https://github.com/gregkh/xxdi/blob/97a6bd5cee05d1b15851981ec38ef5a460ddfcb1/xxdi.pl Signed-off-by: Petr Štetiar (cherry picked from commit 2117d04a3aaad3394c0afec799d9c43f8a09c2cf) --- scripts/xxdi.pl | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 scripts/xxdi.pl diff --git a/scripts/xxdi.pl b/scripts/xxdi.pl new file mode 100755 index 0000000000..acc974c4b3 --- /dev/null +++ b/scripts/xxdi.pl @@ -0,0 +1,50 @@ +#!/usr/bin/env perl +# +# xxdi.pl - perl implementation of 'xxd -i' mode +# +# Copyright 2013 Greg Kroah-Hartman +# Copyright 2013 Linux Foundation +# +# Released under the GPLv2. +# +# Implements the "basic" functionality of 'xxd -i' in perl to keep build +# systems from having to build/install/rely on vim-core, which not all +# distros want to do. But everyone has perl, so use it instead. +# + +use strict; +use warnings; +use File::Slurp qw(slurp); + +my $indata = slurp(@ARGV ? $ARGV[0] : \*STDIN); +my $len_data = length($indata); +my $num_digits_per_line = 12; +my $var_name; +my $outdata; + +# Use the variable name of the file we read from, converting '/' and '. +# to '_', or, if this is stdin, just use "stdin" as the name. +if (@ARGV) { + $var_name = $ARGV[0]; + $var_name =~ s/\//_/g; + $var_name =~ s/\./_/g; +} else { + $var_name = "stdin"; +} + +$outdata .= "unsigned char $var_name\[] = {"; + +# trailing ',' is acceptable, so instead of duplicating the logic for +# just the last character, live with the extra ','. +for (my $key= 0; $key < $len_data; $key++) { + if ($key % $num_digits_per_line == 0) { + $outdata .= "\n\t"; + } + $outdata .= sprintf("0x%.2x, ", ord(substr($indata, $key, 1))); +} + +$outdata .= "\n};\nunsigned int $var_name\_len = $len_data;\n"; + +binmode STDOUT; +print {*STDOUT} $outdata; + From 70124b8579b1c43c9018352adf8e87e1246843c7 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 30 Aug 2022 18:20:04 +0200 Subject: [PATCH 07/16] scripts: xxdi.pl: remove File::Slurp dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to make it more portable. Signed-off-by: Jo-Philipp Wich Signed-off-by: Petr Štetiar (cherry picked from commit 8b278a76d90e3724815a5fde32be59f7796be1d8) --- scripts/xxdi.pl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/xxdi.pl b/scripts/xxdi.pl index acc974c4b3..1f960902be 100755 --- a/scripts/xxdi.pl +++ b/scripts/xxdi.pl @@ -14,9 +14,24 @@ use strict; use warnings; -use File::Slurp qw(slurp); -my $indata = slurp(@ARGV ? $ARGV[0] : \*STDIN); +my $indata; + +{ + local $/; + my $fh; + + if (@ARGV) { + open($fh, '<:raw', $ARGV[0]) || die("Unable to open $ARGV[0]: $!\n"); + } else { + $fh = \*STDIN; + } + + $indata = readline $fh; + + close $fh; +} + my $len_data = length($indata); my $num_digits_per_line = 12; my $var_name; From 45a486bf934dc6ddbc71ed4b986a47883df12150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0tetiar?= Date: Tue, 30 Aug 2022 08:34:26 +0200 Subject: [PATCH 08/16] scripts: xxdi.pl: add xxd -i compat mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So it can serve as a standalone drop in replacement for xxd utility used currently mostly in U-Boot packages with `xxd -i` mode which outputs C include file style, with aim for byte to byte identical output, so the eventual difference in the generated output is easily spottable. Fixes: #10555 Signed-off-by: Petr Štetiar Signed-off-by: Jo-Philipp Wich [perl-fu] (cherry picked from commit 06e01e817ec6643a35beb9e6946689e9cc7d020a) --- scripts/xxdi.pl | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/scripts/xxdi.pl b/scripts/xxdi.pl index 1f960902be..f7bb3c2f9c 100755 --- a/scripts/xxdi.pl +++ b/scripts/xxdi.pl @@ -16,15 +16,21 @@ use strict; use warnings; my $indata; +my $var_name = "stdin"; +my $full_output = (@ARGV > 0 && $ARGV[0] eq '-i') ? shift @ARGV : undef; { local $/; my $fh; if (@ARGV) { - open($fh, '<:raw', $ARGV[0]) || die("Unable to open $ARGV[0]: $!\n"); - } else { + $var_name = $ARGV[0]; + open($fh, '<:raw', $var_name) || die("xxdi.pl: Unable to open $var_name: $!\n"); + } elsif (! -t STDIN) { $fh = \*STDIN; + undef $full_output; + } else { + die "usage: xxdi.pl [-i] [infile]\n"; } $indata = readline $fh; @@ -34,32 +40,27 @@ my $indata; my $len_data = length($indata); my $num_digits_per_line = 12; -my $var_name; -my $outdata; +my $outdata = ""; # Use the variable name of the file we read from, converting '/' and '. # to '_', or, if this is stdin, just use "stdin" as the name. -if (@ARGV) { - $var_name = $ARGV[0]; - $var_name =~ s/\//_/g; - $var_name =~ s/\./_/g; -} else { - $var_name = "stdin"; -} +$var_name =~ s/\//_/g; +$var_name =~ s/\./_/g; +$var_name = "__$var_name" if $var_name =~ /^\d/; -$outdata .= "unsigned char $var_name\[] = {"; +$outdata = "unsigned char $var_name\[] = { " if $full_output; -# trailing ',' is acceptable, so instead of duplicating the logic for -# just the last character, live with the extra ','. for (my $key= 0; $key < $len_data; $key++) { if ($key % $num_digits_per_line == 0) { - $outdata .= "\n\t"; + $outdata = substr($outdata, 0, -1)."\n "; } $outdata .= sprintf("0x%.2x, ", ord(substr($indata, $key, 1))); } -$outdata .= "\n};\nunsigned int $var_name\_len = $len_data;\n"; +$outdata = substr($outdata, 0, -2); +$outdata .= "\n"; + +$outdata .= "};\nunsigned int $var_name\_len = $len_data;\n" if $full_output; binmode STDOUT; -print {*STDOUT} $outdata; - +print $outdata; From 1c8c84620de64b20921873c998e93f72dbaccd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0tetiar?= Date: Tue, 30 Aug 2022 08:45:39 +0200 Subject: [PATCH 09/16] build: provide xxd -i with scripts/xxdi.pl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dependency on xxd was added in commit c4dd2441e787 ("tools: add xxd (from vim)") as U-Boot requires xxd to create the default environment from an external file. Later in commit 2b94aac7a128 ("tools: xxd: use more convenient source tarball"), xxd from another source was used instead, but that source is currently unavailable, so let's fix it by using simple xxdi.pl Perl script instead. Fixes: #10555 Signed-off-by: Petr Štetiar (cherry picked from commit eae2fb8027cb892e42181e471ba344aa5d26bf7e) --- include/prereq-build.mk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/prereq-build.mk b/include/prereq-build.mk index d3593b0205..61cd8ae516 100644 --- a/include/prereq-build.mk +++ b/include/prereq-build.mk @@ -192,7 +192,10 @@ $(STAGING_DIR_HOST)/bin/mkhash: $(SCRIPT_DIR)/mkhash.c mkdir -p $(dir $@) $(CC) -O2 -I$(TOPDIR)/tools/include -o $@ $< -prereq: $(STAGING_DIR_HOST)/bin/mkhash +$(STAGING_DIR_HOST)/bin/xxd: $(SCRIPT_DIR)/xxdi.pl + $(LN) $< $@ + +prereq: $(STAGING_DIR_HOST)/bin/mkhash $(STAGING_DIR_HOST)/bin/xxd # Install ldconfig stub $(eval $(call TestHostCommand,ldconfig-stub,Failed to install stub, \ From c6d3f39ecce43c4a9858157e9e2ee8718750a9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0tetiar?= Date: Tue, 30 Aug 2022 08:41:07 +0200 Subject: [PATCH 10/16] tools: remove xxd package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It shouldn't be needed anymore as we've now `scripts/xxdi.pl`, which should be self contained and fully compatible `xxd -i` replacement. Fixes: #10555 Signed-off-by: Petr Štetiar (cherry picked from commit 88c9056a70901577489ecdc7a25207a9b7576d6e) --- tools/Makefile | 2 +- tools/xxd/Makefile | 19 ------------------- 2 files changed, 1 insertion(+), 20 deletions(-) delete mode 100644 tools/xxd/Makefile diff --git a/tools/Makefile b/tools/Makefile index 577ea799c5..a2665dbc9a 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -25,7 +25,7 @@ tools-y += autoconf autoconf-archive automake bc bison cmake dosfstools tools-y += e2fsprogs fakeroot findutils firmware-utils flex gengetopt tools-y += libressl libtool lzma m4 make-ext4fs missing-macros mkimage tools-y += mklibs mm-macros mtd-utils mtools padjffs2 patch-image -tools-y += patchelf pkgconf quilt squashfskit4 sstrip xxd zip zlib zstd +tools-y += patchelf pkgconf quilt squashfskit4 sstrip zip zlib zstd tools-$(BUILD_B43_TOOLS) += b43-tools tools-$(BUILD_ISL) += isl tools-$(BUILD_TOOLCHAIN) += expat gmp libelf mpc mpfr diff --git a/tools/xxd/Makefile b/tools/xxd/Makefile deleted file mode 100644 index c3cc6863cc..0000000000 --- a/tools/xxd/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later - -include $(TOPDIR)/rules.mk - -PKG_NAME:=xxd -PKG_VERSION:=1.10 -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=http://grail.cba.csuohio.edu/~somos/ -PKG_HASH:=9bf05c19b9084973e3cc877696a7f9881a5c87fa5a9fa438d9962519726559f9 -PKG_CPE_ID:=cpe:/a:vim:vim - -include $(INCLUDE_DIR)/host-build.mk - -define Host/Install - $(INSTALL_DIR) $(STAGING_DIR_HOST)/bin - $(INSTALL_BIN) $(HOST_BUILD_DIR)/xxd $(STAGING_DIR_HOST)/bin/ -endef - -$(eval $(call HostBuild)) From f0bca34f16327c6001515f9c73c2c284574c7b6d Mon Sep 17 00:00:00 2001 From: Josh Roys Date: Sat, 23 Jul 2022 11:23:16 -0400 Subject: [PATCH 11/16] scripts: always check certificates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove flags from wget and curl instructing them to ignore bad server certificates. Although other mechanisms can protect against malicious modifications of downloads, other vectors of attack may be available to an adversary. TLS certificate verification can be disabled by turning oof the "Enable TLS certificate verification during package download" option enabled by default in the "Global build settings" in "make menuconfig" Signed-off-by: Josh Roys [ add additional info on how to disable this option ] Signed-off-by: Christian Marangi Signed-off-by: Petr Štetiar [backport] (cherry picked from commit 90c6e3aedf167b0ae1baf376e7800a631681e69a) --- config/Config-build.in | 4 ++++ rules.mk | 3 +++ scripts/download.pl | 6 ++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config/Config-build.in b/config/Config-build.in index 342859b7c0..196d4e67a0 100644 --- a/config/Config-build.in +++ b/config/Config-build.in @@ -58,6 +58,10 @@ menu "Global build settings" bool "Enable signature checking in opkg" default SIGNED_PACKAGES + config DOWNLOAD_CHECK_CERTIFICATE + bool "Enable TLS certificate verification during package download" + default y + comment "General build options" config TESTING_KERNEL diff --git a/rules.mk b/rules.mk index da9bee2899..7c83d90eda 100644 --- a/rules.mk +++ b/rules.mk @@ -265,6 +265,9 @@ TARGET_CXX:=$(TARGET_CROSS)g++ KPATCH:=$(SCRIPT_DIR)/patch-kernel.sh SED:=$(STAGING_DIR_HOST)/bin/sed -i -e ESED:=$(STAGING_DIR_HOST)/bin/sed -E -i -e +# DOWNLOAD_CHECK_CERTIFICATE is used in /scripts, so we export it here. +DOWNLOAD_CHECK_CERTIFICATE:=$(CONFIG_DOWNLOAD_CHECK_CERTIFICATE) +export DOWNLOAD_CHECK_CERTIFICATE CP:=cp -fpR LN:=ln -sf XARGS:=xargs -r diff --git a/scripts/download.pl b/scripts/download.pl index beb3abdeee..99708c456f 100755 --- a/scripts/download.pl +++ b/scripts/download.pl @@ -24,6 +24,8 @@ my $scriptdir = dirname($0); my @mirrors; my $ok; +my $check_certificate = $ENV{DOWNLOAD_CHECK_CERTIFICATE} eq "y"; + $url_filename or $url_filename = $filename; sub localmirrors { @@ -82,8 +84,8 @@ sub download_cmd($) { } return $have_curl - ? (qw(curl -f --connect-timeout 20 --retry 5 --location --insecure), shellwords($ENV{CURL_OPTIONS} || ''), $url) - : (qw(wget --tries=5 --timeout=20 --no-check-certificate --output-document=-), shellwords($ENV{WGET_OPTIONS} || ''), $url) + ? (qw(curl -f --connect-timeout 20 --retry 5 --location), $check_certificate ? '' : '--insecure', shellwords($ENV{CURL_OPTIONS} || ''), $url) + : (qw(wget --tries=5 --timeout=20 --output-document=-), $check_certificate ? '' : '--no-check-certificate', shellwords($ENV{WGET_OPTIONS} || ''), $url) ; } From f14d7cef7cce3ce79b880f71b25e03e5fb844882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0tetiar?= Date: Tue, 13 Sep 2022 07:38:10 +0200 Subject: [PATCH 12/16] scripts/download.pl: silence can't exec curl warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running build in verbose mode `make V=s` we can see a lot of following warnings when curl is not available in the system: Can't exec "curl": No such file or directory at scripts/download.pl line 77. So lets fix it by redirecting of the stderr to null hole. Signed-off-by: Petr Štetiar (cherry picked from commit c836ca84e8f641e10a8349a8f9b7432b33d6cec1) --- scripts/download.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/download.pl b/scripts/download.pl index 99708c456f..16f808da09 100755 --- a/scripts/download.pl +++ b/scripts/download.pl @@ -76,7 +76,7 @@ sub download_cmd($) { my $url = shift; my $have_curl = 0; - if (open CURL, '-|', 'curl', '--version') { + if (open CURL, "curl --version 2>/dev/null |") { if (defined(my $line = readline CURL)) { $have_curl = 1 if $line =~ /^curl /; } From c07c565ea671e9929b99fbd28c58bde5f5e50070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0tetiar?= Date: Tue, 13 Sep 2022 07:40:37 +0200 Subject: [PATCH 13/16] scripts/download.pl: fix downloads with wget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Several users of wget for downloads (curl is not available in the system) have reported broken download functionality: wget --tries=5 --timeout=20 --output-document=- https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.142.tar.xz http://: Invalid host name. Thats all happening due to '' was passed as an argument, which got later expanded to http://. In the context of a list constructor '' is not nothing, it is an empty string element. So fix it by using () as it will yield "nothing" and thus not introduce an empty string element. Fixes: #10692 Fixes: 90c6e3aedf16 ("scripts: always check certificates") Signed-off-by: Jo-Philipp Wich [shellwords() -> ()] Signed-off-by: Petr Štetiar (cherry picked from commit 50a48faa1b8424e6b4b436b7118fffa2cba14b18) --- scripts/download.pl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/download.pl b/scripts/download.pl index 16f808da09..bfee84762d 100755 --- a/scripts/download.pl +++ b/scripts/download.pl @@ -84,8 +84,14 @@ sub download_cmd($) { } return $have_curl - ? (qw(curl -f --connect-timeout 20 --retry 5 --location), $check_certificate ? '' : '--insecure', shellwords($ENV{CURL_OPTIONS} || ''), $url) - : (qw(wget --tries=5 --timeout=20 --output-document=-), $check_certificate ? '' : '--no-check-certificate', shellwords($ENV{WGET_OPTIONS} || ''), $url) + ? (qw(curl -f --connect-timeout 20 --retry 5 --location), + $check_certificate ? () : '--insecure', + shellwords($ENV{CURL_OPTIONS} || ''), + $url) + : (qw(wget --tries=5 --timeout=20 --output-document=-), + $check_certificate ? () : '--no-check-certificate', + shellwords($ENV{WGET_OPTIONS} || ''), + $url) ; } From 1ea34b9621fafa916e0d4ca0b6ec97ac8a611ba9 Mon Sep 17 00:00:00 2001 From: Alexey Smirnov Date: Tue, 4 Jan 2022 10:11:51 +0300 Subject: [PATCH 14/16] base-files: add support for heartbeat led trigger This patch adds support for creation heartbeat led trigger with, for example, this command: ucidef_set_led_heartbeat "..." "..." "..." from /etc/board.d/01_leds. Signed-off-by: Alexey Smirnov (cherry picked from commit 66071729a27919e555752fce25210b1b035eb319) --- package/base-files/files/lib/functions/uci-defaults.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh index 02882f43ca..f96e645e73 100644 --- a/package/base-files/files/lib/functions/uci-defaults.sh +++ b/package/base-files/files/lib/functions/uci-defaults.sh @@ -418,6 +418,15 @@ ucidef_set_led_default() { json_select .. } +ucidef_set_led_heartbeat() { + _ucidef_set_led_common "$1" "$2" "$3" + + json_add_string trigger heartbeat + json_select .. + + json_select .. +} + ucidef_set_led_gpio() { local gpio="$4" local inverted="$5" From 1f24bd1ba268d339abe18cc6607d97428c42e82b Mon Sep 17 00:00:00 2001 From: Federico Capoano Date: Thu, 15 Sep 2022 19:52:14 +0200 Subject: [PATCH 15/16] rampis: feed zbt-we1026 external watchdog Without feeding the gpio watchdog, the board will reset after 90 seconds Signed-off-by: Arvid E. Picciani (cherry picked from commit 1a97c03d864ee5ab917aff2988c62fce223c041e) [adapted to config-5.4] Signed-off-by: Federico Capoano --- .../linux/ramips/dts/mt7620a_zbtlink_zbt-we1026-5g.dtsi | 8 ++++++++ target/linux/ramips/mt7620/config-5.4 | 1 + 2 files changed, 9 insertions(+) diff --git a/target/linux/ramips/dts/mt7620a_zbtlink_zbt-we1026-5g.dtsi b/target/linux/ramips/dts/mt7620a_zbtlink_zbt-we1026-5g.dtsi index 4991897ca4..f86ac1a88a 100644 --- a/target/linux/ramips/dts/mt7620a_zbtlink_zbt-we1026-5g.dtsi +++ b/target/linux/ramips/dts/mt7620a_zbtlink_zbt-we1026-5g.dtsi @@ -26,6 +26,14 @@ gpios = <&gpio3 0 GPIO_ACTIVE_LOW>; }; }; + + watchdog { + compatible = "linux,wdt-gpio"; + gpios = <&gpio0 11 GPIO_ACTIVE_HIGH>; + hw_algo = "toggle"; + hw_margin_ms = <20000>; + always-running; + }; }; &pcie { diff --git a/target/linux/ramips/mt7620/config-5.4 b/target/linux/ramips/mt7620/config-5.4 index 6a4dde7ecf..f174dafcd8 100644 --- a/target/linux/ramips/mt7620/config-5.4 +++ b/target/linux/ramips/mt7620/config-5.4 @@ -89,6 +89,7 @@ CONFIG_GENERIC_TIME_VSYSCALL=y CONFIG_GPIOLIB=y # CONFIG_GPIO_MT7621 is not set CONFIG_GPIO_RALINK=y +CONFIG_GPIO_WATCHDOG=y CONFIG_HANDLE_DOMAIN_IRQ=y CONFIG_HARDWARE_WATCHPOINTS=y CONFIG_HAS_DMA=y From c670dfb733ef4a35255c4a3df46bfa3834bd9941 Mon Sep 17 00:00:00 2001 From: Federico Capoano Date: Thu, 15 Sep 2022 19:53:36 +0200 Subject: [PATCH 16/16] mt7620: fix missing kernel config symbol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes following missing kernel config symbol after adding GPIO watchdog: Software watchdog (SOFT_WATCHDOG) [M/n/y/?] m Watchdog device controlled through GPIO-line (GPIO_WATCHDOG) [Y/n/m/?] y Register the watchdog as early as possible (GPIO_WATCHDOG_ARCH_INITCALL) [N/y/?] (NEW) Fixes: 1a97c03d864e ("rampis: feed zbt-we1026 external watchdog") Signed-off-by: Petr Štetiar (cherry picked from commit fb2801b82c06878ae2ad20b8f95546c34ed3cdf4) [adapted to config-5.4] Signed-off-by: Federico Capoano --- target/linux/ramips/mt7620/config-5.4 | 1 + 1 file changed, 1 insertion(+) diff --git a/target/linux/ramips/mt7620/config-5.4 b/target/linux/ramips/mt7620/config-5.4 index f174dafcd8..a886875716 100644 --- a/target/linux/ramips/mt7620/config-5.4 +++ b/target/linux/ramips/mt7620/config-5.4 @@ -90,6 +90,7 @@ CONFIG_GPIOLIB=y # CONFIG_GPIO_MT7621 is not set CONFIG_GPIO_RALINK=y CONFIG_GPIO_WATCHDOG=y +# CONFIG_GPIO_WATCHDOG_ARCH_INITCALL is not set CONFIG_HANDLE_DOMAIN_IRQ=y CONFIG_HARDWARE_WATCHPOINTS=y CONFIG_HAS_DMA=y