]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
nand: Allow reinitialization
authorSean Anderson <seanga2@gmail.com>
Sat, 4 Nov 2023 20:37:50 +0000 (16:37 -0400)
committerTom Rini <trini@konsulko.com>
Thu, 16 Nov 2023 17:43:49 +0000 (12:43 -0500)
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 <seanga2@gmail.com>
Reviewed-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
drivers/mtd/nand/raw/nand.c
include/nand.h

index 80017b3dddd62f901334041a54fcd8986919c61a..4c18861aa25a6e6dd428ed3894f2f9295edfd9e7 100644 (file)
@@ -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);
index fc584f5ef7aeb8456f58963ae748576ef29d0ff7..220ffa202ef93436dfa3cd9d1b1ba72f70be5841 100644 (file)
@@ -11,6 +11,7 @@
 #include <config.h>
 
 extern void nand_init(void);
+void nand_reinit(void);
 unsigned long nand_size(void);
 unsigned int nand_page_size(void);