From: Heiko Schocher Date: Wed, 25 May 2016 07:07:08 +0200 Subject: [U-Boot] [PATCH v1 3/7] nand: add nand mtd concat support In-Reply-To: <1464152832-11200-1-git-send-email-hs@denx.de> References: <1464152832-11200-1-git-send-email-hs@denx.de> Message-ID: <1464152832-11200-4-git-send-email-hs@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de add for nand devices mtd concat support. Generic MTD concat support is already ported to mainline, and used in the cfi_mtd driver. This patch adds it similiar for nand devices. Signed-off-by: Heiko Schocher --- drivers/mtd/nand/nand.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c index 8f0a921..5413123 100644 --- a/drivers/mtd/nand/nand.c +++ b/drivers/mtd/nand/nand.c @@ -9,6 +9,7 @@ #include #include #include +#include #ifndef CONFIG_SYS_NAND_BASE_LIST #define CONFIG_SYS_NAND_BASE_LIST { CONFIG_SYS_NAND_BASE } @@ -30,6 +31,12 @@ static char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8]; static unsigned long total_nand_size; /* in kiB */ +#ifdef CONFIG_MTD_CONCAT +static int nand_devices_found; +static struct mtd_info *mtd_nand_list[CONFIG_SYS_MAX_NAND_DEVICE]; +static char c_mtd_name[16]; +#endif + /* Register an initialized NAND mtd device with the U-Boot NAND command. */ int nand_register(int devnum) { @@ -49,6 +56,9 @@ int nand_register(int devnum) * via the mtdcore infrastructure (e.g. ubi). */ add_mtd_device(mtd); +#ifdef CONFIG_MTD_CONCAT + mtd_nand_list[nand_devices_found++] = mtd; +#endif #endif total_nand_size += mtd->size / 1024; @@ -102,4 +112,23 @@ void nand_init(void) */ board_nand_select_device(nand_info[nand_curr_device].priv, nand_curr_device); #endif + +#ifdef CONFIG_MTD_CONCAT + if (nand_devices_found > 1) { + struct mtd_info *mtd; + + /* + * We detected multiple devices. Concatenate them together. + */ + sprintf(c_mtd_name, "nand%d", nand_devices_found); + mtd = mtd_concat_create(mtd_nand_list, nand_devices_found, + c_mtd_name); + + if (mtd == NULL) + return; + + if (add_mtd_device(mtd)) + return; + } +#endif /* CONFIG_MTD_CONCAT */ } -- 2.5.5