From: Sean Anderson Date: Sat, 4 Nov 2023 20:37:50 +0000 (-0400) Subject: nand: Allow reinitialization X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=333d43f6a3e2aa1d6249d22211d77802614e37e5;p=u-boot.git nand: Allow reinitialization NAND devices are destroyed in between unit tests. Provide a function to reinitialize the subsystem at the beginning of each test. Signed-off-by: Sean Anderson Reviewed-by: Dario Binacchi --- diff --git a/drivers/mtd/nand/raw/nand.c b/drivers/mtd/nand/raw/nand.c index 80017b3ddd..4c18861aa2 100644 --- a/drivers/mtd/nand/raw/nand.c +++ b/drivers/mtd/nand/raw/nand.c @@ -115,6 +115,8 @@ static void nand_init_chip(int i) #endif #ifdef CONFIG_MTD_CONCAT +struct mtd_info *concat_mtd; + static void create_mtd_concat(void) { struct mtd_info *nand_info_list[CONFIG_SYS_MAX_NAND_DEVICE]; @@ -129,28 +131,40 @@ static void create_mtd_concat(void) } } 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_list, nand_devices_found, - c_mtd_name); + concat_mtd = mtd_concat_create(nand_info_list, + nand_devices_found, c_mtd_name); - if (mtd == NULL) + if (!concat_mtd) return; - nand_register(nand_devices_found, mtd); + nand_register(nand_devices_found, concat_mtd); } return; } + +static void destroy_mtd_concat(void) +{ + if (!concat_mtd) + return; + + mtd_concat_destroy(concat_mtd); + concat_mtd = NULL; +} #else static void create_mtd_concat(void) { } + +static void destroy_mtd_concat(void) +{ +} #endif unsigned long nand_size(void) @@ -158,10 +172,10 @@ unsigned long nand_size(void) return total_nand_size; } +static int initialized; + void nand_init(void) { - static int initialized; - /* * Avoid initializing NAND Flash multiple times, * otherwise it will calculate a wrong total size. @@ -190,6 +204,18 @@ void nand_init(void) create_mtd_concat(); } +void nand_reinit(void) +{ + int i; + + destroy_mtd_concat(); + for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) + assert(!nand_info[i]); + + initialized = 0; + nand_init(); +} + unsigned int nand_page_size(void) { struct mtd_info *mtd = get_nand_dev_by_index(nand_curr_device); diff --git a/include/nand.h b/include/nand.h index fc584f5ef7..220ffa202e 100644 --- a/include/nand.h +++ b/include/nand.h @@ -11,6 +11,7 @@ #include extern void nand_init(void); +void nand_reinit(void); unsigned long nand_size(void); unsigned int nand_page_size(void);