Message ID | 1464696492-10349-4-git-send-email-hs@denx.de |
---|---|
State | Superseded |
Delegated to: | Tom Rini |
Headers | show |
On Tue, 2016-05-31 at 14:08 +0200, Heiko Schocher wrote: > @@ -59,6 +64,9 @@ int nand_register(int devnum, struct mtd_info *mtd) > * via the mtdcore infrastructure (e.g. ubi). > */ > add_mtd_device(mtd); > +#ifdef CONFIG_MTD_CONCAT > + nand_devices_found++; > +#endif > #endif [snip] > + sprintf(c_mtd_name, "nand%d", nand_devices_found); > + mtd = mtd_concat_create(nand_info, nand_devices_found, > + c_mtd_name); This assumes that there are no gaps in the NAND numbering (e.g. because some device was optional or failed to init). It would be better to build an array by scanning nand_info[] for non-NULL devices. -SCott
Hello Scott, Am 02.06.2016 um 02:09 schrieb Scott Wood: > On Tue, 2016-05-31 at 14:08 +0200, Heiko Schocher wrote: >> @@ -59,6 +64,9 @@ int nand_register(int devnum, struct mtd_info *mtd) >> * via the mtdcore infrastructure (e.g. ubi). >> */ >> add_mtd_device(mtd); >> +#ifdef CONFIG_MTD_CONCAT >> + nand_devices_found++; >> +#endif >> #endif > [snip] >> + sprintf(c_mtd_name, "nand%d", nand_devices_found); >> + mtd = mtd_concat_create(nand_info, nand_devices_found, >> + c_mtd_name); > > This assumes that there are no gaps in the NAND numbering (e.g. because some > device was optional or failed to init). It would be better to build an array > by scanning nand_info[] for non-NULL devices. Yes, you are right ... Hmm... thinking about it ... this did exactly my v1 ... I created such an array "mtd_nand_list" ... Ok, this "mtd_nand_list" was a variable in file scope ... but as it is an array of pointers, the mem footprint is not so big ... but if you find it better to scan nand_info and create a new array on stack, I can do this ... what way do you preffer? bye, Heiko
On Thu, 2016-06-02 at 07:02 +0200, Heiko Schocher wrote: > Hello Scott, > > Am 02.06.2016 um 02:09 schrieb Scott Wood: > > On Tue, 2016-05-31 at 14:08 +0200, Heiko Schocher wrote: > > > @@ -59,6 +64,9 @@ int nand_register(int devnum, struct mtd_info *mtd) > > > * via the mtdcore infrastructure (e.g. ubi). > > > */ > > > add_mtd_device(mtd); > > > +#ifdef CONFIG_MTD_CONCAT > > > + nand_devices_found++; > > > +#endif > > > #endif > > [snip] > > > + sprintf(c_mtd_name, "nand%d", nand_devices_found); > > > + mtd = mtd_concat_create(nand_info, nand_devices_found, > > > + c_mtd_name); > > > > This assumes that there are no gaps in the NAND numbering (e.g. because > > some > > device was optional or failed to init). It would be better to build an > > array > > by scanning nand_info[] for non-NULL devices. > > Yes, you are right ... Hmm... thinking about it ... this did exactly > my v1 ... I created such an array "mtd_nand_list" ... Ok, this > "mtd_nand_list" was a variable in file scope ... but as it is an array > of pointers, the mem footprint is not so big ... My concern was code organization, not (just) footprint. > but if you find it > better to scan nand_info and create a new array on stack, I can do > this ... what way do you preffer? On the stack. -Scott
diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c index f449316..95ee37b 100644 --- a/drivers/mtd/nand/nand.c +++ b/drivers/mtd/nand/nand.c @@ -9,6 +9,7 @@ #include <common.h> #include <nand.h> #include <errno.h> +#include <linux/mtd/concat.h> #ifndef CONFIG_SYS_NAND_BASE_LIST #define CONFIG_SYS_NAND_BASE_LIST { CONFIG_SYS_NAND_BASE } @@ -30,6 +31,10 @@ 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; +#endif + int nand_mtd_to_devnum(struct mtd_info *mtd) { int i; @@ -59,6 +64,9 @@ int nand_register(int devnum, struct mtd_info *mtd) * via the mtdcore infrastructure (e.g. ubi). */ add_mtd_device(mtd); +#ifdef CONFIG_MTD_CONCAT + nand_devices_found++; +#endif #endif total_nand_size += mtd->size / 1024; @@ -112,4 +120,23 @@ void nand_init(void) board_nand_select_device(mtd_to_nand(nand_info[nand_curr_device]), nand_curr_device); #endif + +#ifdef CONFIG_MTD_CONCAT + if (nand_devices_found > 1) { + struct mtd_info *mtd; + char c_mtd_name[16]; + + /* + * We detected multiple devices. Concatenate them together. + */ + sprintf(c_mtd_name, "nand%d", nand_devices_found); + mtd = mtd_concat_create(nand_info, nand_devices_found, + c_mtd_name); + + if (mtd == NULL) + return; + + nand_register(nand_devices_found, mtd); + } +#endif /* CONFIG_MTD_CONCAT */ }
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 <hs@denx.de> --- Changes in v2: - add comments from Scott Wood: - move c_mtd_name from file scope to local - use nand_info instead mtd_nand_list - use oss@buserror.net as email address for Scott - rebase to current mainline commit id: e4a94ce4ac77396b181663c0493c50bc2d5b9143 and the "mtd: nand Sync with Linux v4.6" patches: [U-Boot,1/7] mtd: nand: Remove jz4740 driver http://patchwork.ozlabs.org/patch/627922/ [U-Boot,2/7] mtd: nand: Remove docg4 driver and palmtreo680 flashing tool http://patchwork.ozlabs.org/patch/627924/ [U-Boot,3/7] mtd: nand: Remove nand_info_t typedef http://patchwork.ozlabs.org/patch/627923/ [U-Boot,4/7] nand: Embed mtd_info in struct nand_chip http://patchwork.ozlabs.org/patch/627925/ [U-Boot,5/7] mtd: nand: Add+use mtd_to/from_nand and nand_get/set_controller_data http://patchwork.ozlabs.org/patch/627926/ [U-Boot,6/7] mtd: nand: Add page argument to write_page() etc. http://patchwork.ozlabs.org/patch/627927/ [U-Boot,7/7] mtd: nand: Sync with Linux v4.6 http://patchwork.ozlabs.org/patch/627928/ drivers/mtd/nand/nand.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)