summaryrefslogtreecommitdiff
path: root/board/toradex/common/tdx-cfg-block.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/toradex/common/tdx-cfg-block.c')
-rw-r--r--board/toradex/common/tdx-cfg-block.c145
1 files changed, 105 insertions, 40 deletions
diff --git a/board/toradex/common/tdx-cfg-block.c b/board/toradex/common/tdx-cfg-block.c
index 9ab946970a..e454de9abe 100644
--- a/board/toradex/common/tdx-cfg-block.c
+++ b/board/toradex/common/tdx-cfg-block.c
@@ -1,14 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0+
/*
- * Copyright (c) 2016 Toradex, Inc.
- *
- * SPDX-License-Identifier: GPL-2.0+
+ * Copyright (c) 2016-2019 Toradex, Inc.
*/
#include <common.h>
#include "tdx-cfg-block.h"
-#if defined(CONFIG_TARGET_APALIS_IMX6) || defined(CONFIG_TARGET_COLIBRI_IMX6) \
- || defined(CONFIG_TARGET_APALIS_IMX8) || defined(CONFIG_TARGET_COLIBRI_IMX8QXP)
+#if defined(CONFIG_TARGET_APALIS_IMX6) || \
+ defined(CONFIG_TARGET_APALIS_IMX8) || \
+ defined(CONFIG_TARGET_COLIBRI_IMX6) || \
+ defined(CONFIG_TARGET_COLIBRI_IMX8QXP)
#include <asm/arch/sys_proto.h>
#else
#define is_cpu_type(cpu) (0)
@@ -94,12 +95,22 @@ const char * const toradex_modules[] = {
[34] = "Apalis TK1 2GB",
[35] = "Apalis iMX6 Dual 1GB IT",
[36] = "Colibri iMX6ULL 256MB",
- [37] = "Apalis iMX8 QuadMax 4GB Wi-Fi / Bluetooth",
- [38] = "Colibri iMX8QXP 2GB WB IT",
+ [37] = "Apalis iMX8 QuadMax 4GB Wi-Fi / BT IT",
+ [38] = "Colibri iMX8 QuadXPlus 2GB Wi-Fi / BT IT",
[39] = "Colibri iMX7 Dual 1GB (eMMC)",
- [40] = "Colibri iMX6ULL 512MB Wi-Fi / Bluetooth IT",
+ [40] = "Colibri iMX6ULL 512MB Wi-Fi / BT IT",
[41] = "Colibri iMX7 Dual 512MB EPDC",
[42] = "Apalis TK1 4GB",
+ [43] = "Colibri T20 512MB IT SETEK",
+ [44] = "Colibri iMX6ULL 512MB IT",
+ [45] = "Colibri iMX6ULL 512MB Wi-Fi / Bluetooth",
+ [46] = "Apalis iMX8 QuadXPlus 2GB Wi-Fi / BT IT",
+ [47] = "Apalis iMX8 QuadMax 4GB IT",
+ [48] = "Apalis iMX8 QuadPlus 2GB Wi-Fi / BT",
+ [49] = "Apalis iMX8 QuadPlus 2GB",
+ [50] = "Colibri iMX8 QuadXPlus 2GB IT",
+ [51] = "Colibri iMX8 DualX 1GB Wi-Fi / Bluetooth",
+ [52] = "Colibri iMX8 DualX 1GB",
};
#ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_MMC
@@ -162,10 +173,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);
}
@@ -264,7 +278,7 @@ int read_tdx_cfg_block(void)
}
/* Cap product id to avoid issues with a yet unknown one */
- if (tdx_hw_tag.prodid > (sizeof(toradex_modules) /
+ if (tdx_hw_tag.prodid >= (sizeof(toradex_modules) /
sizeof(toradex_modules[0])))
tdx_hw_tag.prodid = 0;
@@ -278,49 +292,95 @@ static int get_cfgblock_interactive(void)
char message[CONFIG_SYS_CBSIZE];
char *soc;
char it = 'n';
+ char wb = 'n';
int len;
+ /* Unknown module by default */
+ tdx_hw_tag.prodid = 0;
+
if (cpu_is_pxa27x())
sprintf(message, "Is the module the 312 MHz version? [y/N] ");
else
sprintf(message, "Is the module an IT version? [y/N] ");
-
len = cli_readline(message);
it = console_buffer[0];
+#if defined(CONFIG_TARGET_APALIS_IMX8) || \
+ defined(CONFIG_TARGET_COLIBRI_IMX6ULL) || \
+ defined(CONFIG_TARGET_COLIBRI_IMX8X)
+ sprintf(message, "Does the module have Wi-Fi / Bluetooth? " \
+ "[y/N] ");
+ len = cli_readline(message);
+ wb = console_buffer[0];
+#endif
+
soc = env_get("soc");
if (!strcmp("mx6", soc)) {
-#ifdef CONFIG_MACH_TYPE
- if (it == 'y' || it == 'Y')
+#ifdef CONFIG_TARGET_APALIS_IMX6
+ if (it == 'y' || it == 'Y') {
if (is_cpu_type(MXC_CPU_MX6Q))
tdx_hw_tag.prodid = APALIS_IMX6Q_IT;
else
tdx_hw_tag.prodid = APALIS_IMX6D_IT;
- else
+ } else {
if (is_cpu_type(MXC_CPU_MX6Q))
tdx_hw_tag.prodid = APALIS_IMX6Q;
else
tdx_hw_tag.prodid = APALIS_IMX6D;
-#else
- if (it == 'y' || it == 'Y')
+ }
+#elif CONFIG_TARGET_COLIBRI_IMX6
+ if (it == 'y' || it == 'Y') {
if (is_cpu_type(MXC_CPU_MX6DL))
tdx_hw_tag.prodid = COLIBRI_IMX6DL_IT;
else if (is_cpu_type(MXC_CPU_MX6SOLO))
tdx_hw_tag.prodid = COLIBRI_IMX6S_IT;
- else
- tdx_hw_tag.prodid = COLIBRI_IMX6ULL_WIFI_BT_IT;
- else
+ } else {
if (is_cpu_type(MXC_CPU_MX6DL))
tdx_hw_tag.prodid = COLIBRI_IMX6DL;
else if (is_cpu_type(MXC_CPU_MX6SOLO))
tdx_hw_tag.prodid = COLIBRI_IMX6S;
+ }
+#elif CONFIG_TARGET_COLIBRI_IMX6ULL
+ if (it == 'y' || it == 'Y') {
+ if (wb == 'y' || wb == 'Y')
+ tdx_hw_tag.prodid = COLIBRI_IMX6ULL_WIFI_BT_IT;
+ else
+ tdx_hw_tag.prodid = COLIBRI_IMX6ULL_IT;
+ } else {
+ if (wb == 'y' || wb == 'Y')
+ tdx_hw_tag.prodid = COLIBRI_IMX6ULL_WIFI_BT;
else
tdx_hw_tag.prodid = COLIBRI_IMX6ULL;
-#endif /* CONFIG_MACH_TYPE */
- } else if (!strcmp("imx7d", soc)) {
+ }
+#endif
+ } else if (!strcmp("imx7d", soc))
tdx_hw_tag.prodid = COLIBRI_IMX7D;
- } else if (!strcmp("imx7s", soc)) {
+ else if (!strcmp("imx7s", soc))
tdx_hw_tag.prodid = COLIBRI_IMX7S;
+ else if (is_cpu_type(MXC_CPU_IMX8QM)) {
+ if (it == 'y' || it == 'Y') {
+ if (wb == 'y' || wb == 'Y')
+ tdx_hw_tag.prodid = APALIS_IMX8QM_WIFI_BT_IT;
+ else
+ tdx_hw_tag.prodid = APALIS_IMX8QM_IT;
+ } else {
+ if (wb == 'y' || wb == 'Y')
+ tdx_hw_tag.prodid = APALIS_IMX8QP_WIFI_BT;
+ else
+ tdx_hw_tag.prodid = APALIS_IMX8QP;
+ }
+ } else if (is_cpu_type(MXC_CPU_IMX8QXP)) {
+ if (it == 'y' || it == 'Y') {
+ if (wb == 'y' || wb == 'Y')
+ tdx_hw_tag.prodid = COLIBRI_IMX8QXP_WIFI_BT_IT;
+ else
+ tdx_hw_tag.prodid = COLIBRI_IMX8QXP_IT;
+ } else {
+ if (wb == 'y' || wb == 'Y')
+ tdx_hw_tag.prodid = COLIBRI_IMX8DX_WIFI_BT;
+ else
+ tdx_hw_tag.prodid = COLIBRI_IMX8DX;
+ }
} else if (!strcmp("tegra20", soc)) {
if (it == 'y' || it == 'Y')
if (gd->ram_size == 0x10000000)
@@ -337,8 +397,9 @@ static int get_cfgblock_interactive(void)
tdx_hw_tag.prodid = COLIBRI_PXA270_312MHZ;
else
tdx_hw_tag.prodid = COLIBRI_PXA270_520MHZ;
+ }
#ifdef CONFIG_MACH_TYPE
- } else if (!strcmp("tegra30", soc)) {
+ else if (!strcmp("tegra30", soc)) {
if (CONFIG_MACH_TYPE == MACH_TYPE_APALIS_T30) {
if (it == 'y' || it == 'Y')
tdx_hw_tag.prodid = APALIS_T30_IT;
@@ -353,8 +414,9 @@ static int get_cfgblock_interactive(void)
else
tdx_hw_tag.prodid = COLIBRI_T30;
}
+ }
#endif /* CONFIG_MACH_TYPE */
- } else if (!strcmp("tegra124", soc)) {
+ else if (!strcmp("tegra124", soc)) {
tdx_hw_tag.prodid = APALIS_TK1_2GB;
} else if (!strcmp("vf500", soc)) {
if (it == 'y' || it == 'Y')
@@ -366,11 +428,9 @@ static int get_cfgblock_interactive(void)
tdx_hw_tag.prodid = COLIBRI_VF61_IT;
else
tdx_hw_tag.prodid = COLIBRI_VF61;
- } else if (is_cpu_type(MXC_CPU_IMX8QM)) {
- tdx_hw_tag.prodid = APALIS_IMX8QM;
- } else if (is_cpu_type(MXC_CPU_IMX8QXP)) {
- tdx_hw_tag.prodid = COLIBRI_IMX8X;
- } else {
+ }
+
+ if (!tdx_hw_tag.prodid) {
printf("Module type not detectable due to unknown SoC\n");
return -1;
}
@@ -384,7 +444,7 @@ static int get_cfgblock_interactive(void)
tdx_hw_tag.ver_minor = console_buffer[2] - '0';
tdx_hw_tag.ver_assembly = console_buffer[3] - 'A';
- if (cpu_is_pxa27x() && (tdx_hw_tag.ver_major == 1))
+ if (cpu_is_pxa27x() && tdx_hw_tag.ver_major == 1)
tdx_hw_tag.prodid -= (COLIBRI_PXA270_312MHZ -
COLIBRI_PXA270_V1_312MHZ);
@@ -443,7 +503,7 @@ static int do_cfgblock_create(cmd_tbl_t *cmdtp, int flag, int argc,
if (argc >= 3) {
if (argv[2][0] == '-' && argv[2][1] == 'y')
force_overwrite = 1;
- }
+ }
read_tdx_cfg_block();
if (valid_cfgblock) {
@@ -452,7 +512,8 @@ static int do_cfgblock_create(cmd_tbl_t *cmdtp, int flag, int argc,
* On NAND devices, recreation is only allowed if the page is
* empty (config block invalid...)
*/
- printf("NAND erase block %d need to be erased before creating a Toradex config block\n",
+ printf("NAND erase block %d need to be erased before creating" \
+ " a Toradex config block\n",
CONFIG_TDX_CFG_BLOCK_OFFSET /
get_nand_dev_by_index(0)->erasesize);
goto out;
@@ -461,28 +522,32 @@ static int do_cfgblock_create(cmd_tbl_t *cmdtp, int flag, int argc,
* On NOR devices, recreation is only allowed if the sector is
* empty and write protection is off (config block invalid...)
*/
- printf("NOR sector at offset 0x%02x need to be erased and unprotected before creating a Toradex config block\n",
+ printf("NOR sector at offset 0x%02x need to be erased and " \
+ "unprotected before creating a Toradex config block\n",
CONFIG_TDX_CFG_BLOCK_OFFSET);
goto out;
#else
- if (!force_overwrite) {
+ if (!force_overwrite) {
char message[CONFIG_SYS_CBSIZE];
+
sprintf(message,
- "A valid Toradex config block is present, still recreate? [y/N] ");
+ "A valid Toradex config block is present, " \
+ "still recreate? [y/N] ");
if (!cli_readline(message))
goto out;
- if (console_buffer[0] != 'y' && console_buffer[0] != 'Y')
+ if (console_buffer[0] != 'y' &&
+ console_buffer[0] != 'Y')
goto out;
- }
+ }
#endif
}
/* Parse new Toradex config block data... */
- if (argc < 3 || (force_overwrite && argc < 4))
+ if (argc < 3 || (force_overwrite && argc < 4)) {
err = get_cfgblock_interactive();
- else {
+ } else {
if (force_overwrite)
err = get_cfgblock_barcode(argv[3]);
else