kernel/3.1x: add split code for LZMA compressed kernel based firmwares
authorGabor Juhos <juhosg@openwrt.org>
Fri, 24 Jan 2014 17:14:59 +0000 (17:14 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Fri, 24 Jan 2014 17:14:59 +0000 (17:14 +0000)
Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
SVN-Revision: 39387

target/linux/generic/config-3.10
target/linux/generic/config-3.12
target/linux/generic/config-3.13
target/linux/generic/files/drivers/mtd/mtdsplit_lzma.c [new file with mode: 0644]
target/linux/generic/patches-3.10/409-mtd-hook-mtdsplit_lzma-into-Kbuild.patch [new file with mode: 0644]
target/linux/generic/patches-3.12/409-mtd-hook-mtdsplit_lzma-into-Kbuild.patch [new file with mode: 0644]
target/linux/generic/patches-3.12/430-mtd-add-myloader-partition-parser.patch
target/linux/generic/patches-3.13/409-mtd-hook-mtdsplit_lzma-into-Kbuild.patch [new file with mode: 0644]
target/linux/generic/patches-3.13/430-mtd-add-myloader-partition-parser.patch

index a2d4ec2bc0f8e5607dc09d4f6dcc2b9d2beaa28c..30d7d6e7a83f37a011931d9d2e5ef0242c65e025 100644 (file)
@@ -1955,6 +1955,7 @@ CONFIG_MTD_ROOTFS_SPLIT=y
 CONFIG_MTD_SPLIT=y
 # CONFIG_MTD_SPLIT_FIRMWARE is not set
 CONFIG_MTD_SPLIT_FIRMWARE_NAME="firmware"
+# CONFIG_MTD_SPLIT_LZMA_FW is not set
 # CONFIG_MTD_SPLIT_SEAMA_FW is not set
 # CONFIG_MTD_SPLIT_SQUASHFS_ROOT is not set
 # CONFIG_MTD_SPLIT_UIMAGE_FW is not set
index 8398a6130a7e3fb751264c0da773285349b6244a..78d376a0cffc4fe2cc8bfb8240996bffd6b6cea9 100644 (file)
@@ -2031,6 +2031,7 @@ CONFIG_MTD_ROOTFS_SPLIT=y
 CONFIG_MTD_SPLIT=y
 # CONFIG_MTD_SPLIT_FIRMWARE is not set
 CONFIG_MTD_SPLIT_FIRMWARE_NAME="firmware"
+# CONFIG_MTD_SPLIT_LZMA_FW is not set
 # CONFIG_MTD_SPLIT_SEAMA_FW is not set
 # CONFIG_MTD_SPLIT_SQUASHFS_ROOT is not set
 # CONFIG_MTD_SPLIT_UIMAGE_FW is not set
index 8579f8b05377a40d373dcd3d52ba00c7f79cb22b..ff6c09c2a9870491fca493e617e5917b01722318 100644 (file)
@@ -2051,6 +2051,7 @@ CONFIG_MTD_ROOTFS_SPLIT=y
 CONFIG_MTD_SPLIT=y
 # CONFIG_MTD_SPLIT_FIRMWARE is not set
 CONFIG_MTD_SPLIT_FIRMWARE_NAME="firmware"
+# CONFIG_MTD_SPLIT_LZMA_FW is not set
 # CONFIG_MTD_SPLIT_SEAMA_FW is not set
 # CONFIG_MTD_SPLIT_SQUASHFS_ROOT is not set
 # CONFIG_MTD_SPLIT_UIMAGE_FW is not set
diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit_lzma.c b/target/linux/generic/files/drivers/mtd/mtdsplit_lzma.c
new file mode 100644 (file)
index 0000000..d23060a
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ *  Copyright (C) 2014 Gabor Juhos <juhosg@openwrt.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License version 2 as published
+ *  by the Free Software Foundation.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+
+#include <asm/unaligned.h>
+
+#include "mtdsplit.h"
+
+#define LZMA_NR_PARTS          2
+#define LZMA_PROPERTIES_SIZE   5
+
+struct lzma_header {
+       u8 props[LZMA_PROPERTIES_SIZE];
+       u8 size_low[4];
+       u8 size_high[4];
+};
+
+static int mtdsplit_parse_lzma(struct mtd_info *master,
+                              struct mtd_partition **pparts,
+                              struct mtd_part_parser_data *data)
+{
+       struct lzma_header hdr;
+       size_t hdr_len, retlen;
+       size_t rootfs_offset;
+       u32 t;
+       struct mtd_partition *parts;
+       int err;
+
+       hdr_len = sizeof(hdr);
+       err = mtd_read(master, 0, hdr_len, &retlen, (void *) &hdr);
+       if (err)
+               return err;
+
+       if (retlen != hdr_len)
+               return -EIO;
+
+       /* verify LZMA properties */
+       if (hdr.props[0] >= (9 * 5 * 5))
+               return -EINVAL;
+
+       t = get_unaligned_le32(&hdr.props[1]);
+       if (!is_power_of_2(t))
+               return -EINVAL;
+
+       t = get_unaligned_le32(&hdr.size_high);
+       if (t)
+               return -EINVAL;
+
+       err = mtd_find_rootfs_from(master, master->erasesize,
+                                  master->size, &rootfs_offset);
+       if (err)
+               return err;
+
+       parts = kzalloc(LZMA_NR_PARTS * sizeof(*parts), GFP_KERNEL);
+       if (!parts)
+               return -ENOMEM;
+
+       parts[0].name = KERNEL_PART_NAME;
+       parts[0].offset = 0;
+       parts[0].size = rootfs_offset;
+
+       parts[1].name = ROOTFS_PART_NAME;
+       parts[1].offset = rootfs_offset;
+       parts[1].size = master->size - rootfs_offset;
+
+       *pparts = parts;
+       return LZMA_NR_PARTS;
+}
+
+static struct mtd_part_parser mtdsplit_lzma_parser = {
+       .owner = THIS_MODULE,
+       .name = "lzma-fw",
+       .parse_fn = mtdsplit_parse_lzma,
+       .type = MTD_PARSER_TYPE_FIRMWARE,
+};
+
+static int
+mtdsplit_lzma_init(void)
+{
+       return register_mtd_parser(&mtdsplit_lzma_parser);
+}
+
+subsys_initcall(mtdsplit_lzma_init);
diff --git a/target/linux/generic/patches-3.10/409-mtd-hook-mtdsplit_lzma-into-Kbuild.patch b/target/linux/generic/patches-3.10/409-mtd-hook-mtdsplit_lzma-into-Kbuild.patch
new file mode 100644 (file)
index 0000000..cc9a971
--- /dev/null
@@ -0,0 +1,23 @@
+--- a/drivers/mtd/Kconfig
++++ b/drivers/mtd/Kconfig
+@@ -58,6 +58,10 @@ config MTD_SPLIT_UIMAGE_FW
+       bool "uImage based firmware partition parser"
+       select MTD_SPLIT
++config MTD_SPLIT_LZMA_FW
++      bool "LZMA compressed kernel based firmware partition parser"
++      select MTD_SPLIT
++
+ config MTD_SPLIT
+       def_bool n
+       help 
+--- a/drivers/mtd/Makefile
++++ b/drivers/mtd/Makefile
+@@ -10,6 +10,7 @@ mtd-$(CONFIG_MTD_SPLIT)              += mtdsplit.o
+ mtd-$(CONFIG_MTD_SPLIT_SEAMA_FW) += mtdsplit_seama.o
+ mtd-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
+ mtd-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtdsplit_uimage.o
++mtd-$(CONFIG_MTD_SPLIT_LZMA_FW) += mtdsplit_lzma.o
+ obj-$(CONFIG_MTD_OF_PARTS)    += ofpart.o
+ obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
diff --git a/target/linux/generic/patches-3.12/409-mtd-hook-mtdsplit_lzma-into-Kbuild.patch b/target/linux/generic/patches-3.12/409-mtd-hook-mtdsplit_lzma-into-Kbuild.patch
new file mode 100644 (file)
index 0000000..cc9a971
--- /dev/null
@@ -0,0 +1,23 @@
+--- a/drivers/mtd/Kconfig
++++ b/drivers/mtd/Kconfig
+@@ -58,6 +58,10 @@ config MTD_SPLIT_UIMAGE_FW
+       bool "uImage based firmware partition parser"
+       select MTD_SPLIT
++config MTD_SPLIT_LZMA_FW
++      bool "LZMA compressed kernel based firmware partition parser"
++      select MTD_SPLIT
++
+ config MTD_SPLIT
+       def_bool n
+       help 
+--- a/drivers/mtd/Makefile
++++ b/drivers/mtd/Makefile
+@@ -10,6 +10,7 @@ mtd-$(CONFIG_MTD_SPLIT)              += mtdsplit.o
+ mtd-$(CONFIG_MTD_SPLIT_SEAMA_FW) += mtdsplit_seama.o
+ mtd-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
+ mtd-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtdsplit_uimage.o
++mtd-$(CONFIG_MTD_SPLIT_LZMA_FW) += mtdsplit_lzma.o
+ obj-$(CONFIG_MTD_OF_PARTS)    += ofpart.o
+ obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
index 47c2fd06e73230cbe357fb12c301eb57c7f50116..fc352d2779f00bd3a083270a91b405f054d8f6b0 100644 (file)
@@ -1,6 +1,6 @@
 --- a/drivers/mtd/Kconfig
 +++ b/drivers/mtd/Kconfig
-@@ -208,6 +208,22 @@ config MTD_BCM47XX_PARTS
+@@ -212,6 +212,22 @@ config MTD_BCM47XX_PARTS
          This provides partitions parser for devices based on BCM47xx
          boards.
  
@@ -25,7 +25,7 @@
  config MTD_BLKDEVS
 --- a/drivers/mtd/Makefile
 +++ b/drivers/mtd/Makefile
-@@ -18,6 +18,7 @@ obj-$(CONFIG_MTD_AFS_PARTS)  += afs.o
+@@ -19,6 +19,7 @@ obj-$(CONFIG_MTD_AFS_PARTS)  += afs.o
  obj-$(CONFIG_MTD_AR7_PARTS)   += ar7part.o
  obj-$(CONFIG_MTD_BCM63XX_PARTS)       += bcm63xxpart.o
  obj-$(CONFIG_MTD_BCM47XX_PARTS)       += bcm47xxpart.o
diff --git a/target/linux/generic/patches-3.13/409-mtd-hook-mtdsplit_lzma-into-Kbuild.patch b/target/linux/generic/patches-3.13/409-mtd-hook-mtdsplit_lzma-into-Kbuild.patch
new file mode 100644 (file)
index 0000000..cc9a971
--- /dev/null
@@ -0,0 +1,23 @@
+--- a/drivers/mtd/Kconfig
++++ b/drivers/mtd/Kconfig
+@@ -58,6 +58,10 @@ config MTD_SPLIT_UIMAGE_FW
+       bool "uImage based firmware partition parser"
+       select MTD_SPLIT
++config MTD_SPLIT_LZMA_FW
++      bool "LZMA compressed kernel based firmware partition parser"
++      select MTD_SPLIT
++
+ config MTD_SPLIT
+       def_bool n
+       help 
+--- a/drivers/mtd/Makefile
++++ b/drivers/mtd/Makefile
+@@ -10,6 +10,7 @@ mtd-$(CONFIG_MTD_SPLIT)              += mtdsplit.o
+ mtd-$(CONFIG_MTD_SPLIT_SEAMA_FW) += mtdsplit_seama.o
+ mtd-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
+ mtd-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtdsplit_uimage.o
++mtd-$(CONFIG_MTD_SPLIT_LZMA_FW) += mtdsplit_lzma.o
+ obj-$(CONFIG_MTD_OF_PARTS)    += ofpart.o
+ obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
index 47c2fd06e73230cbe357fb12c301eb57c7f50116..fc352d2779f00bd3a083270a91b405f054d8f6b0 100644 (file)
@@ -1,6 +1,6 @@
 --- a/drivers/mtd/Kconfig
 +++ b/drivers/mtd/Kconfig
-@@ -208,6 +208,22 @@ config MTD_BCM47XX_PARTS
+@@ -212,6 +212,22 @@ config MTD_BCM47XX_PARTS
          This provides partitions parser for devices based on BCM47xx
          boards.
  
@@ -25,7 +25,7 @@
  config MTD_BLKDEVS
 --- a/drivers/mtd/Makefile
 +++ b/drivers/mtd/Makefile
-@@ -18,6 +18,7 @@ obj-$(CONFIG_MTD_AFS_PARTS)  += afs.o
+@@ -19,6 +19,7 @@ obj-$(CONFIG_MTD_AFS_PARTS)  += afs.o
  obj-$(CONFIG_MTD_AR7_PARTS)   += ar7part.o
  obj-$(CONFIG_MTD_BCM63XX_PARTS)       += bcm63xxpart.o
  obj-$(CONFIG_MTD_BCM47XX_PARTS)       += bcm47xxpart.o