2013-10-23 12:51:05 +00:00
|
|
|
--- a/arch/mips/lantiq/xway/Makefile
|
|
|
|
+++ b/arch/mips/lantiq/xway/Makefile
|
2013-09-17 21:46:10 +00:00
|
|
|
@@ -1,6 +1,6 @@
|
|
|
|
obj-y := prom.o sysctrl.o clk.o reset.o dma.o gptu.o dcdc.o
|
|
|
|
|
|
|
|
-obj-y += vmmc.o
|
|
|
|
+obj-y += vmmc.o mtd_split.o
|
|
|
|
|
|
|
|
obj-$(CONFIG_PCI) += ath_eep.o rt_eep.o pci-ath-fixup.o
|
|
|
|
|
2013-10-23 12:51:05 +00:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/arch/mips/lantiq/xway/mtd_split.c
|
2013-10-07 15:02:48 +00:00
|
|
|
@@ -0,0 +1,129 @@
|
2013-09-17 21:46:10 +00:00
|
|
|
+#include <linux/magic.h>
|
|
|
|
+#include <linux/root_dev.h>
|
|
|
|
+#include <linux/mtd/mtd.h>
|
|
|
|
+#include <linux/mtd/partitions.h>
|
|
|
|
+
|
|
|
|
+#define ROOTFS_SPLIT_NAME "rootfs_data"
|
|
|
|
+
|
|
|
|
+struct squashfs_super_block {
|
|
|
|
+ __le32 s_magic;
|
|
|
|
+ __le32 pad0[9];
|
|
|
|
+ __le64 bytes_used;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static void split_brnimage_kernel(struct mtd_info *master, const char *name,
|
|
|
|
+ int offset, int size)
|
|
|
|
+{
|
|
|
|
+ unsigned long buf[4];
|
|
|
|
+ // Assume at most 2MB of kernel image
|
|
|
|
+ unsigned long end = offset + (2 << 20);
|
|
|
|
+ unsigned long part_size = offset + 0x400 - 12;
|
|
|
|
+ size_t len;
|
|
|
|
+ int ret;
|
|
|
|
+
|
|
|
|
+ if (strcmp(name, "rootfs") != 0)
|
|
|
|
+ return;
|
|
|
|
+ while (part_size < end) {
|
|
|
|
+ long size_min = part_size - 0x400 - 12 - offset;
|
|
|
|
+ long size_max = part_size + 12 - offset;
|
|
|
|
+ ret = mtd_read(master, part_size, 16, &len, (void *)buf);
|
|
|
|
+ if (ret || len != 16)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ if (le32_to_cpu(buf[0]) < size_min ||
|
|
|
|
+ le32_to_cpu(buf[0]) > size_max) {
|
|
|
|
+ part_size += 0x400;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (le32_to_cpu(buf[3]) == SQUASHFS_MAGIC) {
|
|
|
|
+ part_size += 12 - offset;
|
|
|
|
+ __mtd_add_partition(master, "rootfs", offset + part_size,
|
|
|
|
+ size - part_size, false);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ part_size += 0x400;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void split_eva_kernel(struct mtd_info *master, const char *name,
|
|
|
|
+ int offset, int size)
|
|
|
|
+{
|
|
|
|
+#define EVA_MAGIC 0xfeed1281
|
|
|
|
+ unsigned long magic = 0;
|
2013-10-07 15:02:48 +00:00
|
|
|
+ unsigned long part_size = 0, p;
|
2013-09-17 21:46:10 +00:00
|
|
|
+ size_t len;
|
|
|
|
+ int ret;
|
|
|
|
+
|
|
|
|
+ if (strcmp(name, CONFIG_MTD_SPLIT_FIRMWARE_NAME) != 0)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ ret = mtd_read(master, offset, 4, &len, (void *)&magic);
|
|
|
|
+ if (ret || len != sizeof(magic))
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ if (le32_to_cpu(magic) != EVA_MAGIC)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ ret = mtd_read(master, offset + 4, 4, &len, (void *)&part_size);
|
|
|
|
+ if (ret || len != sizeof(part_size))
|
|
|
|
+ return;
|
|
|
|
+
|
2013-10-07 15:02:48 +00:00
|
|
|
+ p = part_size = le32_to_cpu(part_size) + 0x18;
|
|
|
|
+ p &= ~0xffff;
|
|
|
|
+ p += 0x10000;
|
|
|
|
+
|
|
|
|
+ ret = mtd_read(master, offset + p, 4, &len, (void *)&magic);
|
|
|
|
+ if (ret || len != sizeof(magic))
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ if (magic == SQUASHFS_MAGIC)
|
|
|
|
+ part_size = p + 0x100;
|
|
|
|
+ else
|
|
|
|
+ part_size = mtd_pad_erasesize(master, offset, len);
|
|
|
|
+
|
2013-09-17 21:46:10 +00:00
|
|
|
+ if (part_size + master->erasesize > size)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ __mtd_add_partition(master, "rootfs", offset + part_size,
|
|
|
|
+ size - part_size, false);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void split_tplink_kernel(struct mtd_info *master, const char *name,
|
|
|
|
+ int offset, int size)
|
|
|
|
+{
|
|
|
|
+#define TPLINK_MAGIC 0x00000002
|
|
|
|
+ unsigned long magic = 0;
|
|
|
|
+ unsigned long part_size = 0;
|
|
|
|
+ size_t len;
|
|
|
|
+ int ret;
|
|
|
|
+
|
|
|
|
+ if (strcmp(name, CONFIG_MTD_SPLIT_FIRMWARE_NAME) != 0)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ ret = mtd_read(master, offset, 4, &len, (void *)&magic);
|
|
|
|
+ if (ret || len != sizeof(magic))
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ if (le32_to_cpu(magic) != TPLINK_MAGIC)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ ret = mtd_read(master, offset + 0x78, 4, &len, (void *)&part_size);
|
|
|
|
+ if (ret || len != sizeof(part_size))
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ part_size = be32_to_cpu(part_size) + 0x200;
|
|
|
|
+ if (part_size + master->erasesize > size)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ __mtd_add_partition(master, "rootfs", offset + part_size,
|
|
|
|
+ size - part_size, false);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void arch_split_mtd_part(struct mtd_info *master, const char *name,
|
|
|
|
+ int offset, int size)
|
|
|
|
+{
|
|
|
|
+ split_tplink_kernel(master, name, offset, size);
|
|
|
|
+ split_eva_kernel(master, name, offset, size);
|
|
|
|
+ split_brnimage_kernel(master, name, offset, size);
|
|
|
|
+}
|
2013-10-23 12:51:05 +00:00
|
|
|
--- a/include/linux/mtd/partitions.h
|
|
|
|
+++ b/include/linux/mtd/partitions.h
|
|
|
|
@@ -89,12 +89,17 @@ extern int deregister_mtd_parser(struct
|
2013-09-17 21:46:10 +00:00
|
|
|
int mtd_is_partition(const struct mtd_info *mtd);
|
|
|
|
int mtd_add_partition(struct mtd_info *master, char *name,
|
|
|
|
long long offset, long long length);
|
|
|
|
+int __mtd_add_partition(struct mtd_info *master, char *name,
|
|
|
|
+ long long offset, long long length, bool dup_check);
|
|
|
|
+
|
|
|
|
int mtd_del_partition(struct mtd_info *master, int partno);
|
2013-09-25 16:22:04 +00:00
|
|
|
struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd);
|
|
|
|
uint64_t mtdpart_get_offset(const struct mtd_info *mtd);
|
2013-09-17 21:46:10 +00:00
|
|
|
uint64_t mtd_get_device_size(const struct mtd_info *mtd);
|
|
|
|
-extern void __weak arch_split_mtd_part(struct mtd_info *master,
|
2013-09-25 16:22:04 +00:00
|
|
|
- const char *name, int offset, int size);
|
2013-09-17 21:46:10 +00:00
|
|
|
+void __weak arch_split_mtd_part(struct mtd_info *master,
|
2013-09-25 16:22:04 +00:00
|
|
|
+ const char *name, int offset, int size);
|
2013-09-17 21:46:10 +00:00
|
|
|
+unsigned long
|
|
|
|
+mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len);
|
|
|
|
|
2013-09-25 16:22:04 +00:00
|
|
|
int parse_mtd_partitions_by_type(struct mtd_info *master,
|
|
|
|
enum mtd_parser_type type,
|
2013-10-23 12:51:05 +00:00
|
|
|
--- a/drivers/mtd/mtdpart.c
|
|
|
|
+++ b/drivers/mtd/mtdpart.c
|
|
|
|
@@ -616,7 +616,7 @@ out_register:
|
2013-09-17 21:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-static int
|
|
|
|
+int
|
|
|
|
__mtd_add_partition(struct mtd_info *master, char *name,
|
|
|
|
long long offset, long long length, bool dup_check)
|
|
|
|
{
|
2013-10-23 12:51:05 +00:00
|
|
|
@@ -737,7 +737,7 @@ run_parsers_by_type(struct mtd_part *sla
|
2013-09-25 16:22:04 +00:00
|
|
|
return nr_parts;
|
2013-09-17 21:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-static inline unsigned long
|
|
|
|
+unsigned long
|
|
|
|
mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
|
|
|
|
{
|
|
|
|
unsigned long mask = mtd->erasesize - 1;
|
2013-10-23 12:51:05 +00:00
|
|
|
@@ -806,7 +806,6 @@ static void split_uimage(struct mtd_info
|
2013-09-17 21:46:10 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
len = be32_to_cpu(hdr.size) + 0x40;
|
|
|
|
- len = mtd_pad_erasesize(master, part->offset, len);
|
|
|
|
if (len + master->erasesize > part->mtd.size)
|
|
|
|
return;
|
|
|
|
|