diff options
author | Hauke Mehrtens <hauke@hauke-m.de> | 2021-03-07 18:28:15 +0100 |
---|---|---|
committer | Hauke Mehrtens <hauke@hauke-m.de> | 2021-03-15 16:57:34 +0100 |
commit | 58c5e256648293fee08792098f1d8643ceedf7fd (patch) | |
tree | 4f502b35d51da24039df280fb274ef27df7ca34f | |
parent | b5b0796a13223b56f1c2e13e2697c92dec22e9c2 (diff) | |
download | upstream-58c5e256648293fee08792098f1d8643ceedf7fd.tar.gz upstream-58c5e256648293fee08792098f1d8643ceedf7fd.tar.bz2 upstream-58c5e256648293fee08792098f1d8643ceedf7fd.zip |
mediatek: support non standard trx magic values
Buffalo uses the TRX format with a different magic, add support for
this.
It is planned to send these patches upstream.
Cc: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: INAGAKI Hiroshi <musashino.open@gmail.com>
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
4 files changed, 196 insertions, 0 deletions
diff --git a/target/linux/mediatek/patches-5.10/350-mtd-parsers-trx-Allow-to-specify-trx-magic-in-DT.patch b/target/linux/mediatek/patches-5.10/350-mtd-parsers-trx-Allow-to-specify-trx-magic-in-DT.patch new file mode 100644 index 0000000000..4db51a88ad --- /dev/null +++ b/target/linux/mediatek/patches-5.10/350-mtd-parsers-trx-Allow-to-specify-trx-magic-in-DT.patch @@ -0,0 +1,75 @@ +From 0600e3d81628002a5cd80cf83ee454851b0063c0 Mon Sep 17 00:00:00 2001 +From: Hauke Mehrtens <hauke@hauke-m.de> +Date: Sun, 7 Mar 2021 18:19:26 +0100 +Subject: mtd: parsers: trx: Allow to specify trx-magic in DT + +Buffalo uses a different TRX magic for every device, to be able to use +this trx parser, make it possible to specify the TRX magic in device +tree. If no TRX magic is specified in device tree, the standard value +will be used. This value should only be specified if a vendor chooses to +use a non standard TRX magic. + +Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> +--- + .../bindings/mtd/partitions/brcm,trx.txt | 5 +++++ + drivers/mtd/parsers/parser_trx.c | 21 ++++++++++++++++++- + 2 files changed, 25 insertions(+), 1 deletion(-) + +--- a/Documentation/devicetree/bindings/mtd/partitions/brcm,trx.txt ++++ b/Documentation/devicetree/bindings/mtd/partitions/brcm,trx.txt +@@ -28,6 +28,11 @@ detected by a software parsing TRX heade + Required properties: + - compatible : (required) must be "brcm,trx" + ++Optional properties: ++ ++- trx-magic: TRX magic, if it is different from the default magic ++ 0x30524448 as a u32. ++ + Example: + + flash@0 { +--- a/drivers/mtd/parsers/parser_trx.c ++++ b/drivers/mtd/parsers/parser_trx.c +@@ -74,6 +74,24 @@ out_default: + return "rootfs"; + } + ++static uint32_t parser_trx_get_magic(struct mtd_info *mtd) ++{ ++ uint32_t trx_magic = TRX_MAGIC; ++ struct device_node *np; ++ int err; ++ ++ np = mtd_get_of_node(mtd); ++ if (!np) ++ return trx_magic; ++ ++ /* Get different magic from device tree if specified */ ++ err = of_property_read_u32(np, "trx-magic", &trx_magic); ++ if (err != 0 && err != -EINVAL) ++ pr_err("failed to parse \"trx-magic\" DT attribute, use default: %d\n", err); ++ ++ return trx_magic; ++} ++ + static int parser_trx_parse(struct mtd_info *mtd, + const struct mtd_partition **pparts, + struct mtd_part_parser_data *data) +@@ -83,6 +101,7 @@ static int parser_trx_parse(struct mtd_i + struct trx_header trx; + size_t bytes_read; + uint8_t curr_part = 0, i = 0; ++ uint32_t trx_magic = parser_trx_get_magic(mtd); + int err; + + parts = kcalloc(TRX_PARSER_MAX_PARTS, sizeof(struct mtd_partition), +@@ -97,7 +116,7 @@ static int parser_trx_parse(struct mtd_i + return err; + } + +- if (trx.magic != TRX_MAGIC) { ++ if (trx.magic != trx_magic) { + kfree(parts); + return -ENOENT; + } diff --git a/target/linux/mediatek/patches-5.10/351-mtd-parsers-Remove-dependency-to-BRCM-architectures.patch b/target/linux/mediatek/patches-5.10/351-mtd-parsers-Remove-dependency-to-BRCM-architectures.patch new file mode 100644 index 0000000000..5f06cad4cd --- /dev/null +++ b/target/linux/mediatek/patches-5.10/351-mtd-parsers-Remove-dependency-to-BRCM-architectures.patch @@ -0,0 +1,23 @@ +From 63f0cf88ab5461acb0911252f12bb94ee3bf05a2 Mon Sep 17 00:00:00 2001 +From: Hauke Mehrtens <hauke@hauke-m.de> +Date: Sun, 7 Mar 2021 18:23:29 +0100 +Subject: mtd: parsers: Remove dependency to BRCM architectures + +Buffalo uses the TRX partition format also on Mediatek SoCs. + +Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> +--- + drivers/mtd/parsers/Kconfig | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/mtd/parsers/Kconfig ++++ b/drivers/mtd/parsers/Kconfig +@@ -121,7 +121,7 @@ config MTD_AFS_PARTS + + config MTD_PARSER_TRX + tristate "Parser for TRX format partitions" +- depends on MTD && (BCM47XX || ARCH_BCM_5301X || COMPILE_TEST) ++ depends on MTD + help + TRX is a firmware format used by Broadcom on their devices. It + may contain up to 3/4 partitions (depending on the version). diff --git a/target/linux/mediatek/patches-5.4/0350-mtd-parsers-trx-Allow-to-specify-trx-magic-in-DT.patch b/target/linux/mediatek/patches-5.4/0350-mtd-parsers-trx-Allow-to-specify-trx-magic-in-DT.patch new file mode 100644 index 0000000000..4db51a88ad --- /dev/null +++ b/target/linux/mediatek/patches-5.4/0350-mtd-parsers-trx-Allow-to-specify-trx-magic-in-DT.patch @@ -0,0 +1,75 @@ +From 0600e3d81628002a5cd80cf83ee454851b0063c0 Mon Sep 17 00:00:00 2001 +From: Hauke Mehrtens <hauke@hauke-m.de> +Date: Sun, 7 Mar 2021 18:19:26 +0100 +Subject: mtd: parsers: trx: Allow to specify trx-magic in DT + +Buffalo uses a different TRX magic for every device, to be able to use +this trx parser, make it possible to specify the TRX magic in device +tree. If no TRX magic is specified in device tree, the standard value +will be used. This value should only be specified if a vendor chooses to +use a non standard TRX magic. + +Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> +--- + .../bindings/mtd/partitions/brcm,trx.txt | 5 +++++ + drivers/mtd/parsers/parser_trx.c | 21 ++++++++++++++++++- + 2 files changed, 25 insertions(+), 1 deletion(-) + +--- a/Documentation/devicetree/bindings/mtd/partitions/brcm,trx.txt ++++ b/Documentation/devicetree/bindings/mtd/partitions/brcm,trx.txt +@@ -28,6 +28,11 @@ detected by a software parsing TRX heade + Required properties: + - compatible : (required) must be "brcm,trx" + ++Optional properties: ++ ++- trx-magic: TRX magic, if it is different from the default magic ++ 0x30524448 as a u32. ++ + Example: + + flash@0 { +--- a/drivers/mtd/parsers/parser_trx.c ++++ b/drivers/mtd/parsers/parser_trx.c +@@ -74,6 +74,24 @@ out_default: + return "rootfs"; + } + ++static uint32_t parser_trx_get_magic(struct mtd_info *mtd) ++{ ++ uint32_t trx_magic = TRX_MAGIC; ++ struct device_node *np; ++ int err; ++ ++ np = mtd_get_of_node(mtd); ++ if (!np) ++ return trx_magic; ++ ++ /* Get different magic from device tree if specified */ ++ err = of_property_read_u32(np, "trx-magic", &trx_magic); ++ if (err != 0 && err != -EINVAL) ++ pr_err("failed to parse \"trx-magic\" DT attribute, use default: %d\n", err); ++ ++ return trx_magic; ++} ++ + static int parser_trx_parse(struct mtd_info *mtd, + const struct mtd_partition **pparts, + struct mtd_part_parser_data *data) +@@ -83,6 +101,7 @@ static int parser_trx_parse(struct mtd_i + struct trx_header trx; + size_t bytes_read; + uint8_t curr_part = 0, i = 0; ++ uint32_t trx_magic = parser_trx_get_magic(mtd); + int err; + + parts = kcalloc(TRX_PARSER_MAX_PARTS, sizeof(struct mtd_partition), +@@ -97,7 +116,7 @@ static int parser_trx_parse(struct mtd_i + return err; + } + +- if (trx.magic != TRX_MAGIC) { ++ if (trx.magic != trx_magic) { + kfree(parts); + return -ENOENT; + } diff --git a/target/linux/mediatek/patches-5.4/0351-mtd-parsers-Remove-dependency-to-BRCM-architectures.patch b/target/linux/mediatek/patches-5.4/0351-mtd-parsers-Remove-dependency-to-BRCM-architectures.patch new file mode 100644 index 0000000000..5f06cad4cd --- /dev/null +++ b/target/linux/mediatek/patches-5.4/0351-mtd-parsers-Remove-dependency-to-BRCM-architectures.patch @@ -0,0 +1,23 @@ +From 63f0cf88ab5461acb0911252f12bb94ee3bf05a2 Mon Sep 17 00:00:00 2001 +From: Hauke Mehrtens <hauke@hauke-m.de> +Date: Sun, 7 Mar 2021 18:23:29 +0100 +Subject: mtd: parsers: Remove dependency to BRCM architectures + +Buffalo uses the TRX partition format also on Mediatek SoCs. + +Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> +--- + drivers/mtd/parsers/Kconfig | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/mtd/parsers/Kconfig ++++ b/drivers/mtd/parsers/Kconfig +@@ -121,7 +121,7 @@ config MTD_AFS_PARTS + + config MTD_PARSER_TRX + tristate "Parser for TRX format partitions" +- depends on MTD && (BCM47XX || ARCH_BCM_5301X || COMPILE_TEST) ++ depends on MTD + help + TRX is a firmware format used by Broadcom on their devices. It + may contain up to 3/4 partitions (depending on the version). |