]> git.ipfire.org Git - thirdparty/u-boot.git/blobdiff - board/toradex/common/tdx-cfg-block.c
toradex: configblock: add an -y parameter to 'cfgblock create’
[thirdparty/u-boot.git] / board / toradex / common / tdx-cfg-block.c
index f6231ff2f9968713a24d2420ac8c8c735234de56..2fcb998ae44ea4741804b72879ee7ce0e081582e 100644 (file)
@@ -91,6 +91,13 @@ const char * const toradex_modules[] = {
        [33] = "Colibri iMX7 Dual 512MB",
        [34] = "Apalis TK1 2GB",
        [35] = "Apalis iMX6 Dual 1GB IT",
+       [36] = "Colibri iMX6ULL 256MB",
+       [37] = "Apalis iMX8 QuadMax 4GB Wi-Fi / Bluetooth",
+       [38] = "Colibri iMX8X",
+       [39] = "Colibri iMX7 Dual 1GB (eMMC)",
+       [40] = "Colibri iMX6ULL 512MB Wi-Fi / Bluetooth IT",
+       [41] = "Colibri iMX7 Dual 512MB EPDC",
+       [42] = "Apalis TK1 4GB",
 };
 
 #ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_MMC
@@ -149,10 +156,13 @@ out:
 static int read_tdx_cfg_block_from_nand(unsigned char *config_block)
 {
        size_t size = TDX_CFG_BLOCK_MAX_SIZE;
+       struct mtd_info *mtd = get_nand_dev_by_index(0);
+
+       if (!mtd)
+               return -ENODEV;
 
        /* Read production parameter config block from NAND page */
-       return nand_read_skip_bad(get_nand_dev_by_index(0),
-                                 CONFIG_TDX_CFG_BLOCK_OFFSET,
+       return nand_read_skip_bad(mtd, CONFIG_TDX_CFG_BLOCK_OFFSET,
                                  &size, NULL, TDX_CFG_BLOCK_MAX_SIZE,
                                  config_block);
 }
@@ -408,6 +418,7 @@ static int do_cfgblock_create(cmd_tbl_t *cmdtp, int flag, int argc,
        int offset = 0;
        int ret = CMD_RET_SUCCESS;
        int err;
+       int force_overwrite = 0;
 
        /* Allocate RAM area for config block */
        config_block = memalign(ARCH_DMA_MINALIGN, size);
@@ -418,6 +429,11 @@ static int do_cfgblock_create(cmd_tbl_t *cmdtp, int flag, int argc,
 
        memset(config_block, 0xff, size);
 
+       if (argc >= 3) {
+               if (argv[2][0] == '-' && argv[2][1] == 'y')
+                       force_overwrite = 1;
+       }
+
        read_tdx_cfg_block();
        if (valid_cfgblock) {
 #if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND)
@@ -438,24 +454,31 @@ static int do_cfgblock_create(cmd_tbl_t *cmdtp, int flag, int argc,
                       CONFIG_TDX_CFG_BLOCK_OFFSET);
                goto out;
 #else
-               char message[CONFIG_SYS_CBSIZE];
-               sprintf(message,
-                       "A valid Toradex config block is present, still recreate? [y/N] ");
+               if (!force_overwrite) {
+                       char message[CONFIG_SYS_CBSIZE];
 
-               if (!cli_readline(message))
-                       goto out;
+                       sprintf(message,
+                               "A valid Toradex config block is present, still recreate? [y/N] ");
 
-               if (console_buffer[0] != 'y' && console_buffer[0] != 'Y')
-                       goto out;
+                       if (!cli_readline(message))
+                               goto out;
+
+                       if (console_buffer[0] != 'y' &&
+                           console_buffer[0] != 'Y')
+                               goto out;
+               }
 #endif
        }
 
        /* Parse new Toradex config block data... */
-       if (argc < 3)
+       if (argc < 3 || (force_overwrite && argc < 4)) {
                err = get_cfgblock_interactive();
-       else
-               err = get_cfgblock_barcode(argv[2]);
-
+       } else {
+               if (force_overwrite)
+                       err = get_cfgblock_barcode(argv[3]);
+               else
+                       err = get_cfgblock_barcode(argv[2]);
+       }
        if (err) {
                ret = CMD_RET_FAILURE;
                goto out;
@@ -539,8 +562,8 @@ static int do_cfgblock(cmd_tbl_t *cmdtp, int flag, int argc,
 }
 
 U_BOOT_CMD(
-       cfgblock, 3, 0, do_cfgblock,
+       cfgblock, 4, 0, do_cfgblock,
        "Toradex config block handling commands",
-       "create [barcode] - (Re-)create Toradex config block\n"
+       "create [-y] [barcode] - (Re-)create Toradex config block\n"
        "cfgblock reload - Reload Toradex config block from flash"
 );