kernel: mtdsplit_uimage: replace "openwrt, okli" parser
The only difference between the "openwrt,okli" and the generic parser is the magic. Set this in device tree for all affected devices and remove the "openwrt,okli" parser. Tested-by: Michael Pratt <mcpratt@protonmail.com> # EAP300 v2, ENS202EXT and ENH202 Signed-off-by: Bjørn Mork <bjorn@mork.no>
This commit is contained in:
		@@ -4,6 +4,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <dt-bindings/gpio/gpio.h>
 | 
					#include <dt-bindings/gpio/gpio.h>
 | 
				
			||||||
#include <dt-bindings/input/input.h>
 | 
					#include <dt-bindings/input/input.h>
 | 
				
			||||||
 | 
					#include <dt-bindings/mtd/partitions/uimage.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/ {
 | 
					/ {
 | 
				
			||||||
	compatible = "engenius,enh202-v1", "qca,ar7240";
 | 
						compatible = "engenius,enh202-v1", "qca,ar7240";
 | 
				
			||||||
@@ -80,7 +81,8 @@
 | 
				
			|||||||
			#size-cells = <1>;
 | 
								#size-cells = <1>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			partition@0 {
 | 
								partition@0 {
 | 
				
			||||||
				compatible = "openwrt,okli";
 | 
									compatible = "openwrt,uimage", "denx,uimage";
 | 
				
			||||||
 | 
									openwrt,ih-magic = <IH_MAGIC_OKLI>;
 | 
				
			||||||
				label = "firmware";
 | 
									label = "firmware";
 | 
				
			||||||
				reg = <0x0 0x0>;
 | 
									reg = <0x0 0x0>;
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <dt-bindings/gpio/gpio.h>
 | 
					#include <dt-bindings/gpio/gpio.h>
 | 
				
			||||||
#include <dt-bindings/input/input.h>
 | 
					#include <dt-bindings/input/input.h>
 | 
				
			||||||
 | 
					#include <dt-bindings/mtd/partitions/uimage.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/ {
 | 
					/ {
 | 
				
			||||||
	compatible = "engenius,eap350-v1", "qca,ar7242";
 | 
						compatible = "engenius,eap350-v1", "qca,ar7242";
 | 
				
			||||||
@@ -59,7 +60,8 @@
 | 
				
			|||||||
			#size-cells = <1>;
 | 
								#size-cells = <1>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			partition@0 {
 | 
								partition@0 {
 | 
				
			||||||
				compatible = "openwrt,okli";
 | 
									compatible = "openwrt,uimage", "denx,uimage";
 | 
				
			||||||
 | 
									openwrt,ih-magic = <IH_MAGIC_OKLI>;
 | 
				
			||||||
				label = "firmware";
 | 
									label = "firmware";
 | 
				
			||||||
				reg = <0x0 0x0>;
 | 
									reg = <0x0 0x0>;
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <dt-bindings/gpio/gpio.h>
 | 
					#include <dt-bindings/gpio/gpio.h>
 | 
				
			||||||
#include <dt-bindings/input/input.h>
 | 
					#include <dt-bindings/input/input.h>
 | 
				
			||||||
 | 
					#include <dt-bindings/mtd/partitions/uimage.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/ {
 | 
					/ {
 | 
				
			||||||
	compatible = "engenius,ecb350-v1", "qca,ar7242";
 | 
						compatible = "engenius,ecb350-v1", "qca,ar7242";
 | 
				
			||||||
@@ -59,7 +60,8 @@
 | 
				
			|||||||
			#size-cells = <1>;
 | 
								#size-cells = <1>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			partition@0 {
 | 
								partition@0 {
 | 
				
			||||||
				compatible = "openwrt,okli";
 | 
									compatible = "openwrt,uimage", "denx,uimage";
 | 
				
			||||||
 | 
									openwrt,ih-magic = <IH_MAGIC_OKLI>;
 | 
				
			||||||
				label = "firmware";
 | 
									label = "firmware";
 | 
				
			||||||
				reg = <0x0 0x0>;
 | 
									reg = <0x0 0x0>;
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <dt-bindings/gpio/gpio.h>
 | 
					#include <dt-bindings/gpio/gpio.h>
 | 
				
			||||||
#include <dt-bindings/input/input.h>
 | 
					#include <dt-bindings/input/input.h>
 | 
				
			||||||
 | 
					#include <dt-bindings/mtd/partitions/uimage.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/ {
 | 
					/ {
 | 
				
			||||||
	model = "Engenius EAP300 v2";
 | 
						model = "Engenius EAP300 v2";
 | 
				
			||||||
@@ -60,7 +61,8 @@
 | 
				
			|||||||
			#size-cells = <1>;
 | 
								#size-cells = <1>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			partition@0 {
 | 
								partition@0 {
 | 
				
			||||||
				compatible = "openwrt,okli";
 | 
									compatible = "openwrt,uimage", "denx,uimage";
 | 
				
			||||||
 | 
									openwrt,ih-magic = <IH_MAGIC_OKLI>;
 | 
				
			||||||
				label = "firmware";
 | 
									label = "firmware";
 | 
				
			||||||
				reg = <0x0 0x0>;
 | 
									reg = <0x0 0x0>;
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <dt-bindings/gpio/gpio.h>
 | 
					#include <dt-bindings/gpio/gpio.h>
 | 
				
			||||||
#include <dt-bindings/input/input.h>
 | 
					#include <dt-bindings/input/input.h>
 | 
				
			||||||
 | 
					#include <dt-bindings/mtd/partitions/uimage.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/ {
 | 
					/ {
 | 
				
			||||||
	model = "Engenius ENS202EXT v1";
 | 
						model = "Engenius ENS202EXT v1";
 | 
				
			||||||
@@ -70,7 +71,8 @@
 | 
				
			|||||||
			#size-cells = <1>;
 | 
								#size-cells = <1>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			partition@0 {
 | 
								partition@0 {
 | 
				
			||||||
				compatible = "openwrt,okli";
 | 
									compatible = "openwrt,uimage", "denx,uimage";
 | 
				
			||||||
 | 
									openwrt,ih-magic = <IH_MAGIC_OKLI>;
 | 
				
			||||||
				label = "firmware";
 | 
									label = "firmware";
 | 
				
			||||||
				reg = <0x0 0x0>;
 | 
									reg = <0x0 0x0>;
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <dt-bindings/gpio/gpio.h>
 | 
					#include <dt-bindings/gpio/gpio.h>
 | 
				
			||||||
#include <dt-bindings/input/input.h>
 | 
					#include <dt-bindings/input/input.h>
 | 
				
			||||||
 | 
					#include <dt-bindings/mtd/partitions/uimage.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/ {
 | 
					/ {
 | 
				
			||||||
	model = "PISEN WMB001N";
 | 
						model = "PISEN WMB001N";
 | 
				
			||||||
@@ -106,7 +107,8 @@
 | 
				
			|||||||
			partition@0 {
 | 
								partition@0 {
 | 
				
			||||||
				reg = <0x0 0x0>;
 | 
									reg = <0x0 0x0>;
 | 
				
			||||||
				label = "firmware";
 | 
									label = "firmware";
 | 
				
			||||||
				compatible = "openwrt,okli";
 | 
									compatible = "openwrt,uimage", "denx,uimage";
 | 
				
			||||||
 | 
									openwrt,ih-magic = <IH_MAGIC_OKLI>;
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <dt-bindings/gpio/gpio.h>
 | 
					#include <dt-bindings/gpio/gpio.h>
 | 
				
			||||||
#include <dt-bindings/input/input.h>
 | 
					#include <dt-bindings/input/input.h>
 | 
				
			||||||
 | 
					#include <dt-bindings/mtd/partitions/uimage.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/ {
 | 
					/ {
 | 
				
			||||||
	aliases {
 | 
						aliases {
 | 
				
			||||||
@@ -47,7 +48,8 @@
 | 
				
			|||||||
			#size-cells = <1>;
 | 
								#size-cells = <1>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			partition@0 {
 | 
								partition@0 {
 | 
				
			||||||
				compatible = "openwrt,okli";
 | 
									compatible = "openwrt,uimage", "denx,uimage";
 | 
				
			||||||
 | 
									openwrt,ih-magic = <IH_MAGIC_OKLI>;
 | 
				
			||||||
				label = "firmware";
 | 
									label = "firmware";
 | 
				
			||||||
				reg = <0x0 0x0>;
 | 
									reg = <0x0 0x0>;
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <dt-bindings/gpio/gpio.h>
 | 
					#include <dt-bindings/gpio/gpio.h>
 | 
				
			||||||
#include <dt-bindings/input/input.h>
 | 
					#include <dt-bindings/input/input.h>
 | 
				
			||||||
 | 
					#include <dt-bindings/mtd/partitions/uimage.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/ {
 | 
					/ {
 | 
				
			||||||
	compatible = "engenius,enstationac-v1", "qca,qca9557";
 | 
						compatible = "engenius,enstationac-v1", "qca,qca9557";
 | 
				
			||||||
@@ -70,7 +71,8 @@
 | 
				
			|||||||
			#size-cells = <1>;
 | 
								#size-cells = <1>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			partition@0 {
 | 
								partition@0 {
 | 
				
			||||||
				compatible = "openwrt,okli";
 | 
									compatible = "openwrt,uimage", "denx,uimage";
 | 
				
			||||||
 | 
									openwrt,ih-magic = <IH_MAGIC_OKLI>;
 | 
				
			||||||
				label = "firmware";
 | 
									label = "firmware";
 | 
				
			||||||
				reg = <0x0 0x0>;
 | 
									reg = <0x0 0x0>;
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <dt-bindings/gpio/gpio.h>
 | 
					#include <dt-bindings/gpio/gpio.h>
 | 
				
			||||||
#include <dt-bindings/input/input.h>
 | 
					#include <dt-bindings/input/input.h>
 | 
				
			||||||
 | 
					#include <dt-bindings/mtd/partitions/uimage.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/ {
 | 
					/ {
 | 
				
			||||||
	aliases {
 | 
						aliases {
 | 
				
			||||||
@@ -85,7 +86,8 @@
 | 
				
			|||||||
			#size-cells = <1>;
 | 
								#size-cells = <1>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			partition@0 {
 | 
								partition@0 {
 | 
				
			||||||
				compatible = "openwrt,okli";
 | 
									compatible = "openwrt,uimage", "denx,uimage";
 | 
				
			||||||
 | 
									openwrt,ih-magic = <IH_MAGIC_OKLI>;
 | 
				
			||||||
				label = "firmware";
 | 
									label = "firmware";
 | 
				
			||||||
				reg = <0x0 0x0>;
 | 
									reg = <0x0 0x0>;
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -429,58 +429,6 @@ static struct mtd_part_parser uimage_edimax_parser = {
 | 
				
			|||||||
	.type = MTD_PARSER_TYPE_FIRMWARE,
 | 
						.type = MTD_PARSER_TYPE_FIRMWARE,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**************************************************
 | 
					 | 
				
			||||||
 * OKLI (OpenWrt Kernel Loader Image)
 | 
					 | 
				
			||||||
 **************************************************/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define IH_MAGIC_OKLI	0x4f4b4c49
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static ssize_t uimage_verify_okli(u_char *buf, size_t len, u32 ih_magic)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct uimage_header *header = (struct uimage_header *)buf;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* default sanity checks */
 | 
					 | 
				
			||||||
	if (be32_to_cpu(header->ih_magic) != IH_MAGIC_OKLI) {
 | 
					 | 
				
			||||||
		pr_debug("invalid uImage magic: %08x\n",
 | 
					 | 
				
			||||||
			 be32_to_cpu(header->ih_magic));
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (header->ih_os != IH_OS_LINUX) {
 | 
					 | 
				
			||||||
		pr_debug("invalid uImage OS: %08x\n",
 | 
					 | 
				
			||||||
			 be32_to_cpu(header->ih_os));
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (header->ih_type != IH_TYPE_KERNEL) {
 | 
					 | 
				
			||||||
		pr_debug("invalid uImage type: %08x\n",
 | 
					 | 
				
			||||||
			 be32_to_cpu(header->ih_type));
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static int
 | 
					 | 
				
			||||||
mtdsplit_uimage_parse_okli(struct mtd_info *master,
 | 
					 | 
				
			||||||
			      const struct mtd_partition **pparts,
 | 
					 | 
				
			||||||
			      struct mtd_part_parser_data *data)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	return __mtdsplit_parse_uimage(master, pparts, data,
 | 
					 | 
				
			||||||
				      uimage_verify_okli);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static const struct of_device_id mtdsplit_uimage_okli_of_match_table[] = {
 | 
					 | 
				
			||||||
	{ .compatible = "openwrt,okli" },
 | 
					 | 
				
			||||||
	{},
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static struct mtd_part_parser uimage_okli_parser = {
 | 
					 | 
				
			||||||
	.owner = THIS_MODULE,
 | 
					 | 
				
			||||||
	.name = "okli-fw",
 | 
					 | 
				
			||||||
	.of_match_table = mtdsplit_uimage_okli_of_match_table,
 | 
					 | 
				
			||||||
	.parse_fn = mtdsplit_uimage_parse_okli,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**************************************************
 | 
					/**************************************************
 | 
				
			||||||
 * Init
 | 
					 * Init
 | 
				
			||||||
@@ -492,7 +440,6 @@ static int __init mtdsplit_uimage_init(void)
 | 
				
			|||||||
	register_mtd_parser(&uimage_netgear_parser);
 | 
						register_mtd_parser(&uimage_netgear_parser);
 | 
				
			||||||
	register_mtd_parser(&uimage_allnet_parser);
 | 
						register_mtd_parser(&uimage_allnet_parser);
 | 
				
			||||||
	register_mtd_parser(&uimage_edimax_parser);
 | 
						register_mtd_parser(&uimage_edimax_parser);
 | 
				
			||||||
	register_mtd_parser(&uimage_okli_parser);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -188,4 +188,9 @@
 | 
				
			|||||||
#define IH_MAGIC	0x27051956	/* Image Magic Number		*/
 | 
					#define IH_MAGIC	0x27051956	/* Image Magic Number		*/
 | 
				
			||||||
#define IH_NMLEN		32	/* Image Name Length		*/
 | 
					#define IH_NMLEN		32	/* Image Name Length		*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Magic values specific to "openwrt,uimage" partitions
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define IH_MAGIC_OKLI	0x4f4b4c49	/* 'OKLI'			*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif	/* __UIMAGE_H__ */
 | 
					#endif	/* __UIMAGE_H__ */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <dt-bindings/gpio/gpio.h>
 | 
					#include <dt-bindings/gpio/gpio.h>
 | 
				
			||||||
#include <dt-bindings/input/input.h>
 | 
					#include <dt-bindings/input/input.h>
 | 
				
			||||||
 | 
					#include <dt-bindings/mtd/partitions/uimage.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/ {
 | 
					/ {
 | 
				
			||||||
	aliases {
 | 
						aliases {
 | 
				
			||||||
@@ -31,7 +32,8 @@
 | 
				
			|||||||
			#size-cells = <1>;
 | 
								#size-cells = <1>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			partition@0 {
 | 
								partition@0 {
 | 
				
			||||||
				compatible = "openwrt,okli";
 | 
									compatible = "openwrt,uimage", "denx,uimage";
 | 
				
			||||||
 | 
									openwrt,ih-magic = <IH_MAGIC_OKLI>;
 | 
				
			||||||
				label = "firmware";
 | 
									label = "firmware";
 | 
				
			||||||
				reg = <0x0 0x0>;
 | 
									reg = <0x0 0x0>;
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user