diff mbox series

[v4,03/10] kernel: mtdsplit_uimage: replace "fonfxc" and "sge" parsers

Message ID 20210120173653.28784-4-bjorn@mork.no
State Accepted
Delegated to: Petr Štetiar
Headers show
Series kernel: mtdsplit_uimage: use device tree properties for non-standard uimage parsing | expand

Commit Message

Bjørn Mork Jan. 20, 2021, 5:36 p.m. UTC
Convert users of the "fonfxc" and "sge" parsers to the generic
"openwrt,uimage", using device specific "openwrt,padding" properties.

Signed-off-by: Bjørn Mork <bjorn@mork.no>
---
 .../drivers/mtd/mtdsplit/mtdsplit_uimage.c    | 93 ++-----------------
 .../linux/ramips/dts/mt7620a_fon_fon2601.dts  |  3 +-
 .../ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi   |  3 +-
 .../ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi  |  6 +-
 4 files changed, 16 insertions(+), 89 deletions(-)

Comments

Stijn Segers Jan. 22, 2021, 5:46 p.m. UTC | #1
Hi Bjorn,


Op woensdag 20 januari 2021 om 18:36 schreef Bjørn Mork 
<bjorn@mork.no>:
> Convert users of the "fonfxc" and "sge" parsers to the generic
> "openwrt,uimage", using device specific "openwrt,padding" properties.
> 
> Signed-off-by: Bjørn Mork <bjorn@mork.no>


I gave the v4 a few tries on my DIR-878 A1, and it works. Both 
sysupgrading
with and without keeping settings works (been going back and forth 
between
builds with and without the patch set to double check since I was seeing
some unrelated weirdness earlier this week while testing this).

Would be neat to get some people with a DIR-882 A1 to confirm as well (I
know there are some).

Cheers

Stijn

Tested-by: Stijn Segers <foss@volatilesystems.org>

