Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 2 | /* |
Marcel Ziswiler | 75b9327 | 2020-01-28 14:42:23 +0100 | [diff] [blame] | 3 | * Copyright (c) 2016-2020 Toradex |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 7 | #include <asm/global_data.h> |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 8 | #include "tdx-cfg-block.h" |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 9 | #include "tdx-eeprom.h" |
| 10 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 11 | #include <command.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 12 | #include <asm/cache.h> |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 13 | |
Marcel Ziswiler | 2658c8e | 2019-04-09 17:25:32 +0200 | [diff] [blame] | 14 | #if defined(CONFIG_TARGET_APALIS_IMX6) || \ |
Marcel Ziswiler | 0032061 | 2019-07-12 12:35:08 +0200 | [diff] [blame] | 15 | defined(CONFIG_TARGET_APALIS_IMX8) || \ |
Marcel Ziswiler | 2658c8e | 2019-04-09 17:25:32 +0200 | [diff] [blame] | 16 | defined(CONFIG_TARGET_COLIBRI_IMX6) || \ |
Marcel Ziswiler | eca26ba | 2020-01-28 14:42:24 +0100 | [diff] [blame] | 17 | defined(CONFIG_TARGET_COLIBRI_IMX8X) || \ |
| 18 | defined(CONFIG_TARGET_VERDIN_IMX8MM) || \ |
Marcel Ziswiler | 4a9c702 | 2020-10-28 11:58:08 +0200 | [diff] [blame] | 19 | defined(CONFIG_TARGET_VERDIN_IMX8MN) || \ |
| 20 | defined(CONFIG_TARGET_VERDIN_IMX8MP) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 21 | #include <asm/arch/sys_proto.h> |
| 22 | #else |
| 23 | #define is_cpu_type(cpu) (0) |
| 24 | #endif |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 25 | #include <cli.h> |
| 26 | #include <console.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 27 | #include <env.h> |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 28 | #include <flash.h> |
| 29 | #include <malloc.h> |
| 30 | #include <mmc.h> |
| 31 | #include <nand.h> |
Simon Glass | 0ffb9d6 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 32 | #include <asm/mach-types.h> |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
| 36 | #define TAG_VALID 0xcf01 |
| 37 | #define TAG_MAC 0x0000 |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 38 | #define TAG_CAR_SERIAL 0x0021 |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 39 | #define TAG_HW 0x0008 |
| 40 | #define TAG_INVALID 0xffff |
| 41 | |
| 42 | #define TAG_FLAG_VALID 0x1 |
| 43 | |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 44 | #define TDX_EEPROM_ID_MODULE 0 |
| 45 | #define TDX_EEPROM_ID_CARRIER 1 |
| 46 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 47 | #if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_MMC) |
| 48 | #define TDX_CFG_BLOCK_MAX_SIZE 512 |
| 49 | #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND) |
| 50 | #define TDX_CFG_BLOCK_MAX_SIZE 64 |
| 51 | #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR) |
| 52 | #define TDX_CFG_BLOCK_MAX_SIZE 64 |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 53 | #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_EEPROM) |
| 54 | #define TDX_CFG_BLOCK_MAX_SIZE 64 |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 55 | #else |
| 56 | #error Toradex config block location not set |
| 57 | #endif |
| 58 | |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 59 | #ifdef CONFIG_TDX_CFG_BLOCK_EXTRA |
| 60 | #define TDX_CFG_BLOCK_EXTRA_MAX_SIZE 64 |
| 61 | #endif |
| 62 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 63 | struct toradex_tag { |
| 64 | u32 len:14; |
| 65 | u32 flags:2; |
| 66 | u32 id:16; |
| 67 | }; |
| 68 | |
| 69 | bool valid_cfgblock; |
| 70 | struct toradex_hw tdx_hw_tag; |
| 71 | struct toradex_eth_addr tdx_eth_addr; |
| 72 | u32 tdx_serial; |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 73 | #ifdef CONFIG_TDX_CFG_BLOCK_EXTRA |
| 74 | u32 tdx_car_serial; |
| 75 | bool valid_cfgblock_carrier; |
| 76 | struct toradex_hw tdx_car_hw_tag; |
| 77 | #endif |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 78 | |
| 79 | const char * const toradex_modules[] = { |
| 80 | [0] = "UNKNOWN MODULE", |
| 81 | [1] = "Colibri PXA270 312MHz", |
| 82 | [2] = "Colibri PXA270 520MHz", |
| 83 | [3] = "Colibri PXA320 806MHz", |
| 84 | [4] = "Colibri PXA300 208MHz", |
| 85 | [5] = "Colibri PXA310 624MHz", |
| 86 | [6] = "Colibri PXA320 806MHz IT", |
| 87 | [7] = "Colibri PXA300 208MHz XT", |
| 88 | [8] = "Colibri PXA270 312MHz", |
| 89 | [9] = "Colibri PXA270 520MHz", |
| 90 | [10] = "Colibri VF50 128MB", /* not currently on sale */ |
| 91 | [11] = "Colibri VF61 256MB", |
| 92 | [12] = "Colibri VF61 256MB IT", |
| 93 | [13] = "Colibri VF50 128MB IT", |
| 94 | [14] = "Colibri iMX6 Solo 256MB", |
| 95 | [15] = "Colibri iMX6 DualLite 512MB", |
| 96 | [16] = "Colibri iMX6 Solo 256MB IT", |
| 97 | [17] = "Colibri iMX6 DualLite 512MB IT", |
| 98 | [18] = "UNKNOWN MODULE", |
| 99 | [19] = "UNKNOWN MODULE", |
| 100 | [20] = "Colibri T20 256MB", |
| 101 | [21] = "Colibri T20 512MB", |
| 102 | [22] = "Colibri T20 512MB IT", |
| 103 | [23] = "Colibri T30 1GB", |
| 104 | [24] = "Colibri T20 256MB IT", |
| 105 | [25] = "Apalis T30 2GB", |
| 106 | [26] = "Apalis T30 1GB", |
| 107 | [27] = "Apalis iMX6 Quad 1GB", |
| 108 | [28] = "Apalis iMX6 Quad 2GB IT", |
| 109 | [29] = "Apalis iMX6 Dual 512MB", |
| 110 | [30] = "Colibri T30 1GB IT", |
| 111 | [31] = "Apalis T30 1GB IT", |
| 112 | [32] = "Colibri iMX7 Solo 256MB", |
| 113 | [33] = "Colibri iMX7 Dual 512MB", |
| 114 | [34] = "Apalis TK1 2GB", |
| 115 | [35] = "Apalis iMX6 Dual 1GB IT", |
Stefan Agner | 01875e9 | 2018-05-30 19:01:47 +0200 | [diff] [blame] | 116 | [36] = "Colibri iMX6ULL 256MB", |
Marcel Ziswiler | 2658c8e | 2019-04-09 17:25:32 +0200 | [diff] [blame] | 117 | [37] = "Apalis iMX8 QuadMax 4GB Wi-Fi / BT IT", |
| 118 | [38] = "Colibri iMX8 QuadXPlus 2GB Wi-Fi / BT IT", |
Stefan Agner | 01875e9 | 2018-05-30 19:01:47 +0200 | [diff] [blame] | 119 | [39] = "Colibri iMX7 Dual 1GB (eMMC)", |
Marcel Ziswiler | 2658c8e | 2019-04-09 17:25:32 +0200 | [diff] [blame] | 120 | [40] = "Colibri iMX6ULL 512MB Wi-Fi / BT IT", |
Stefan Agner | 01875e9 | 2018-05-30 19:01:47 +0200 | [diff] [blame] | 121 | [41] = "Colibri iMX7 Dual 512MB EPDC", |
| 122 | [42] = "Apalis TK1 4GB", |
Gerard Salvatella | 5ab3b1d | 2019-04-09 17:24:07 +0200 | [diff] [blame] | 123 | [43] = "Colibri T20 512MB IT SETEK", |
| 124 | [44] = "Colibri iMX6ULL 512MB IT", |
| 125 | [45] = "Colibri iMX6ULL 512MB Wi-Fi / Bluetooth", |
Marcel Ziswiler | f60ffec | 2019-04-09 17:25:33 +0200 | [diff] [blame] | 126 | [46] = "Apalis iMX8 QuadXPlus 2GB Wi-Fi / BT IT", |
| 127 | [47] = "Apalis iMX8 QuadMax 4GB IT", |
| 128 | [48] = "Apalis iMX8 QuadPlus 2GB Wi-Fi / BT", |
| 129 | [49] = "Apalis iMX8 QuadPlus 2GB", |
| 130 | [50] = "Colibri iMX8 QuadXPlus 2GB IT", |
| 131 | [51] = "Colibri iMX8 DualX 1GB Wi-Fi / Bluetooth", |
| 132 | [52] = "Colibri iMX8 DualX 1GB", |
Marcel Ziswiler | 75b9327 | 2020-01-28 14:42:23 +0100 | [diff] [blame] | 133 | [53] = "Apalis iMX8 QuadXPlus 2GB ECC IT", |
| 134 | [54] = "Apalis iMX8 DualXPlus 1GB", |
Marcel Ziswiler | eca26ba | 2020-01-28 14:42:24 +0100 | [diff] [blame] | 135 | [55] = "Verdin iMX8M Mini Quad 2GB Wi-Fi / BT IT", |
Marcel Ziswiler | 4a9c702 | 2020-10-28 11:58:08 +0200 | [diff] [blame] | 136 | [56] = "Verdin iMX8M Nano Quad 1GB Wi-Fi / BT", /* not currently on sale */ |
Marcel Ziswiler | eca26ba | 2020-01-28 14:42:24 +0100 | [diff] [blame] | 137 | [57] = "Verdin iMX8M Mini DualLite 1GB", |
Marcel Ziswiler | 4a9c702 | 2020-10-28 11:58:08 +0200 | [diff] [blame] | 138 | [58] = "Verdin iMX8M Plus Quad 4GB Wi-Fi / BT IT", |
| 139 | [59] = "Verdin iMX8M Mini Quad 2GB IT", |
| 140 | [60] = "Verdin iMX8M Mini DualLite 1GB WB IT", |
| 141 | [61] = "Verdin iMX8M Plus Quad 2GB", |
Marcel Ziswiler | c066a44 | 2021-10-06 18:55:34 +0200 | [diff] [blame] | 142 | [62] = "Colibri iMX6ULL 1GB IT (eMMC)", |
| 143 | [63] = "Verdin iMX8M Plus Quad 4GB IT", |
| 144 | [64] = "Verdin iMX8M Plus Quad 2GB Wi-Fi / BT IT", |
| 145 | [65] = "Verdin iMX8M Plus QuadLite 1GB IT", |
| 146 | [66] = "Verdin iMX8M Plus Quad 8GB Wi-Fi / BT", |
Philippe Schenker | 48b3703 | 2022-05-09 18:58:15 +0200 | [diff] [blame] | 147 | [67] = "Apalis iMX8 QuadMax 8GB Wi-Fi / BT IT", |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
Igor Opaniuk | 414df35 | 2020-07-15 13:30:54 +0300 | [diff] [blame] | 150 | const char * const toradex_carrier_boards[] = { |
| 151 | [0] = "UNKNOWN CARRIER BOARD", |
| 152 | [155] = "Dahlia", |
| 153 | [156] = "Verdin Development Board", |
| 154 | }; |
| 155 | |
| 156 | const char * const toradex_display_adapters[] = { |
| 157 | [0] = "UNKNOWN DISPLAY ADAPTER", |
| 158 | [157] = "Verdin DSI to HDMI Adapter", |
| 159 | [159] = "Verdin DSI to LVDS Adapter", |
| 160 | }; |
| 161 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 162 | #ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_MMC |
| 163 | static int tdx_cfg_block_mmc_storage(u8 *config_block, int write) |
| 164 | { |
| 165 | struct mmc *mmc; |
| 166 | int dev = CONFIG_TDX_CFG_BLOCK_DEV; |
| 167 | int offset = CONFIG_TDX_CFG_BLOCK_OFFSET; |
| 168 | uint part = CONFIG_TDX_CFG_BLOCK_PART; |
| 169 | uint blk_start; |
| 170 | int ret = 0; |
| 171 | |
| 172 | /* Read production parameter config block from eMMC */ |
| 173 | mmc = find_mmc_device(dev); |
| 174 | if (!mmc) { |
| 175 | puts("No MMC card found\n"); |
| 176 | ret = -ENODEV; |
| 177 | goto out; |
| 178 | } |
Stefan Agner | dd20234 | 2019-07-12 12:35:05 +0200 | [diff] [blame] | 179 | if (mmc_init(mmc)) { |
| 180 | puts("MMC init failed\n"); |
| 181 | return -EINVAL; |
| 182 | } |
Simon Glass | 8c4c5c8 | 2017-04-23 20:02:11 -0600 | [diff] [blame] | 183 | if (part != mmc_get_blk_desc(mmc)->hwpart) { |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 184 | if (blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part)) { |
| 185 | puts("MMC partition switch failed\n"); |
| 186 | ret = -ENODEV; |
| 187 | goto out; |
| 188 | } |
| 189 | } |
| 190 | if (offset < 0) |
| 191 | offset += mmc->capacity; |
| 192 | blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len; |
| 193 | |
| 194 | if (!write) { |
| 195 | /* Careful reads a whole block of 512 bytes into config_block */ |
| 196 | if (blk_dread(mmc_get_blk_desc(mmc), blk_start, 1, |
| 197 | (unsigned char *)config_block) != 1) { |
| 198 | ret = -EIO; |
| 199 | goto out; |
| 200 | } |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 201 | } else { |
| 202 | /* Just writing one 512 byte block */ |
| 203 | if (blk_dwrite(mmc_get_blk_desc(mmc), blk_start, 1, |
| 204 | (unsigned char *)config_block) != 1) { |
| 205 | ret = -EIO; |
| 206 | goto out; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | out: |
| 211 | /* Switch back to regular eMMC user partition */ |
| 212 | blk_select_hwpart_devnum(IF_TYPE_MMC, 0, 0); |
| 213 | |
| 214 | return ret; |
| 215 | } |
| 216 | #endif |
| 217 | |
| 218 | #ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_NAND |
| 219 | static int read_tdx_cfg_block_from_nand(unsigned char *config_block) |
| 220 | { |
| 221 | size_t size = TDX_CFG_BLOCK_MAX_SIZE; |
Stefan Agner | 8843b6d | 2018-08-06 09:19:18 +0200 | [diff] [blame] | 222 | struct mtd_info *mtd = get_nand_dev_by_index(0); |
| 223 | |
| 224 | if (!mtd) |
| 225 | return -ENODEV; |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 226 | |
| 227 | /* Read production parameter config block from NAND page */ |
Stefan Agner | 8843b6d | 2018-08-06 09:19:18 +0200 | [diff] [blame] | 228 | return nand_read_skip_bad(mtd, CONFIG_TDX_CFG_BLOCK_OFFSET, |
Grygorii Strashko | bb31462 | 2017-06-26 19:13:06 -0500 | [diff] [blame] | 229 | &size, NULL, TDX_CFG_BLOCK_MAX_SIZE, |
| 230 | config_block); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | static int write_tdx_cfg_block_to_nand(unsigned char *config_block) |
| 234 | { |
| 235 | size_t size = TDX_CFG_BLOCK_MAX_SIZE; |
| 236 | |
| 237 | /* Write production parameter config block to NAND page */ |
Grygorii Strashko | bb31462 | 2017-06-26 19:13:06 -0500 | [diff] [blame] | 238 | return nand_write_skip_bad(get_nand_dev_by_index(0), |
| 239 | CONFIG_TDX_CFG_BLOCK_OFFSET, |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 240 | &size, NULL, TDX_CFG_BLOCK_MAX_SIZE, |
| 241 | config_block, WITH_WR_VERIFY); |
| 242 | } |
| 243 | #endif |
| 244 | |
| 245 | #ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_NOR |
| 246 | static int read_tdx_cfg_block_from_nor(unsigned char *config_block) |
| 247 | { |
| 248 | /* Read production parameter config block from NOR flash */ |
| 249 | memcpy(config_block, (void *)CONFIG_TDX_CFG_BLOCK_OFFSET, |
| 250 | TDX_CFG_BLOCK_MAX_SIZE); |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | static int write_tdx_cfg_block_to_nor(unsigned char *config_block) |
| 255 | { |
| 256 | /* Write production parameter config block to NOR flash */ |
| 257 | return flash_write((void *)config_block, CONFIG_TDX_CFG_BLOCK_OFFSET, |
| 258 | TDX_CFG_BLOCK_MAX_SIZE); |
| 259 | } |
| 260 | #endif |
| 261 | |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 262 | #ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_EEPROM |
| 263 | static int read_tdx_cfg_block_from_eeprom(unsigned char *config_block) |
| 264 | { |
| 265 | return read_tdx_eeprom_data(TDX_EEPROM_ID_MODULE, 0x0, config_block, |
| 266 | TDX_CFG_BLOCK_MAX_SIZE); |
| 267 | } |
| 268 | |
| 269 | static int write_tdx_cfg_block_to_eeprom(unsigned char *config_block) |
| 270 | { |
| 271 | return write_tdx_eeprom_data(TDX_EEPROM_ID_MODULE, 0x0, config_block, |
| 272 | TDX_CFG_BLOCK_MAX_SIZE); |
| 273 | } |
| 274 | #endif |
| 275 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 276 | int read_tdx_cfg_block(void) |
| 277 | { |
| 278 | int ret = 0; |
| 279 | u8 *config_block = NULL; |
| 280 | struct toradex_tag *tag; |
| 281 | size_t size = TDX_CFG_BLOCK_MAX_SIZE; |
| 282 | int offset; |
| 283 | |
| 284 | /* Allocate RAM area for config block */ |
| 285 | config_block = memalign(ARCH_DMA_MINALIGN, size); |
| 286 | if (!config_block) { |
| 287 | printf("Not enough malloc space available!\n"); |
| 288 | return -ENOMEM; |
| 289 | } |
| 290 | |
| 291 | memset(config_block, 0, size); |
| 292 | |
| 293 | #if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_MMC) |
| 294 | ret = tdx_cfg_block_mmc_storage(config_block, 0); |
| 295 | #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND) |
| 296 | ret = read_tdx_cfg_block_from_nand(config_block); |
| 297 | #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR) |
| 298 | ret = read_tdx_cfg_block_from_nor(config_block); |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 299 | #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_EEPROM) |
| 300 | ret = read_tdx_cfg_block_from_eeprom(config_block); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 301 | #else |
| 302 | ret = -EINVAL; |
| 303 | #endif |
| 304 | if (ret) |
| 305 | goto out; |
| 306 | |
| 307 | /* Expect a valid tag first */ |
| 308 | tag = (struct toradex_tag *)config_block; |
| 309 | if (tag->flags != TAG_FLAG_VALID || tag->id != TAG_VALID) { |
| 310 | valid_cfgblock = false; |
| 311 | ret = -EINVAL; |
| 312 | goto out; |
| 313 | } |
| 314 | valid_cfgblock = true; |
| 315 | offset = 4; |
| 316 | |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 317 | /* |
| 318 | * check if there is enough space for storing tag and value of the |
| 319 | * biggest element |
| 320 | */ |
| 321 | while (offset + sizeof(struct toradex_tag) + |
| 322 | sizeof(struct toradex_hw) < TDX_CFG_BLOCK_MAX_SIZE) { |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 323 | tag = (struct toradex_tag *)(config_block + offset); |
| 324 | offset += 4; |
| 325 | if (tag->id == TAG_INVALID) |
| 326 | break; |
| 327 | |
| 328 | if (tag->flags == TAG_FLAG_VALID) { |
| 329 | switch (tag->id) { |
| 330 | case TAG_MAC: |
| 331 | memcpy(&tdx_eth_addr, config_block + offset, |
| 332 | 6); |
| 333 | |
| 334 | /* NIC part of MAC address is serial number */ |
| 335 | tdx_serial = ntohl(tdx_eth_addr.nic) >> 8; |
| 336 | break; |
| 337 | case TAG_HW: |
| 338 | memcpy(&tdx_hw_tag, config_block + offset, 8); |
| 339 | break; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | /* Get to next tag according to current tags length */ |
| 344 | offset += tag->len * 4; |
| 345 | } |
| 346 | |
| 347 | /* Cap product id to avoid issues with a yet unknown one */ |
Marcel Ziswiler | 8c9127c | 2019-03-25 17:18:29 +0100 | [diff] [blame] | 348 | if (tdx_hw_tag.prodid >= (sizeof(toradex_modules) / |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 349 | sizeof(toradex_modules[0]))) |
| 350 | tdx_hw_tag.prodid = 0; |
| 351 | |
| 352 | out: |
| 353 | free(config_block); |
| 354 | return ret; |
| 355 | } |
| 356 | |
Philippe Schenker | 498f95a | 2022-06-13 19:35:23 +0200 | [diff] [blame^] | 357 | static int parse_assembly_string(char *string_to_parse, u16 *assembly) |
| 358 | { |
| 359 | if (string_to_parse[3] >= 'A' && string_to_parse[3] <= 'Z') |
| 360 | *assembly = string_to_parse[3] - 'A'; |
| 361 | else if (string_to_parse[3] == '#') |
| 362 | *assembly = dectoul(&string_to_parse[4], NULL); |
| 363 | else |
| 364 | return -EINVAL; |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 369 | static int get_cfgblock_interactive(void) |
| 370 | { |
| 371 | char message[CONFIG_SYS_CBSIZE]; |
| 372 | char *soc; |
| 373 | char it = 'n'; |
Marcel Ziswiler | 35e3c6e | 2019-07-12 12:35:06 +0200 | [diff] [blame] | 374 | char wb = 'n'; |
Philippe Schenker | 48b3703 | 2022-05-09 18:58:15 +0200 | [diff] [blame] | 375 | char mem8g = 'n'; |
Marcel Ziswiler | eca26ba | 2020-01-28 14:42:24 +0100 | [diff] [blame] | 376 | int len = 0; |
Philippe Schenker | 498f95a | 2022-06-13 19:35:23 +0200 | [diff] [blame^] | 377 | int ret = 0; |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 378 | |
Stefan Agner | 68f5878 | 2019-04-09 17:24:08 +0200 | [diff] [blame] | 379 | /* Unknown module by default */ |
| 380 | tdx_hw_tag.prodid = 0; |
| 381 | |
Marcel Ziswiler | 384ca7f | 2022-04-13 11:33:32 +0200 | [diff] [blame] | 382 | sprintf(message, "Is the module an IT version? [y/N] "); |
Denys Drozdov | 8f6eaa9 | 2021-10-06 18:55:33 +0200 | [diff] [blame] | 383 | |
| 384 | len = cli_readline(message); |
| 385 | it = console_buffer[0]; |
Marcel Ziswiler | eca26ba | 2020-01-28 14:42:24 +0100 | [diff] [blame] | 386 | |
Marcel Ziswiler | 35e3c6e | 2019-07-12 12:35:06 +0200 | [diff] [blame] | 387 | #if defined(CONFIG_TARGET_APALIS_IMX8) || \ |
| 388 | defined(CONFIG_TARGET_COLIBRI_IMX6ULL) || \ |
Marcel Ziswiler | 4a9c702 | 2020-10-28 11:58:08 +0200 | [diff] [blame] | 389 | defined(CONFIG_TARGET_COLIBRI_IMX8X) || \ |
| 390 | defined(CONFIG_TARGET_VERDIN_IMX8MM) || \ |
| 391 | defined(CONFIG_TARGET_VERDIN_IMX8MP) |
Marcel Ziswiler | 35e3c6e | 2019-07-12 12:35:06 +0200 | [diff] [blame] | 392 | sprintf(message, "Does the module have Wi-Fi / Bluetooth? [y/N] "); |
| 393 | len = cli_readline(message); |
| 394 | wb = console_buffer[0]; |
Philippe Schenker | 48b3703 | 2022-05-09 18:58:15 +0200 | [diff] [blame] | 395 | |
| 396 | #if defined(CONFIG_TARGET_APALIS_IMX8) |
| 397 | if ((wb == 'y' || wb == 'Y') && (it == 'y' || it == 'Y')) { |
| 398 | sprintf(message, "Does your module have 8GB of RAM? [y/N] "); |
| 399 | len = cli_readline(message); |
| 400 | mem8g = console_buffer[0]; |
| 401 | } |
| 402 | #endif |
Marcel Ziswiler | 35e3c6e | 2019-07-12 12:35:06 +0200 | [diff] [blame] | 403 | #endif |
| 404 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 405 | soc = env_get("soc"); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 406 | if (!strcmp("mx6", soc)) { |
Stefan Agner | 68f5878 | 2019-04-09 17:24:08 +0200 | [diff] [blame] | 407 | #ifdef CONFIG_TARGET_APALIS_IMX6 |
| 408 | if (it == 'y' || it == 'Y') { |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 409 | if (is_cpu_type(MXC_CPU_MX6Q)) |
| 410 | tdx_hw_tag.prodid = APALIS_IMX6Q_IT; |
| 411 | else |
| 412 | tdx_hw_tag.prodid = APALIS_IMX6D_IT; |
Stefan Agner | 68f5878 | 2019-04-09 17:24:08 +0200 | [diff] [blame] | 413 | } else { |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 414 | if (is_cpu_type(MXC_CPU_MX6Q)) |
| 415 | tdx_hw_tag.prodid = APALIS_IMX6Q; |
| 416 | else |
| 417 | tdx_hw_tag.prodid = APALIS_IMX6D; |
Stefan Agner | 68f5878 | 2019-04-09 17:24:08 +0200 | [diff] [blame] | 418 | } |
| 419 | #elif CONFIG_TARGET_COLIBRI_IMX6 |
Gerard Salvatella | 5ab3b1d | 2019-04-09 17:24:07 +0200 | [diff] [blame] | 420 | if (it == 'y' || it == 'Y') { |
Stefan Agner | 68f5878 | 2019-04-09 17:24:08 +0200 | [diff] [blame] | 421 | if (is_cpu_type(MXC_CPU_MX6DL)) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 422 | tdx_hw_tag.prodid = COLIBRI_IMX6DL_IT; |
Stefan Agner | 68f5878 | 2019-04-09 17:24:08 +0200 | [diff] [blame] | 423 | else if (is_cpu_type(MXC_CPU_MX6SOLO)) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 424 | tdx_hw_tag.prodid = COLIBRI_IMX6S_IT; |
Gerard Salvatella | 5ab3b1d | 2019-04-09 17:24:07 +0200 | [diff] [blame] | 425 | } else { |
Stefan Agner | 68f5878 | 2019-04-09 17:24:08 +0200 | [diff] [blame] | 426 | if (is_cpu_type(MXC_CPU_MX6DL)) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 427 | tdx_hw_tag.prodid = COLIBRI_IMX6DL; |
Stefan Agner | 68f5878 | 2019-04-09 17:24:08 +0200 | [diff] [blame] | 428 | else if (is_cpu_type(MXC_CPU_MX6SOLO)) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 429 | tdx_hw_tag.prodid = COLIBRI_IMX6S; |
Gerard Salvatella | 5ab3b1d | 2019-04-09 17:24:07 +0200 | [diff] [blame] | 430 | } |
Stefan Agner | 68f5878 | 2019-04-09 17:24:08 +0200 | [diff] [blame] | 431 | #elif CONFIG_TARGET_COLIBRI_IMX6ULL |
Stefan Agner | 68f5878 | 2019-04-09 17:24:08 +0200 | [diff] [blame] | 432 | if (it == 'y' || it == 'Y') { |
| 433 | if (wb == 'y' || wb == 'Y') |
| 434 | tdx_hw_tag.prodid = COLIBRI_IMX6ULL_WIFI_BT_IT; |
| 435 | else |
Marcel Ziswiler | c066a44 | 2021-10-06 18:55:34 +0200 | [diff] [blame] | 436 | if (gd->ram_size == 0x20000000) |
| 437 | tdx_hw_tag.prodid = COLIBRI_IMX6ULL_IT; |
| 438 | else |
| 439 | tdx_hw_tag.prodid = COLIBRI_IMX6ULL_IT_EMMC; |
Stefan Agner | 68f5878 | 2019-04-09 17:24:08 +0200 | [diff] [blame] | 440 | } else { |
| 441 | if (wb == 'y' || wb == 'Y') |
| 442 | tdx_hw_tag.prodid = COLIBRI_IMX6ULL_WIFI_BT; |
| 443 | else |
| 444 | tdx_hw_tag.prodid = COLIBRI_IMX6ULL; |
| 445 | } |
| 446 | #endif |
Gerard Salvatella | 5ab3b1d | 2019-04-09 17:24:07 +0200 | [diff] [blame] | 447 | } else if (!strcmp("imx7d", soc)) |
Marcel Ziswiler | c066a44 | 2021-10-06 18:55:34 +0200 | [diff] [blame] | 448 | if (gd->ram_size == 0x20000000) |
| 449 | tdx_hw_tag.prodid = COLIBRI_IMX7D; |
| 450 | else |
| 451 | tdx_hw_tag.prodid = COLIBRI_IMX7D_EMMC; |
Gerard Salvatella | 5ab3b1d | 2019-04-09 17:24:07 +0200 | [diff] [blame] | 452 | else if (!strcmp("imx7s", soc)) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 453 | tdx_hw_tag.prodid = COLIBRI_IMX7S; |
Marcel Ziswiler | 0032061 | 2019-07-12 12:35:08 +0200 | [diff] [blame] | 454 | else if (is_cpu_type(MXC_CPU_IMX8QM)) { |
| 455 | if (it == 'y' || it == 'Y') { |
Philippe Schenker | 48b3703 | 2022-05-09 18:58:15 +0200 | [diff] [blame] | 456 | if (wb == 'y' || wb == 'Y') { |
| 457 | if (mem8g == 'y' || mem8g == 'Y') |
| 458 | tdx_hw_tag.prodid = APALIS_IMX8QM_8GB_WIFI_BT_IT; |
| 459 | else |
| 460 | tdx_hw_tag.prodid = APALIS_IMX8QM_WIFI_BT_IT; |
| 461 | } |
Marcel Ziswiler | 0032061 | 2019-07-12 12:35:08 +0200 | [diff] [blame] | 462 | else |
| 463 | tdx_hw_tag.prodid = APALIS_IMX8QM_IT; |
| 464 | } else { |
| 465 | if (wb == 'y' || wb == 'Y') |
| 466 | tdx_hw_tag.prodid = APALIS_IMX8QP_WIFI_BT; |
| 467 | else |
| 468 | tdx_hw_tag.prodid = APALIS_IMX8QP; |
| 469 | } |
| 470 | } else if (is_cpu_type(MXC_CPU_IMX8QXP)) { |
Denys Drozdov | 00b1e93 | 2022-04-13 11:33:25 +0200 | [diff] [blame] | 471 | #ifdef CONFIG_TARGET_COLIBRI_IMX8X |
Marcel Ziswiler | 7e2954f | 2019-07-12 12:35:07 +0200 | [diff] [blame] | 472 | if (it == 'y' || it == 'Y') { |
| 473 | if (wb == 'y' || wb == 'Y') |
| 474 | tdx_hw_tag.prodid = COLIBRI_IMX8QXP_WIFI_BT_IT; |
| 475 | else |
| 476 | tdx_hw_tag.prodid = COLIBRI_IMX8QXP_IT; |
| 477 | } else { |
| 478 | if (wb == 'y' || wb == 'Y') |
| 479 | tdx_hw_tag.prodid = COLIBRI_IMX8DX_WIFI_BT; |
| 480 | else |
| 481 | tdx_hw_tag.prodid = COLIBRI_IMX8DX; |
| 482 | } |
Marcel Ziswiler | 75b9327 | 2020-01-28 14:42:23 +0100 | [diff] [blame] | 483 | #endif |
Marcel Ziswiler | 3834f66 | 2020-10-28 11:58:15 +0200 | [diff] [blame] | 484 | } else if (is_cpu_type(MXC_CPU_IMX8MMDL)) { |
| 485 | if (wb == 'y' || wb == 'Y') |
| 486 | tdx_hw_tag.prodid = VERDIN_IMX8MMDL_WIFI_BT_IT; |
| 487 | else |
| 488 | tdx_hw_tag.prodid = VERDIN_IMX8MMDL; |
Marcel Ziswiler | 4a9c702 | 2020-10-28 11:58:08 +0200 | [diff] [blame] | 489 | } else if (is_cpu_type(MXC_CPU_IMX8MM)) { |
Marcel Ziswiler | 3834f66 | 2020-10-28 11:58:15 +0200 | [diff] [blame] | 490 | if (wb == 'y' || wb == 'Y') |
| 491 | tdx_hw_tag.prodid = VERDIN_IMX8MMQ_WIFI_BT_IT; |
| 492 | else |
| 493 | tdx_hw_tag.prodid = VERDIN_IMX8MMQ_IT; |
Marcel Ziswiler | 4a9c702 | 2020-10-28 11:58:08 +0200 | [diff] [blame] | 494 | } else if (is_cpu_type(MXC_CPU_IMX8MN)) { |
| 495 | tdx_hw_tag.prodid = VERDIN_IMX8MNQ_WIFI_BT; |
Marcel Ziswiler | c066a44 | 2021-10-06 18:55:34 +0200 | [diff] [blame] | 496 | } else if (is_cpu_type(MXC_CPU_IMX8MPL)) { |
| 497 | tdx_hw_tag.prodid = VERDIN_IMX8MPQL_IT; |
Marcel Ziswiler | 4a9c702 | 2020-10-28 11:58:08 +0200 | [diff] [blame] | 498 | } else if (is_cpu_type(MXC_CPU_IMX8MP)) { |
| 499 | if (wb == 'y' || wb == 'Y') |
Marcel Ziswiler | c066a44 | 2021-10-06 18:55:34 +0200 | [diff] [blame] | 500 | if (gd->ram_size == 0x80000000) |
| 501 | tdx_hw_tag.prodid = VERDIN_IMX8MPQ_2GB_WIFI_BT_IT; |
| 502 | else if (gd->ram_size == 0x200000000) |
| 503 | tdx_hw_tag.prodid = VERDIN_IMX8MPQ_8GB_WIFI_BT; |
| 504 | else |
| 505 | tdx_hw_tag.prodid = VERDIN_IMX8MPQ_WIFI_BT_IT; |
Marcel Ziswiler | 4a9c702 | 2020-10-28 11:58:08 +0200 | [diff] [blame] | 506 | else |
Marcel Ziswiler | c066a44 | 2021-10-06 18:55:34 +0200 | [diff] [blame] | 507 | if (it == 'y' || it == 'Y') |
| 508 | tdx_hw_tag.prodid = VERDIN_IMX8MPQ_IT; |
| 509 | else |
| 510 | tdx_hw_tag.prodid = VERDIN_IMX8MPQ; |
Marcel Ziswiler | 7e2954f | 2019-07-12 12:35:07 +0200 | [diff] [blame] | 511 | } else if (!strcmp("tegra20", soc)) { |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 512 | if (it == 'y' || it == 'Y') |
| 513 | if (gd->ram_size == 0x10000000) |
| 514 | tdx_hw_tag.prodid = COLIBRI_T20_256MB_IT; |
| 515 | else |
| 516 | tdx_hw_tag.prodid = COLIBRI_T20_512MB_IT; |
| 517 | else |
| 518 | if (gd->ram_size == 0x10000000) |
| 519 | tdx_hw_tag.prodid = COLIBRI_T20_256MB; |
| 520 | else |
| 521 | tdx_hw_tag.prodid = COLIBRI_T20_512MB; |
Gerard Salvatella | 5ab3b1d | 2019-04-09 17:24:07 +0200 | [diff] [blame] | 522 | } |
Tom Rini | eb6aadc | 2021-08-30 09:16:32 -0400 | [diff] [blame] | 523 | #if defined(CONFIG_TARGET_APALIS_T30) || defined(CONFIG_TARGET_COLIBRI_T30) |
Gerard Salvatella | 5ab3b1d | 2019-04-09 17:24:07 +0200 | [diff] [blame] | 524 | else if (!strcmp("tegra30", soc)) { |
Tom Rini | eb6aadc | 2021-08-30 09:16:32 -0400 | [diff] [blame] | 525 | #ifdef CONFIG_TARGET_APALIS_T30 |
| 526 | if (it == 'y' || it == 'Y') |
| 527 | tdx_hw_tag.prodid = APALIS_T30_IT; |
| 528 | else |
| 529 | if (gd->ram_size == 0x40000000) |
| 530 | tdx_hw_tag.prodid = APALIS_T30_1GB; |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 531 | else |
Tom Rini | eb6aadc | 2021-08-30 09:16:32 -0400 | [diff] [blame] | 532 | tdx_hw_tag.prodid = APALIS_T30_2GB; |
| 533 | #else |
| 534 | if (it == 'y' || it == 'Y') |
| 535 | tdx_hw_tag.prodid = COLIBRI_T30_IT; |
| 536 | else |
| 537 | tdx_hw_tag.prodid = COLIBRI_T30; |
| 538 | #endif |
Gerard Salvatella | 5ab3b1d | 2019-04-09 17:24:07 +0200 | [diff] [blame] | 539 | } |
Tom Rini | eb6aadc | 2021-08-30 09:16:32 -0400 | [diff] [blame] | 540 | #endif /* CONFIG_TARGET_APALIS_T30 || CONFIG_TARGET_COLIBRI_T30 */ |
Gerard Salvatella | 5ab3b1d | 2019-04-09 17:24:07 +0200 | [diff] [blame] | 541 | else if (!strcmp("tegra124", soc)) { |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 542 | tdx_hw_tag.prodid = APALIS_TK1_2GB; |
| 543 | } else if (!strcmp("vf500", soc)) { |
| 544 | if (it == 'y' || it == 'Y') |
| 545 | tdx_hw_tag.prodid = COLIBRI_VF50_IT; |
| 546 | else |
| 547 | tdx_hw_tag.prodid = COLIBRI_VF50; |
| 548 | } else if (!strcmp("vf610", soc)) { |
| 549 | if (it == 'y' || it == 'Y') |
| 550 | tdx_hw_tag.prodid = COLIBRI_VF61_IT; |
| 551 | else |
| 552 | tdx_hw_tag.prodid = COLIBRI_VF61; |
Stefan Agner | 68f5878 | 2019-04-09 17:24:08 +0200 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | if (!tdx_hw_tag.prodid) { |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 556 | printf("Module type not detectable due to unknown SoC\n"); |
| 557 | return -1; |
| 558 | } |
| 559 | |
| 560 | while (len < 4) { |
Philippe Schenker | 498f95a | 2022-06-13 19:35:23 +0200 | [diff] [blame^] | 561 | sprintf(message, "Enter the module version (e.g. V1.1B or V1.1#26): V"); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 562 | len = cli_readline(message); |
| 563 | } |
| 564 | |
| 565 | tdx_hw_tag.ver_major = console_buffer[0] - '0'; |
| 566 | tdx_hw_tag.ver_minor = console_buffer[2] - '0'; |
Philippe Schenker | 498f95a | 2022-06-13 19:35:23 +0200 | [diff] [blame^] | 567 | |
| 568 | ret = parse_assembly_string(console_buffer, &tdx_hw_tag.ver_assembly); |
| 569 | if (ret) { |
| 570 | printf("Parsing module version failed\n"); |
| 571 | return ret; |
| 572 | } |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 573 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 574 | while (len < 8) { |
| 575 | sprintf(message, "Enter module serial number: "); |
| 576 | len = cli_readline(message); |
| 577 | } |
| 578 | |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 579 | tdx_serial = dectoul(console_buffer, NULL); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 580 | |
| 581 | return 0; |
| 582 | } |
| 583 | |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 584 | static int get_cfgblock_barcode(char *barcode, struct toradex_hw *tag, |
| 585 | u32 *serial) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 586 | { |
Denys Drozdov | 3a1c657 | 2021-04-07 15:28:24 +0300 | [diff] [blame] | 587 | char revision[3] = {barcode[6], barcode[7], '\0'}; |
| 588 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 589 | if (strlen(barcode) < 16) { |
| 590 | printf("Argument too short, barcode is 16 chars long\n"); |
| 591 | return -1; |
| 592 | } |
| 593 | |
| 594 | /* Get hardware information from the first 8 digits */ |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 595 | tag->ver_major = barcode[4] - '0'; |
| 596 | tag->ver_minor = barcode[5] - '0'; |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 597 | tag->ver_assembly = dectoul(revision, NULL); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 598 | |
| 599 | barcode[4] = '\0'; |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 600 | tag->prodid = dectoul(barcode, NULL); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 601 | |
| 602 | /* Parse second part of the barcode (serial number */ |
| 603 | barcode += 8; |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 604 | *serial = dectoul(barcode, NULL); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 605 | |
| 606 | return 0; |
| 607 | } |
| 608 | |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 609 | static int write_tag(u8 *config_block, int *offset, int tag_id, |
| 610 | u8 *tag_data, size_t tag_data_size) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 611 | { |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 612 | struct toradex_tag *tag; |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 613 | |
| 614 | if (!offset || !config_block) |
| 615 | return -EINVAL; |
| 616 | |
| 617 | tag = (struct toradex_tag *)(config_block + *offset); |
| 618 | tag->id = tag_id; |
| 619 | tag->flags = TAG_FLAG_VALID; |
| 620 | /* len is provided as number of 32bit values after the tag */ |
| 621 | tag->len = (tag_data_size + sizeof(u32) - 1) / sizeof(u32); |
| 622 | *offset += sizeof(struct toradex_tag); |
| 623 | if (tag_data && tag_data_size) { |
| 624 | memcpy(config_block + *offset, tag_data, |
| 625 | tag_data_size); |
| 626 | *offset += tag_data_size; |
| 627 | } |
| 628 | |
| 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | #ifdef CONFIG_TDX_CFG_BLOCK_EXTRA |
| 633 | int read_tdx_cfg_block_carrier(void) |
| 634 | { |
| 635 | int ret = 0; |
| 636 | u8 *config_block = NULL; |
| 637 | struct toradex_tag *tag; |
| 638 | size_t size = TDX_CFG_BLOCK_EXTRA_MAX_SIZE; |
| 639 | int offset; |
| 640 | |
| 641 | /* Allocate RAM area for carrier config block */ |
| 642 | config_block = memalign(ARCH_DMA_MINALIGN, size); |
| 643 | if (!config_block) { |
| 644 | printf("Not enough malloc space available!\n"); |
| 645 | return -ENOMEM; |
| 646 | } |
| 647 | |
| 648 | memset(config_block, 0, size); |
| 649 | |
| 650 | ret = read_tdx_eeprom_data(TDX_EEPROM_ID_CARRIER, 0x0, config_block, |
| 651 | size); |
| 652 | if (ret) |
| 653 | return ret; |
| 654 | |
| 655 | /* Expect a valid tag first */ |
| 656 | tag = (struct toradex_tag *)config_block; |
| 657 | if (tag->flags != TAG_FLAG_VALID || tag->id != TAG_VALID) { |
| 658 | valid_cfgblock_carrier = false; |
| 659 | ret = -EINVAL; |
| 660 | goto out; |
| 661 | } |
| 662 | valid_cfgblock_carrier = true; |
| 663 | offset = 4; |
| 664 | |
| 665 | while (offset + sizeof(struct toradex_tag) + |
| 666 | sizeof(struct toradex_hw) < TDX_CFG_BLOCK_MAX_SIZE) { |
| 667 | tag = (struct toradex_tag *)(config_block + offset); |
| 668 | offset += 4; |
| 669 | if (tag->id == TAG_INVALID) |
| 670 | break; |
| 671 | |
| 672 | if (tag->flags == TAG_FLAG_VALID) { |
| 673 | switch (tag->id) { |
| 674 | case TAG_CAR_SERIAL: |
| 675 | memcpy(&tdx_car_serial, config_block + offset, |
| 676 | sizeof(tdx_car_serial)); |
| 677 | break; |
| 678 | case TAG_HW: |
| 679 | memcpy(&tdx_car_hw_tag, config_block + |
| 680 | offset, 8); |
| 681 | break; |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | /* Get to next tag according to current tags length */ |
| 686 | offset += tag->len * 4; |
| 687 | } |
| 688 | out: |
| 689 | free(config_block); |
| 690 | return ret; |
| 691 | } |
| 692 | |
Igor Opaniuk | e9ad67a | 2020-07-15 13:30:56 +0300 | [diff] [blame] | 693 | int check_pid8_sanity(char *pid8) |
| 694 | { |
| 695 | char s_carrierid_verdin_dev[5]; |
| 696 | char s_carrierid_dahlia[5]; |
| 697 | |
| 698 | sprintf(s_carrierid_verdin_dev, "0%d", VERDIN_DEVELOPMENT_BOARD); |
| 699 | sprintf(s_carrierid_dahlia, "0%d", DAHLIA); |
| 700 | |
| 701 | /* sane value check, first 4 chars which represent carrier id */ |
| 702 | if (!strncmp(pid8, s_carrierid_verdin_dev, 4)) |
| 703 | return 0; |
| 704 | |
| 705 | if (!strncmp(pid8, s_carrierid_dahlia, 4)) |
| 706 | return 0; |
| 707 | |
| 708 | return -EINVAL; |
| 709 | } |
| 710 | |
| 711 | int try_migrate_tdx_cfg_block_carrier(void) |
| 712 | { |
| 713 | char pid8[8]; |
| 714 | int offset = 0; |
| 715 | int ret = CMD_RET_SUCCESS; |
| 716 | size_t size = TDX_CFG_BLOCK_EXTRA_MAX_SIZE; |
| 717 | u8 *config_block; |
| 718 | |
| 719 | memset(pid8, 0x0, 8); |
| 720 | ret = read_tdx_eeprom_data(TDX_EEPROM_ID_CARRIER, 0x0, (u8 *)pid8, 8); |
| 721 | if (ret) |
| 722 | return ret; |
| 723 | |
| 724 | if (check_pid8_sanity(pid8)) |
| 725 | return -EINVAL; |
| 726 | |
| 727 | /* Allocate RAM area for config block */ |
| 728 | config_block = memalign(ARCH_DMA_MINALIGN, size); |
| 729 | if (!config_block) { |
| 730 | printf("Not enough malloc space available!\n"); |
| 731 | return CMD_RET_FAILURE; |
| 732 | } |
| 733 | |
| 734 | memset(config_block, 0xff, size); |
| 735 | /* we try parse PID8 concatenating zeroed serial number */ |
| 736 | tdx_car_hw_tag.ver_major = pid8[4] - '0'; |
| 737 | tdx_car_hw_tag.ver_minor = pid8[5] - '0'; |
| 738 | tdx_car_hw_tag.ver_assembly = pid8[7] - '0'; |
| 739 | |
| 740 | pid8[4] = '\0'; |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 741 | tdx_car_hw_tag.prodid = dectoul(pid8, NULL); |
Igor Opaniuk | e9ad67a | 2020-07-15 13:30:56 +0300 | [diff] [blame] | 742 | |
| 743 | /* Valid Tag */ |
| 744 | write_tag(config_block, &offset, TAG_VALID, NULL, 0); |
| 745 | |
| 746 | /* Product Tag */ |
| 747 | write_tag(config_block, &offset, TAG_HW, (u8 *)&tdx_car_hw_tag, |
| 748 | sizeof(tdx_car_hw_tag)); |
| 749 | |
| 750 | /* Serial Tag */ |
| 751 | write_tag(config_block, &offset, TAG_CAR_SERIAL, (u8 *)&tdx_car_serial, |
| 752 | sizeof(tdx_car_serial)); |
| 753 | |
| 754 | memset(config_block + offset, 0, 32 - offset); |
| 755 | ret = write_tdx_eeprom_data(TDX_EEPROM_ID_CARRIER, 0x0, config_block, |
| 756 | size); |
| 757 | if (ret) { |
| 758 | printf("Failed to write Toradex Extra config block: %d\n", |
| 759 | ret); |
| 760 | ret = CMD_RET_FAILURE; |
| 761 | goto out; |
| 762 | } |
| 763 | |
| 764 | printf("Successfully migrated to Toradex Config Block from PID8\n"); |
| 765 | |
| 766 | out: |
| 767 | free(config_block); |
| 768 | return ret; |
| 769 | } |
| 770 | |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 771 | static int get_cfgblock_carrier_interactive(void) |
| 772 | { |
| 773 | char message[CONFIG_SYS_CBSIZE]; |
| 774 | int len; |
Philippe Schenker | 498f95a | 2022-06-13 19:35:23 +0200 | [diff] [blame^] | 775 | int ret = 0; |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 776 | |
| 777 | printf("Supported carrier boards:\n"); |
| 778 | printf("CARRIER BOARD NAME\t\t [ID]\n"); |
| 779 | for (int i = 0; i < sizeof(toradex_carrier_boards) / |
| 780 | sizeof(toradex_carrier_boards[0]); i++) |
| 781 | if (toradex_carrier_boards[i]) |
| 782 | printf("%s \t\t [%d]\n", toradex_carrier_boards[i], i); |
| 783 | |
| 784 | sprintf(message, "Choose your carrier board (provide ID): "); |
| 785 | len = cli_readline(message); |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 786 | tdx_car_hw_tag.prodid = dectoul(console_buffer, NULL); |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 787 | |
| 788 | do { |
Philippe Schenker | 498f95a | 2022-06-13 19:35:23 +0200 | [diff] [blame^] | 789 | sprintf(message, "Enter carrier board version (e.g. V1.1B or V1.1#26): V"); |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 790 | len = cli_readline(message); |
| 791 | } while (len < 4); |
| 792 | |
| 793 | tdx_car_hw_tag.ver_major = console_buffer[0] - '0'; |
| 794 | tdx_car_hw_tag.ver_minor = console_buffer[2] - '0'; |
Philippe Schenker | 498f95a | 2022-06-13 19:35:23 +0200 | [diff] [blame^] | 795 | |
| 796 | ret = parse_assembly_string(console_buffer, &tdx_car_hw_tag.ver_assembly); |
| 797 | if (ret) { |
| 798 | printf("Parsing module version failed\n"); |
| 799 | return ret; |
| 800 | } |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 801 | |
| 802 | while (len < 8) { |
| 803 | sprintf(message, "Enter carrier board serial number: "); |
| 804 | len = cli_readline(message); |
| 805 | } |
| 806 | |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 807 | tdx_car_serial = dectoul(console_buffer, NULL); |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 808 | |
| 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | static int do_cfgblock_carrier_create(struct cmd_tbl *cmdtp, int flag, int argc, |
| 813 | char * const argv[]) |
| 814 | { |
| 815 | u8 *config_block; |
| 816 | size_t size = TDX_CFG_BLOCK_EXTRA_MAX_SIZE; |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 817 | int offset = 0; |
| 818 | int ret = CMD_RET_SUCCESS; |
| 819 | int err; |
Dominik Sliwa | f1e1059 | 2019-03-25 17:18:27 +0100 | [diff] [blame] | 820 | int force_overwrite = 0; |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 821 | |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 822 | if (argc >= 3) { |
| 823 | if (argv[2][0] == '-' && argv[2][1] == 'y') |
| 824 | force_overwrite = 1; |
| 825 | } |
| 826 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 827 | /* Allocate RAM area for config block */ |
| 828 | config_block = memalign(ARCH_DMA_MINALIGN, size); |
| 829 | if (!config_block) { |
| 830 | printf("Not enough malloc space available!\n"); |
| 831 | return CMD_RET_FAILURE; |
| 832 | } |
| 833 | |
| 834 | memset(config_block, 0xff, size); |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 835 | read_tdx_cfg_block_carrier(); |
| 836 | if (valid_cfgblock_carrier && !force_overwrite) { |
| 837 | char message[CONFIG_SYS_CBSIZE]; |
| 838 | |
| 839 | sprintf(message, "A valid Toradex Carrier config block is present, still recreate? [y/N] "); |
| 840 | |
| 841 | if (!cli_readline(message)) |
| 842 | goto out; |
| 843 | |
| 844 | if (console_buffer[0] != 'y' && |
| 845 | console_buffer[0] != 'Y') |
| 846 | goto out; |
| 847 | } |
| 848 | |
| 849 | if (argc < 3 || (force_overwrite && argc < 4)) { |
| 850 | err = get_cfgblock_carrier_interactive(); |
| 851 | } else { |
| 852 | if (force_overwrite) |
| 853 | err = get_cfgblock_barcode(argv[3], &tdx_car_hw_tag, |
| 854 | &tdx_car_serial); |
| 855 | else |
| 856 | err = get_cfgblock_barcode(argv[2], &tdx_car_hw_tag, |
| 857 | &tdx_car_serial); |
| 858 | } |
| 859 | |
| 860 | if (err) { |
| 861 | ret = CMD_RET_FAILURE; |
| 862 | goto out; |
| 863 | } |
| 864 | |
| 865 | /* Valid Tag */ |
| 866 | write_tag(config_block, &offset, TAG_VALID, NULL, 0); |
| 867 | |
| 868 | /* Product Tag */ |
| 869 | write_tag(config_block, &offset, TAG_HW, (u8 *)&tdx_car_hw_tag, |
| 870 | sizeof(tdx_car_hw_tag)); |
| 871 | |
| 872 | /* Serial Tag */ |
| 873 | write_tag(config_block, &offset, TAG_CAR_SERIAL, (u8 *)&tdx_car_serial, |
| 874 | sizeof(tdx_car_serial)); |
| 875 | |
| 876 | memset(config_block + offset, 0, 32 - offset); |
| 877 | err = write_tdx_eeprom_data(TDX_EEPROM_ID_CARRIER, 0x0, config_block, |
| 878 | size); |
| 879 | if (err) { |
| 880 | printf("Failed to write Toradex Extra config block: %d\n", |
| 881 | ret); |
| 882 | ret = CMD_RET_FAILURE; |
| 883 | goto out; |
| 884 | } |
| 885 | |
| 886 | printf("Toradex Extra config block successfully written\n"); |
| 887 | |
| 888 | out: |
| 889 | free(config_block); |
| 890 | return ret; |
| 891 | } |
| 892 | |
| 893 | #endif /* CONFIG_TDX_CFG_BLOCK_EXTRA */ |
| 894 | |
| 895 | static int do_cfgblock_create(struct cmd_tbl *cmdtp, int flag, int argc, |
| 896 | char * const argv[]) |
| 897 | { |
| 898 | u8 *config_block; |
| 899 | size_t size = TDX_CFG_BLOCK_MAX_SIZE; |
| 900 | int offset = 0; |
| 901 | int ret = CMD_RET_SUCCESS; |
| 902 | int err; |
| 903 | int force_overwrite = 0; |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 904 | |
Dominik Sliwa | f1e1059 | 2019-03-25 17:18:27 +0100 | [diff] [blame] | 905 | if (argc >= 3) { |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 906 | #ifdef CONFIG_TDX_CFG_BLOCK_EXTRA |
| 907 | if (!strcmp(argv[2], "carrier")) |
| 908 | return do_cfgblock_carrier_create(cmdtp, flag, |
| 909 | --argc, ++argv); |
| 910 | #endif /* CONFIG_TDX_CFG_BLOCK_EXTRA */ |
Dominik Sliwa | f1e1059 | 2019-03-25 17:18:27 +0100 | [diff] [blame] | 911 | if (argv[2][0] == '-' && argv[2][1] == 'y') |
| 912 | force_overwrite = 1; |
| 913 | } |
| 914 | |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 915 | /* Allocate RAM area for config block */ |
| 916 | config_block = memalign(ARCH_DMA_MINALIGN, size); |
| 917 | if (!config_block) { |
| 918 | printf("Not enough malloc space available!\n"); |
| 919 | return CMD_RET_FAILURE; |
| 920 | } |
| 921 | |
| 922 | memset(config_block, 0xff, size); |
| 923 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 924 | read_tdx_cfg_block(); |
| 925 | if (valid_cfgblock) { |
| 926 | #if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND) |
| 927 | /* |
| 928 | * On NAND devices, recreation is only allowed if the page is |
| 929 | * empty (config block invalid...) |
| 930 | */ |
Marcel Ziswiler | 6cf2f78 | 2019-07-12 12:35:09 +0200 | [diff] [blame] | 931 | printf("NAND erase block %d need to be erased before creating a Toradex config block\n", |
Grygorii Strashko | bb31462 | 2017-06-26 19:13:06 -0500 | [diff] [blame] | 932 | CONFIG_TDX_CFG_BLOCK_OFFSET / |
| 933 | get_nand_dev_by_index(0)->erasesize); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 934 | goto out; |
| 935 | #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR) |
| 936 | /* |
| 937 | * On NOR devices, recreation is only allowed if the sector is |
| 938 | * empty and write protection is off (config block invalid...) |
| 939 | */ |
Marcel Ziswiler | 6cf2f78 | 2019-07-12 12:35:09 +0200 | [diff] [blame] | 940 | printf("NOR sector at offset 0x%02x need to be erased and unprotected before creating a Toradex config block\n", |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 941 | CONFIG_TDX_CFG_BLOCK_OFFSET); |
| 942 | goto out; |
| 943 | #else |
Dominik Sliwa | f1e1059 | 2019-03-25 17:18:27 +0100 | [diff] [blame] | 944 | if (!force_overwrite) { |
| 945 | char message[CONFIG_SYS_CBSIZE]; |
| 946 | |
| 947 | sprintf(message, |
| 948 | "A valid Toradex config block is present, still recreate? [y/N] "); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 949 | |
Dominik Sliwa | f1e1059 | 2019-03-25 17:18:27 +0100 | [diff] [blame] | 950 | if (!cli_readline(message)) |
| 951 | goto out; |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 952 | |
Dominik Sliwa | f1e1059 | 2019-03-25 17:18:27 +0100 | [diff] [blame] | 953 | if (console_buffer[0] != 'y' && |
| 954 | console_buffer[0] != 'Y') |
| 955 | goto out; |
| 956 | } |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 957 | #endif |
| 958 | } |
| 959 | |
| 960 | /* Parse new Toradex config block data... */ |
Dominik Sliwa | f1e1059 | 2019-03-25 17:18:27 +0100 | [diff] [blame] | 961 | if (argc < 3 || (force_overwrite && argc < 4)) { |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 962 | err = get_cfgblock_interactive(); |
Dominik Sliwa | f1e1059 | 2019-03-25 17:18:27 +0100 | [diff] [blame] | 963 | } else { |
| 964 | if (force_overwrite) |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 965 | err = get_cfgblock_barcode(argv[3], &tdx_hw_tag, |
| 966 | &tdx_serial); |
Dominik Sliwa | f1e1059 | 2019-03-25 17:18:27 +0100 | [diff] [blame] | 967 | else |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 968 | err = get_cfgblock_barcode(argv[2], &tdx_hw_tag, |
| 969 | &tdx_serial); |
Dominik Sliwa | f1e1059 | 2019-03-25 17:18:27 +0100 | [diff] [blame] | 970 | } |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 971 | if (err) { |
| 972 | ret = CMD_RET_FAILURE; |
| 973 | goto out; |
| 974 | } |
| 975 | |
| 976 | /* Convert serial number to MAC address (the storage format) */ |
| 977 | tdx_eth_addr.oui = htonl(0x00142dUL << 8); |
| 978 | tdx_eth_addr.nic = htonl(tdx_serial << 8); |
| 979 | |
| 980 | /* Valid Tag */ |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 981 | write_tag(config_block, &offset, TAG_VALID, NULL, 0); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 982 | |
| 983 | /* Product Tag */ |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 984 | write_tag(config_block, &offset, TAG_HW, (u8 *)&tdx_hw_tag, |
| 985 | sizeof(tdx_hw_tag)); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 986 | |
| 987 | /* MAC Tag */ |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 988 | write_tag(config_block, &offset, TAG_MAC, (u8 *)&tdx_eth_addr, |
| 989 | sizeof(tdx_eth_addr)); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 990 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 991 | memset(config_block + offset, 0, 32 - offset); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 992 | #if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_MMC) |
| 993 | err = tdx_cfg_block_mmc_storage(config_block, 1); |
| 994 | #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND) |
| 995 | err = write_tdx_cfg_block_to_nand(config_block); |
| 996 | #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR) |
| 997 | err = write_tdx_cfg_block_to_nor(config_block); |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 998 | #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_EEPROM) |
| 999 | err = write_tdx_cfg_block_to_eeprom(config_block); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 1000 | #else |
| 1001 | err = -EINVAL; |
| 1002 | #endif |
| 1003 | if (err) { |
| 1004 | printf("Failed to write Toradex config block: %d\n", ret); |
| 1005 | ret = CMD_RET_FAILURE; |
| 1006 | goto out; |
| 1007 | } |
| 1008 | |
| 1009 | printf("Toradex config block successfully written\n"); |
| 1010 | |
| 1011 | out: |
| 1012 | free(config_block); |
| 1013 | return ret; |
| 1014 | } |
| 1015 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1016 | static int do_cfgblock(struct cmd_tbl *cmdtp, int flag, int argc, |
| 1017 | char *const argv[]) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 1018 | { |
| 1019 | int ret; |
| 1020 | |
| 1021 | if (argc < 2) |
| 1022 | return CMD_RET_USAGE; |
| 1023 | |
| 1024 | if (!strcmp(argv[1], "create")) { |
| 1025 | return do_cfgblock_create(cmdtp, flag, argc, argv); |
| 1026 | } else if (!strcmp(argv[1], "reload")) { |
| 1027 | ret = read_tdx_cfg_block(); |
| 1028 | if (ret) { |
| 1029 | printf("Failed to reload Toradex config block: %d\n", |
| 1030 | ret); |
| 1031 | return CMD_RET_FAILURE; |
| 1032 | } |
| 1033 | return CMD_RET_SUCCESS; |
| 1034 | } |
| 1035 | |
| 1036 | return CMD_RET_USAGE; |
| 1037 | } |
| 1038 | |
Igor Opaniuk | 67c9bfc | 2020-07-15 13:30:55 +0300 | [diff] [blame] | 1039 | U_BOOT_CMD( |
| 1040 | cfgblock, 5, 0, do_cfgblock, |
| 1041 | "Toradex config block handling commands", |
| 1042 | "create [-y] [barcode] - (Re-)create Toradex config block\n" |
| 1043 | "create carrier [-y] [barcode] - (Re-)create Toradex Carrier config block\n" |
| 1044 | "cfgblock reload - Reload Toradex config block from flash" |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 1045 | ); |