]> 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 68ec4369ad7e01ae11d987adca77679f8790b474..2fcb998ae44ea4741804b72879ee7ce0e081582e 100644 (file)
@@ -1,7 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2016 Toradex, Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -92,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
@@ -129,8 +135,6 @@ static int tdx_cfg_block_mmc_storage(u8 *config_block, int write)
                        ret = -EIO;
                        goto out;
                }
-               /* Flush cache after read */
-               flush_cache((ulong)(unsigned char *)config_block, 512);
        } else {
                /* Just writing one 512 byte block */
                if (blk_dwrite(mmc_get_blk_desc(mmc), blk_start, 1,
@@ -152,10 +156,15 @@ 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(nand_info[0], CONFIG_TDX_CFG_BLOCK_OFFSET,
-                        &size, NULL, TDX_CFG_BLOCK_MAX_SIZE, config_block);
+       return nand_read_skip_bad(mtd, CONFIG_TDX_CFG_BLOCK_OFFSET,
+                                 &size, NULL, TDX_CFG_BLOCK_MAX_SIZE,
+                                 config_block);
 }
 
 static int write_tdx_cfg_block_to_nand(unsigned char *config_block)
@@ -163,7 +172,8 @@ static int write_tdx_cfg_block_to_nand(unsigned char *config_block)
        size_t size = TDX_CFG_BLOCK_MAX_SIZE;
 
        /* Write production parameter config block to NAND page */
-       return nand_write_skip_bad(nand_info[0], CONFIG_TDX_CFG_BLOCK_OFFSET,
+       return nand_write_skip_bad(get_nand_dev_by_index(0),
+                                  CONFIG_TDX_CFG_BLOCK_OFFSET,
                                   &size, NULL, TDX_CFG_BLOCK_MAX_SIZE,
                                   config_block, WITH_WR_VERIFY);
 }
@@ -275,7 +285,7 @@ static int get_cfgblock_interactive(void)
        len = cli_readline(message);
        it = console_buffer[0];
 
-       soc = getenv("soc");
+       soc = env_get("soc");
        if (!strcmp("mx6", soc)) {
 #ifdef CONFIG_MACH_TYPE
                if (it == 'y' || it == 'Y')
@@ -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)
@@ -426,7 +442,8 @@ static int do_cfgblock_create(cmd_tbl_t *cmdtp, int flag, int argc,
                 * empty (config block invalid...)
                 */
                printf("NAND erase block %d need to be erased before creating a Toradex config block\n",
-                      CONFIG_TDX_CFG_BLOCK_OFFSET / nand_info[0]->erasesize);
+                      CONFIG_TDX_CFG_BLOCK_OFFSET /
+                      get_nand_dev_by_index(0)->erasesize);
                goto out;
 #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR)
                /*
@@ -437,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;
@@ -538,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"
 );