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