> ---
>  .../drivers/mtd/mtdsplit/mtdsplit_uimage.c    | 93 
> ++-----------------
>  .../linux/ramips/dts/mt7620a_fon_fon2601.dts  |  3 +-
>  .../ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi   |  3 +-
>  .../ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi  |  6 +-
>  4 files changed, 16 insertions(+), 89 deletions(-)
> 
> diff --git 
> a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c 
> b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c
> index f9544ec382e3..f5e48c661e8f 100644
> --- 
> a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c
> +++ 
> b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c
> @@ -87,7 +87,7 @@ static void uimage_parse_dt(struct mtd_info 
> *master, int *extralen)
>  static int __mtdsplit_parse_uimage(struct mtd_info *master,
>  		   const struct mtd_partition **pparts,
>  		   struct mtd_part_parser_data *data,
> -		   ssize_t (*find_header)(u_char *buf, size_t len, int *extralen))
> +		   ssize_t (*find_header)(u_char *buf, size_t len))
>  {
>  	struct mtd_partition *parts;
>  	u_char *buf;
> @@ -125,7 +125,7 @@ static int __mtdsplit_parse_uimage(struct 
> mtd_info *master,
>  		if (ret)
>  			continue;
> 
> -		ret = find_header(buf, MAX_HEADER_LEN, &extralen);
> +		ret = find_header(buf, MAX_HEADER_LEN);
>  		if (ret < 0) {
>  			pr_debug("no valid uImage found in \"%s\" at offset %llx\n",
>  				 master->name, (unsigned long long) offset);
> @@ -213,7 +213,7 @@ err_free_parts:
>  	return ret;
>  }
> 
> -static ssize_t uimage_verify_default(u_char *buf, size_t len, int 
> *extralen)
> +static ssize_t uimage_verify_default(u_char *buf, size_t len)
>  {
>  	struct uimage_header *header = (struct uimage_header *)buf;
> 
> @@ -274,7 +274,7 @@ static struct mtd_part_parser 
> uimage_generic_parser = {
>  #define FW_MAGIC_WNDR3700V2	0x33373031
>  #define FW_MAGIC_WPN824N	0x31313030
> 
> -static ssize_t uimage_verify_wndr3700(u_char *buf, size_t len, int 
> *extralen)
> +static ssize_t uimage_verify_wndr3700(u_char *buf, size_t len)
>  {
>  	struct uimage_header *header = (struct uimage_header *)buf;
>  	uint8_t expected_type = IH_TYPE_FILESYSTEM;
> @@ -336,7 +336,7 @@ static struct mtd_part_parser 
> uimage_netgear_parser = {
>  #define FW_MAGIC_SG8208M	0x00000006
>  #define FW_MAGIC_SG8310PM	0x83000006
> 
> -static ssize_t uimage_verify_allnet(u_char *buf, size_t len, int 
> *extralen)
> +static ssize_t uimage_verify_allnet(u_char *buf, size_t len)
>  {
>  	struct uimage_header *header = (struct uimage_header *)buf;
> 
> @@ -383,7 +383,7 @@ static struct mtd_part_parser 
> uimage_allnet_parser = {
>  #define FW_EDIMAX_OFFSET	20
>  #define FW_MAGIC_EDIMAX		0x43535953
> 
> -static ssize_t uimage_find_edimax(u_char *buf, size_t len, int 
> *extralen)
> +static ssize_t uimage_find_edimax(u_char *buf, size_t len)
>  {
>  	u32 *magic;
> 
> @@ -396,7 +396,7 @@ static ssize_t uimage_find_edimax(u_char *buf, 
> size_t len, int *extralen)
>  	if (be32_to_cpu(*magic) != FW_MAGIC_EDIMAX)
>  		return -EINVAL;
> 
> -	if (!uimage_verify_default(buf + FW_EDIMAX_OFFSET, len, extralen))
> +	if (!uimage_verify_default(buf + FW_EDIMAX_OFFSET, len))
>  		return FW_EDIMAX_OFFSET;
> 
>  	return -EINVAL;
> @@ -424,88 +424,13 @@ static struct mtd_part_parser 
> uimage_edimax_parser = {
>  	.type = MTD_PARSER_TYPE_FIRMWARE,
>  };
> 
> -
> -/**************************************************
> - * Fon(Foxconn)
> - **************************************************/
> -
> -#define FONFXC_PAD_LEN		32
> -
> -static ssize_t uimage_find_fonfxc(u_char *buf, size_t len, int 
> *extralen)
> -{
> -	if (uimage_verify_default(buf, len, extralen) < 0)
> -		return -EINVAL;
> -
> -	*extralen = FONFXC_PAD_LEN;
> -
> -	return 0;
> -}
> -
> -static int
> -mtdsplit_uimage_parse_fonfxc(struct mtd_info *master,
> -			      const struct mtd_partition **pparts,
> -			      struct mtd_part_parser_data *data)
> -{
> -	return __mtdsplit_parse_uimage(master, pparts, data,
> -				       uimage_find_fonfxc);
> -}
> -
> -static const struct of_device_id 
> mtdsplit_uimage_fonfxc_of_match_table[] = {
> -	{ .compatible = "fonfxc,uimage" },
> -	{},
> -};
> -
> -static struct mtd_part_parser uimage_fonfxc_parser = {
> -	.owner = THIS_MODULE,
> -	.name = "fonfxc-fw",
> -	.of_match_table = mtdsplit_uimage_fonfxc_of_match_table,
> -	.parse_fn = mtdsplit_uimage_parse_fonfxc,
> -};
> -
> -/**************************************************
> - * SGE (T&W) Shenzhen Gongjin Electronics
> - **************************************************/
> -
> -#define SGE_PAD_LEN		96
> -
> -static ssize_t uimage_find_sge(u_char *buf, size_t len, int 
> *extralen)
> -{
> -	if (uimage_verify_default(buf, len, extralen) < 0)
> -		return -EINVAL;
> -
> -	*extralen = SGE_PAD_LEN;
> -
> -	return 0;
> -}
> -
> -static int
> -mtdsplit_uimage_parse_sge(struct mtd_info *master,
> -			      const struct mtd_partition **pparts,
> -			      struct mtd_part_parser_data *data)
> -{
> -	return __mtdsplit_parse_uimage(master, pparts, data,
> -				       uimage_find_sge);
> -}
> -
> -static const struct of_device_id 
> mtdsplit_uimage_sge_of_match_table[] = {
> -	{ .compatible = "sge,uimage" },
> -	{},
> -};
> -
> -static struct mtd_part_parser uimage_sge_parser = {
> -	.owner = THIS_MODULE,
> -	.name = "sge-fw",
> -	.of_match_table = mtdsplit_uimage_sge_of_match_table,
> -	.parse_fn = mtdsplit_uimage_parse_sge,
> -};
> -
>  /**************************************************
>   * OKLI (OpenWrt Kernel Loader Image)
>   **************************************************/
> 
>  #define IH_MAGIC_OKLI	0x4f4b4c49
> 
> -static ssize_t uimage_verify_okli(u_char *buf, size_t len, int 
> *extralen)
> +static ssize_t uimage_verify_okli(u_char *buf, size_t len)
>  {
>  	struct uimage_header *header = (struct uimage_header *)buf;
> 
> @@ -562,8 +487,6 @@ static int __init mtdsplit_uimage_init(void)
>  	register_mtd_parser(&uimage_netgear_parser);
>  	register_mtd_parser(&uimage_allnet_parser);
>  	register_mtd_parser(&uimage_edimax_parser);
> -	register_mtd_parser(&uimage_fonfxc_parser);
> -	register_mtd_parser(&uimage_sge_parser);
>  	register_mtd_parser(&uimage_okli_parser);
> 
>  	return 0;
> diff --git a/target/linux/ramips/dts/mt7620a_fon_fon2601.dts 
> b/target/linux/ramips/dts/mt7620a_fon_fon2601.dts
> index 4dc0e28c9f61..ee61c6e59e99 100644
> --- a/target/linux/ramips/dts/mt7620a_fon_fon2601.dts
> +++ b/target/linux/ramips/dts/mt7620a_fon_fon2601.dts
> @@ -83,7 +83,8 @@
>  			};
> 
>  			partition@50000 {
> -				compatible = "fonfxc,uimage";
> +				compatible = "openwrt,uimage", "denx,uimage";
> +				openwrt,padding = <32>;
>  				label = "firmware";
>  				reg = <0x50000 0xf90000>;
>  			};
> diff --git a/target/linux/ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi 
> b/target/linux/ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi
> index c43cc49aa16f..95ef0afcd9d5 100644
> --- a/target/linux/ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi
> +++ b/target/linux/ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi
> @@ -34,7 +34,8 @@
>  			};
> 
>  			partition@60000 {
> -				compatible = "sge,uimage";
> +				compatible = "openwrt,uimage", "denx,uimage";
> +				openwrt,padding = <96>;
>  				label = "firmware";
>  				reg = <0x60000 0xfa0000>;
>  			};
> diff --git a/target/linux/ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi 
> b/target/linux/ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi
> index 96c69211243b..a54b2be4f061 100644
> --- a/target/linux/ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi
> +++ b/target/linux/ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi
> @@ -89,7 +89,8 @@
> 
>  		partition@180000 {
>  			label = "firmware";
> -			compatible = "sge,uimage";
> +			compatible = "openwrt,uimage", "denx,uimage";
> +			openwrt,padding = <96>;
>  			reg = <0x180000 0x2800000>;
>  		};
> 
> @@ -101,7 +102,8 @@
> 
>  		partition@4980000 {
>  			label = "firmware2";
> -			compatible = "sge,uimage";
> +			compatible = "openwrt,uimage", "denx,uimage";
> +			openwrt,padding = <96>;
>  			reg = <0x4980000 0x2800000>;
>  		};
> 
> --
> 2.20.1
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
diff mbox series

Patch

diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c
index f9544ec382e3..f5e48c661e8f 100644
--- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c
+++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c
@@ -87,7 +87,7 @@  static void uimage_parse_dt(struct mtd_info *master, int *extralen)
 static int __mtdsplit_parse_uimage(struct mtd_info *master,
 		   const struct mtd_partition **pparts,
 		   struct mtd_part_parser_data *data,
-		   ssize_t (*find_header)(u_char *buf, size_t len, int *extralen))
+		   ssize_t (*find_header)(u_char *buf, size_t len))
 {
 	struct mtd_partition *parts;
 	u_char *buf;
@@ -125,7 +125,7 @@  static int __mtdsplit_parse_uimage(struct mtd_info *master,
 		if (ret)
 			continue;
 
-		ret = find_header(buf, MAX_HEADER_LEN, &extralen);
+		ret = find_header(buf, MAX_HEADER_LEN);
 		if (ret < 0) {
 			pr_debug("no valid uImage found in \"%s\" at offset %llx\n",
 				 master->name, (unsigned long long) offset);
@@ -213,7 +213,7 @@  err_free_parts:
 	return ret;
 }
 
-static ssize_t uimage_verify_default(u_char *buf, size_t len, int *extralen)
+static ssize_t uimage_verify_default(u_char *buf, size_t len)
 {
 	struct uimage_header *header = (struct uimage_header *)buf;
 
@@ -274,7 +274,7 @@  static struct mtd_part_parser uimage_generic_parser = {
 #define FW_MAGIC_WNDR3700V2	0x33373031
 #define FW_MAGIC_WPN824N	0x31313030
 
-static ssize_t uimage_verify_wndr3700(u_char *buf, size_t len, int *extralen)
+static ssize_t uimage_verify_wndr3700(u_char *buf, size_t len)
 {
 	struct uimage_header *header = (struct uimage_header *)buf;
 	uint8_t expected_type = IH_TYPE_FILESYSTEM;
@@ -336,7 +336,7 @@  static struct mtd_part_parser uimage_netgear_parser = {
 #define FW_MAGIC_SG8208M	0x00000006
 #define FW_MAGIC_SG8310PM	0x83000006
 
-static ssize_t uimage_verify_allnet(u_char *buf, size_t len, int *extralen)
+static ssize_t uimage_verify_allnet(u_char *buf, size_t len)
 {
 	struct uimage_header *header = (struct uimage_header *)buf;
 
@@ -383,7 +383,7 @@  static struct mtd_part_parser uimage_allnet_parser = {
 #define FW_EDIMAX_OFFSET	20
 #define FW_MAGIC_EDIMAX		0x43535953
 
-static ssize_t uimage_find_edimax(u_char *buf, size_t len, int *extralen)
+static ssize_t uimage_find_edimax(u_char *buf, size_t len)
 {
 	u32 *magic;
 
@@ -396,7 +396,7 @@  static ssize_t uimage_find_edimax(u_char *buf, size_t len, int *extralen)
 	if (be32_to_cpu(*magic) != FW_MAGIC_EDIMAX)
 		return -EINVAL;
 
-	if (!uimage_verify_default(buf + FW_EDIMAX_OFFSET, len, extralen))
+	if (!uimage_verify_default(buf + FW_EDIMAX_OFFSET, len))
 		return FW_EDIMAX_OFFSET;
 
 	return -EINVAL;
@@ -424,88 +424,13 @@  static struct mtd_part_parser uimage_edimax_parser = {
 	.type = MTD_PARSER_TYPE_FIRMWARE,
 };
 
-
-/**************************************************
- * Fon(Foxconn)
- **************************************************/
-
-#define FONFXC_PAD_LEN		32
-
-static ssize_t uimage_find_fonfxc(u_char *buf, size_t len, int *extralen)
-{
-	if (uimage_verify_default(buf, len, extralen) < 0)
-		return -EINVAL;
-
-	*extralen = FONFXC_PAD_LEN;
-
-	return 0;
-}
-
-static int
-mtdsplit_uimage_parse_fonfxc(struct mtd_info *master,
-			      const struct mtd_partition **pparts,
-			      struct mtd_part_parser_data *data)
-{
-	return __mtdsplit_parse_uimage(master, pparts, data,
-				       uimage_find_fonfxc);
-}
-
-static const struct of_device_id mtdsplit_uimage_fonfxc_of_match_table[] = {
-	{ .compatible = "fonfxc,uimage" },
-	{},
-};
-
-static struct mtd_part_parser uimage_fonfxc_parser = {
-	.owner = THIS_MODULE,
-	.name = "fonfxc-fw",
-	.of_match_table = mtdsplit_uimage_fonfxc_of_match_table,
-	.parse_fn = mtdsplit_uimage_parse_fonfxc,
-};
-
-/**************************************************
- * SGE (T&W) Shenzhen Gongjin Electronics
- **************************************************/
-
-#define SGE_PAD_LEN		96
-
-static ssize_t uimage_find_sge(u_char *buf, size_t len, int *extralen)
-{
-	if (uimage_verify_default(buf, len, extralen) < 0)
-		return -EINVAL;
-
-	*extralen = SGE_PAD_LEN;
-
-	return 0;
-}
-
-static int
-mtdsplit_uimage_parse_sge(struct mtd_info *master,
-			      const struct mtd_partition **pparts,
-			      struct mtd_part_parser_data *data)
-{
-	return __mtdsplit_parse_uimage(master, pparts, data,
-				       uimage_find_sge);
-}
-
-static const struct of_device_id mtdsplit_uimage_sge_of_match_table[] = {
-	{ .compatible = "sge,uimage" },
-	{},
-};
-
-static struct mtd_part_parser uimage_sge_parser = {
-	.owner = THIS_MODULE,
-	.name = "sge-fw",
-	.of_match_table = mtdsplit_uimage_sge_of_match_table,
-	.parse_fn = mtdsplit_uimage_parse_sge,
-};
-
 /**************************************************
  * OKLI (OpenWrt Kernel Loader Image)
  **************************************************/
 
 #define IH_MAGIC_OKLI	0x4f4b4c49
 
-static ssize_t uimage_verify_okli(u_char *buf, size_t len, int *extralen)
+static ssize_t uimage_verify_okli(u_char *buf, size_t len)
 {
 	struct uimage_header *header = (struct uimage_header *)buf;
 
@@ -562,8 +487,6 @@  static int __init mtdsplit_uimage_init(void)
 	register_mtd_parser(&uimage_netgear_parser);
 	register_mtd_parser(&uimage_allnet_parser);
 	register_mtd_parser(&uimage_edimax_parser);
-	register_mtd_parser(&uimage_fonfxc_parser);
-	register_mtd_parser(&uimage_sge_parser);
 	register_mtd_parser(&uimage_okli_parser);
 
 	return 0;
diff --git a/target/linux/ramips/dts/mt7620a_fon_fon2601.dts b/target/linux/ramips/dts/mt7620a_fon_fon2601.dts
index 4dc0e28c9f61..ee61c6e59e99 100644
--- a/target/linux/ramips/dts/mt7620a_fon_fon2601.dts
+++ b/target/linux/ramips/dts/mt7620a_fon_fon2601.dts
@@ -83,7 +83,8 @@ 
 			};
 
 			partition@50000 {
-				compatible = "fonfxc,uimage";
+				compatible = "openwrt,uimage", "denx,uimage";
+				openwrt,padding = <32>;
 				label = "firmware";
 				reg = <0x50000 0xf90000>;
 			};
diff --git a/target/linux/ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi b/target/linux/ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi
index c43cc49aa16f..95ef0afcd9d5 100644
--- a/target/linux/ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi
+++ b/target/linux/ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi
@@ -34,7 +34,8 @@ 
 			};
 
 			partition@60000 {
-				compatible = "sge,uimage";
+				compatible = "openwrt,uimage", "denx,uimage";
+				openwrt,padding = <96>;
 				label = "firmware";
 				reg = <0x60000 0xfa0000>;
 			};
diff --git a/target/linux/ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi b/target/linux/ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi
index 96c69211243b..a54b2be4f061 100644
--- a/target/linux/ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi
+++ b/target/linux/ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi
@@ -89,7 +89,8 @@ 
 
 		partition@180000 {
 			label = "firmware";
-			compatible = "sge,uimage";
+			compatible = "openwrt,uimage", "denx,uimage";
+			openwrt,padding = <96>;
 			reg = <0x180000 0x2800000>;
 		};
 
@@ -101,7 +102,8 @@ 
 
 		partition@4980000 {
 			label = "firmware2";
-			compatible = "sge,uimage";
+			compatible = "openwrt,uimage", "denx,uimage";
+			openwrt,padding = <96>;
 			reg = <0x4980000 0x2800000>;
 		};