ar71xx: add size depend partition generation

Partitions are generated depending on the size of the flash chip.
The layout on which the partition based is hardcoded into the module.
Using this new partition layout it makes possible to have 8mb and 16mb within
the same board definition.
This commit is contained in:
Alexander Couzens 2015-05-19 14:18:09 +02:00
parent acd543359d
commit 5f90cba27a
3 changed files with 158 additions and 1 deletions

View File

@ -297,3 +297,4 @@ CONFIG_UIDGID_CONVERTED=y
CONFIG_USB_ARCH_HAS_XHCI=y
CONFIG_USB_SUPPORT=y
CONFIG_ZONE_DMA_FLAG=0
CONFIG_MTD_SIZE_DEPEND_PARTS=y

View File

@ -42,6 +42,16 @@
#define SYSMOCOM_CALDATA_OFFSET 0x1000
#define SYSMOCOM_WMAC_MAC_OFFSET 0x1002
static const char *size_depend_part_probes[] = {
"SizeDepend",
NULL,
};
static struct flash_platform_data size_depend_flash_data = {
.part_probes = size_depend_part_probes,
};
static struct gpio_led sysmocom_sob_ap1_leds_gpio[] __initdata = {
{
.name = "sysmocom:orange:wlan",
@ -130,7 +140,7 @@ static struct i2c_board_info sob_ap_i2c_devs[] __initdata = {
static void __init sysmocom_common_setup(void)
{
ath79_register_m25p80(NULL);
ath79_register_m25p80(&size_depend_flash_data);
}
static void __init sysmocom_sob_ap1_setup(void)

View File

@ -0,0 +1,146 @@
Index: linux-3.10.49/drivers/mtd/Kconfig
===================================================================
--- linux-3.10.49.orig/drivers/mtd/Kconfig
+++ linux-3.10.49/drivers/mtd/Kconfig
@@ -80,6 +80,13 @@ config MTD_TESTS
WARNING: some of the tests will ERASE entire MTD device which they
test. Do not use these tests unless you really know what you do.
+config MTD_SIZE_DEPEND_PARTS
+ bool "Size depended partition generator (hardcoded)"
+ def_bool n
+ help
+ Generate a flash chip size depended partition layout. The layout itself
+ is hardcoded
+
config MTD_REDBOOT_PARTS
tristate "RedBoot partition table parsing"
---help---
Index: linux-3.10.49/drivers/mtd/Makefile
===================================================================
--- linux-3.10.49.orig/drivers/mtd/Makefile
+++ linux-3.10.49/drivers/mtd/Makefile
@@ -13,6 +13,7 @@ mtd-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtd
mtd-$(CONFIG_MTD_SPLIT_LZMA_FW) += mtdsplit_lzma.o
obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
+obj-$(CONFIG_MTD_SIZE_DEPEND_PARTS) += size_depend.o
obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o
obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
Index: linux-3.10.49/drivers/mtd/size_depend.c
===================================================================
--- /dev/null
+++ linux-3.10.49/drivers/mtd/size_depend.c
@@ -0,0 +1,111 @@
+/*
+ * Generate a mtd partition table based on the flash
+ * produce (hardcoded) layout.
+ *
+ * Copyright © 2015 Alexander Couzens <lynxis@fe80.eu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/vmalloc.h>
+
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/module.h>
+#include <linux/err.h>
+
+static int parse_size_depend_partitions(struct mtd_info *master,
+ struct mtd_partition **pparts,
+ struct mtd_part_parser_data *data)
+{
+ /* 256k for "uboot" at the beginning
+ * space between for "firmware"
+ * 64k for "art" (calibration) data at the end
+ */
+ int nrparts;
+ int namelen;
+ struct mtd_partition *parts;
+ char *name;
+
+ printk(KERN_INFO "size_depend: generating mtd layout\n");
+ /* +1 for \0 bytes */
+ namelen = strlen("firmware") + 1
+ + strlen("u-boot") + 1
+ + strlen("u-boot-env") + 1
+ + strlen("art") + 1;
+
+ nrparts = 4;
+
+ parts = kzalloc(sizeof(*parts)*nrparts + namelen, GFP_KERNEL);
+ if (!parts)
+ return ERR_PTR(-ENOMEM);
+
+ name = (char *) &parts[nrparts];
+
+ parts[0].name = name;
+ parts[0].size = 256 * 1024;
+ parts[0].offset = 0;
+ parts[0].mask_flags |= MTD_WRITEABLE;
+ strlcpy(name, "u-boot", strlen("u-boot") + 1);
+ name += strlen("u-boot") + 1;
+
+ parts[1].name = name;
+ parts[1].size = 64 * 1024;
+ parts[1].offset = 256 * 1024;
+ strlcpy(name, "u-boot-env", strlen("u-boot-env") + 1);
+ name += strlen("u-boot-env") + 1;
+
+ parts[2].name = name;
+ parts[2].size = mtd_get_device_size(master) - ((320 * 1024) + (64 * 1024));
+ parts[2].offset = 320 * 1024;
+ strlcpy(name, "firmware", strlen("firmware") + 1);
+ name += strlen("firmware") + 1;
+
+ parts[3].name = name;
+ parts[3].size = 64 * 1024;
+ parts[3].offset = mtd_get_device_size(master) - (64 * 1024);
+ parts[3].mask_flags |= MTD_WRITEABLE;
+ strlcpy(name, "art", strlen("art") + 1);
+
+ *pparts = parts;
+
+ return nrparts;
+}
+
+static struct mtd_part_parser size_depend_parser = {
+ .owner = THIS_MODULE,
+ .parse_fn = parse_size_depend_partitions,
+ .name = "SizeDepend",
+};
+
+/* mtd parsers will request the module by parser name */
+MODULE_ALIAS("SizeDepend");
+
+static int __init size_depend_parser_init(void)
+{
+ return register_mtd_parser(&size_depend_parser);
+}
+
+static void __exit size_depend_parser_exit(void)
+{
+ deregister_mtd_parser(&size_depend_parser);
+}
+
+module_init(size_depend_parser_init);
+module_exit(size_depend_parser_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Alexander Couzens <lynxis@fe80.eu>");
+MODULE_DESCRIPTION("Choose a partition table based on flash size");