[OpenWrt-Devel] PATCH [kernel]: proper support for Edimax uimages

Tomasz Wasiak tjwasiak at gmail.com
Mon Oct 27 00:27:05 EDT 2014


There is support for building proper images for Edimax devices which do have 20 bytes long header before
uImage but those images are not bootable without adding extra kernel parameters as firmware partition is
not automatically split into kernel, rootfs and rootfs_data. Attached patch is corrects this issue (at
least for kernel 3.10.58).


--- a/drivers/mtd/mtdsplit_uimage.c
+++ b/drivers/mtd/mtdsplit_uimage.c
@@ -121,6 +121,31 @@
 		break;
 	}
 
+	if (uimage_size == 0 ) {
+
+		/* find uImage on 20 bytes past erase block boundary (Edimax header is 20 bytes long) */
+		for (offset = 20; offset < master->size; offset += master->erasesize) {
+
+			ret = read_uimage_header(master, offset, header);
+			if (ret)
+				continue;
+
+			if (!verify(header)) {
+				pr_debug("no valid uImage found in \"%s\" at offset %llx\n",
+					 master->name, (unsigned long long) offset);
+				continue;
+			}
+
+			uimage_size = sizeof(*header) + be32_to_cpu(header->ih_size);
+			if ((offset + uimage_size) > master->size) {
+				pr_debug("uImage exceeds MTD device \"%s\"\n",
+					 master->name);
+				continue;
+			}
+			break;
+		}
+	}
+
 	if (uimage_size == 0) {
 		pr_debug("no uImage found in \"%s\"\n", master->name);
 		ret = -ENODEV;
@@ -129,7 +154,7 @@
 
 	uimage_offset = offset;
 
-	if (uimage_offset == 0) {
+	if (uimage_offset == 0 || uimage_offset == 20) {
 		uimage_part = 0;
 		rf_part = 1;
 
@@ -271,10 +296,45 @@
 	.type = MTD_PARSER_TYPE_FIRMWARE,
 };
 
+#define FW_MAGIC_EDIMAX		0x43535953
+
+static bool uimage_verify_edimax(struct uimage_header *header)
+{
+	switch be32_to_cpu(header->ih_magic) {
+	case FW_MAGIC_EDIMAX:
+		break;
+	default:
+		return false;
+	}
+
+	if (header->ih_os != IH_OS_LINUX ||
+	    header->ih_type != IH_TYPE_FILESYSTEM)
+		return false;
+
+	return true;
+}
+
+static int
+mtdsplit_uimage_parse_edimax(struct mtd_info *master,
+			     struct mtd_partition **pparts,
+			     struct mtd_part_parser_data *data)
+{
+	return __mtdsplit_parse_uimage(master, pparts, data,
+				      uimage_verify_edimax);
+}
+
+static struct mtd_part_parser uimage_edimax_parser = {
+	.owner = THIS_MODULE,
+	.name = "edimax-fw",
+	.parse_fn = mtdsplit_uimage_parse_edimax,
+	.type = MTD_PARSER_TYPE_FIRMWARE,
+};
+
 static int __init mtdsplit_uimage_init(void)
 {
 	register_mtd_parser(&uimage_generic_parser);
 	register_mtd_parser(&uimage_netgear_parser);
+	register_mtd_parser(&uimage_edimax_parser);
 
 	return 0;
 }
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list