toradex: configblock: initialize MMC before switching partition
[oweals/u-boot.git] / board / toradex / common / tdx-cfg-block.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2016-2019 Toradex, Inc.
4  */
5
6 #include <common.h>
7 #include "tdx-cfg-block.h"
8
9 #if defined(CONFIG_TARGET_APALIS_IMX6) || \
10         defined(CONFIG_TARGET_COLIBRI_IMX6) || \
11         defined(CONFIG_TARGET_COLIBRI_IMX8QXP)
12 #include <asm/arch/sys_proto.h>
13 #else
14 #define is_cpu_type(cpu) (0)
15 #endif
16 #if defined(CONFIG_CPU_PXA27X)
17 #include <asm/arch-pxa/pxa.h>
18 #else
19 #define cpu_is_pxa27x(cpu) (0)
20 #endif
21 #include <cli.h>
22 #include <console.h>
23 #include <flash.h>
24 #include <malloc.h>
25 #include <mmc.h>
26 #include <nand.h>
27 #include <asm/mach-types.h>
28
29 DECLARE_GLOBAL_DATA_PTR;
30
31 #define TAG_VALID       0xcf01
32 #define TAG_MAC         0x0000
33 #define TAG_HW          0x0008
34 #define TAG_INVALID     0xffff
35
36 #define TAG_FLAG_VALID  0x1
37
38 #if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_MMC)
39 #define TDX_CFG_BLOCK_MAX_SIZE 512
40 #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND)
41 #define TDX_CFG_BLOCK_MAX_SIZE 64
42 #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR)
43 #define TDX_CFG_BLOCK_MAX_SIZE 64
44 #else
45 #error Toradex config block location not set
46 #endif
47
48 struct toradex_tag {
49         u32 len:14;
50         u32 flags:2;
51         u32 id:16;
52 };
53
54 bool valid_cfgblock;
55 struct toradex_hw tdx_hw_tag;
56 struct toradex_eth_addr tdx_eth_addr;
57 u32 tdx_serial;
58
59 const char * const toradex_modules[] = {
60          [0] = "UNKNOWN MODULE",
61          [1] = "Colibri PXA270 312MHz",
62          [2] = "Colibri PXA270 520MHz",
63          [3] = "Colibri PXA320 806MHz",
64          [4] = "Colibri PXA300 208MHz",
65          [5] = "Colibri PXA310 624MHz",
66          [6] = "Colibri PXA320 806MHz IT",
67          [7] = "Colibri PXA300 208MHz XT",
68          [8] = "Colibri PXA270 312MHz",
69          [9] = "Colibri PXA270 520MHz",
70         [10] = "Colibri VF50 128MB", /* not currently on sale */
71         [11] = "Colibri VF61 256MB",
72         [12] = "Colibri VF61 256MB IT",
73         [13] = "Colibri VF50 128MB IT",
74         [14] = "Colibri iMX6 Solo 256MB",
75         [15] = "Colibri iMX6 DualLite 512MB",
76         [16] = "Colibri iMX6 Solo 256MB IT",
77         [17] = "Colibri iMX6 DualLite 512MB IT",
78         [18] = "UNKNOWN MODULE",
79         [19] = "UNKNOWN MODULE",
80         [20] = "Colibri T20 256MB",
81         [21] = "Colibri T20 512MB",
82         [22] = "Colibri T20 512MB IT",
83         [23] = "Colibri T30 1GB",
84         [24] = "Colibri T20 256MB IT",
85         [25] = "Apalis T30 2GB",
86         [26] = "Apalis T30 1GB",
87         [27] = "Apalis iMX6 Quad 1GB",
88         [28] = "Apalis iMX6 Quad 2GB IT",
89         [29] = "Apalis iMX6 Dual 512MB",
90         [30] = "Colibri T30 1GB IT",
91         [31] = "Apalis T30 1GB IT",
92         [32] = "Colibri iMX7 Solo 256MB",
93         [33] = "Colibri iMX7 Dual 512MB",
94         [34] = "Apalis TK1 2GB",
95         [35] = "Apalis iMX6 Dual 1GB IT",
96         [36] = "Colibri iMX6ULL 256MB",
97         [37] = "Apalis iMX8 QuadMax 4GB Wi-Fi / BT IT",
98         [38] = "Colibri iMX8 QuadXPlus 2GB Wi-Fi / BT IT",
99         [39] = "Colibri iMX7 Dual 1GB (eMMC)",
100         [40] = "Colibri iMX6ULL 512MB Wi-Fi / BT IT",
101         [41] = "Colibri iMX7 Dual 512MB EPDC",
102         [42] = "Apalis TK1 4GB",
103         [43] = "Colibri T20 512MB IT SETEK",
104         [44] = "Colibri iMX6ULL 512MB IT",
105         [45] = "Colibri iMX6ULL 512MB Wi-Fi / Bluetooth",
106         [46] = "Apalis iMX8 QuadXPlus 2GB Wi-Fi / BT IT",
107         [47] = "Apalis iMX8 QuadMax 4GB IT",
108         [48] = "Apalis iMX8 QuadPlus 2GB Wi-Fi / BT",
109         [49] = "Apalis iMX8 QuadPlus 2GB",
110         [50] = "Colibri iMX8 QuadXPlus 2GB IT",
111         [51] = "Colibri iMX8 DualX 1GB Wi-Fi / Bluetooth",
112         [52] = "Colibri iMX8 DualX 1GB",
113 };
114
115 #ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_MMC
116 static int tdx_cfg_block_mmc_storage(u8 *config_block, int write)
117 {
118         struct mmc *mmc;
119         int dev = CONFIG_TDX_CFG_BLOCK_DEV;
120         int offset = CONFIG_TDX_CFG_BLOCK_OFFSET;
121         uint part = CONFIG_TDX_CFG_BLOCK_PART;
122         uint blk_start;
123         int ret = 0;
124
125         /* Read production parameter config block from eMMC */
126         mmc = find_mmc_device(dev);
127         if (!mmc) {
128                 puts("No MMC card found\n");
129                 ret = -ENODEV;
130                 goto out;
131         }
132         if (mmc_init(mmc)) {
133                 puts("MMC init failed\n");
134                 return -EINVAL;
135         }
136         if (part != mmc_get_blk_desc(mmc)->hwpart) {
137                 if (blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part)) {
138                         puts("MMC partition switch failed\n");
139                         ret = -ENODEV;
140                         goto out;
141                 }
142         }
143         if (offset < 0)
144                 offset += mmc->capacity;
145         blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
146
147         if (!write) {
148                 /* Careful reads a whole block of 512 bytes into config_block */
149                 if (blk_dread(mmc_get_blk_desc(mmc), blk_start, 1,
150                               (unsigned char *)config_block) != 1) {
151                         ret = -EIO;
152                         goto out;
153                 }
154         } else {
155                 /* Just writing one 512 byte block */
156                 if (blk_dwrite(mmc_get_blk_desc(mmc), blk_start, 1,
157                                (unsigned char *)config_block) != 1) {
158                         ret = -EIO;
159                         goto out;
160                 }
161         }
162
163 out:
164         /* Switch back to regular eMMC user partition */
165         blk_select_hwpart_devnum(IF_TYPE_MMC, 0, 0);
166
167         return ret;
168 }
169 #endif
170
171 #ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_NAND
172 static int read_tdx_cfg_block_from_nand(unsigned char *config_block)
173 {
174         size_t size = TDX_CFG_BLOCK_MAX_SIZE;
175         struct mtd_info *mtd = get_nand_dev_by_index(0);
176
177         if (!mtd)
178                 return -ENODEV;
179
180         /* Read production parameter config block from NAND page */
181         return nand_read_skip_bad(mtd, CONFIG_TDX_CFG_BLOCK_OFFSET,
182                                   &size, NULL, TDX_CFG_BLOCK_MAX_SIZE,
183                                   config_block);
184 }
185
186 static int write_tdx_cfg_block_to_nand(unsigned char *config_block)
187 {
188         size_t size = TDX_CFG_BLOCK_MAX_SIZE;
189
190         /* Write production parameter config block to NAND page */
191         return nand_write_skip_bad(get_nand_dev_by_index(0),
192                                    CONFIG_TDX_CFG_BLOCK_OFFSET,
193                                    &size, NULL, TDX_CFG_BLOCK_MAX_SIZE,
194                                    config_block, WITH_WR_VERIFY);
195 }
196 #endif
197
198 #ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_NOR
199 static int read_tdx_cfg_block_from_nor(unsigned char *config_block)
200 {
201         /* Read production parameter config block from NOR flash */
202         memcpy(config_block, (void *)CONFIG_TDX_CFG_BLOCK_OFFSET,
203                TDX_CFG_BLOCK_MAX_SIZE);
204         return 0;
205 }
206
207 static int write_tdx_cfg_block_to_nor(unsigned char *config_block)
208 {
209         /* Write production parameter config block to NOR flash */
210         return flash_write((void *)config_block, CONFIG_TDX_CFG_BLOCK_OFFSET,
211                            TDX_CFG_BLOCK_MAX_SIZE);
212 }
213 #endif
214
215 int read_tdx_cfg_block(void)
216 {
217         int ret = 0;
218         u8 *config_block = NULL;
219         struct toradex_tag *tag;
220         size_t size = TDX_CFG_BLOCK_MAX_SIZE;
221         int offset;
222
223         /* Allocate RAM area for config block */
224         config_block = memalign(ARCH_DMA_MINALIGN, size);
225         if (!config_block) {
226                 printf("Not enough malloc space available!\n");
227                 return -ENOMEM;
228         }
229
230         memset(config_block, 0, size);
231
232 #if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_MMC)
233         ret = tdx_cfg_block_mmc_storage(config_block, 0);
234 #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND)
235         ret = read_tdx_cfg_block_from_nand(config_block);
236 #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR)
237         ret = read_tdx_cfg_block_from_nor(config_block);
238 #else
239         ret = -EINVAL;
240 #endif
241         if (ret)
242                 goto out;
243
244         /* Expect a valid tag first */
245         tag = (struct toradex_tag *)config_block;
246         if (tag->flags != TAG_FLAG_VALID || tag->id != TAG_VALID) {
247                 valid_cfgblock = false;
248                 ret = -EINVAL;
249                 goto out;
250         }
251         valid_cfgblock = true;
252         offset = 4;
253
254         while (offset < TDX_CFG_BLOCK_MAX_SIZE) {
255                 tag = (struct toradex_tag *)(config_block + offset);
256                 offset += 4;
257                 if (tag->id == TAG_INVALID)
258                         break;
259
260                 if (tag->flags == TAG_FLAG_VALID) {
261                         switch (tag->id) {
262                         case TAG_MAC:
263                                 memcpy(&tdx_eth_addr, config_block + offset,
264                                        6);
265
266                                 /* NIC part of MAC address is serial number */
267                                 tdx_serial = ntohl(tdx_eth_addr.nic) >> 8;
268                                 break;
269                         case TAG_HW:
270                                 memcpy(&tdx_hw_tag, config_block + offset, 8);
271                                 break;
272                         }
273                 }
274
275                 /* Get to next tag according to current tags length */
276                 offset += tag->len * 4;
277         }
278
279         /* Cap product id to avoid issues with a yet unknown one */
280         if (tdx_hw_tag.prodid >= (sizeof(toradex_modules) /
281                                   sizeof(toradex_modules[0])))
282                 tdx_hw_tag.prodid = 0;
283
284 out:
285         free(config_block);
286         return ret;
287 }
288
289 static int get_cfgblock_interactive(void)
290 {
291         char message[CONFIG_SYS_CBSIZE];
292         char *soc;
293         char it = 'n';
294         int len;
295
296         /* Unknown module by default */
297         tdx_hw_tag.prodid = 0;
298
299         if (cpu_is_pxa27x())
300                 sprintf(message, "Is the module the 312 MHz version? [y/N] ");
301         else
302                 sprintf(message, "Is the module an IT version? [y/N] ");
303
304         len = cli_readline(message);
305         it = console_buffer[0];
306
307         soc = env_get("soc");
308         if (!strcmp("mx6", soc)) {
309 #ifdef CONFIG_TARGET_APALIS_IMX6
310                 if (it == 'y' || it == 'Y') {
311                         if (is_cpu_type(MXC_CPU_MX6Q))
312                                 tdx_hw_tag.prodid = APALIS_IMX6Q_IT;
313                         else
314                                 tdx_hw_tag.prodid = APALIS_IMX6D_IT;
315                 } else {
316                         if (is_cpu_type(MXC_CPU_MX6Q))
317                                 tdx_hw_tag.prodid = APALIS_IMX6Q;
318                         else
319                                 tdx_hw_tag.prodid = APALIS_IMX6D;
320                 }
321 #elif CONFIG_TARGET_COLIBRI_IMX6
322                 if (it == 'y' || it == 'Y') {
323                         if (is_cpu_type(MXC_CPU_MX6DL))
324                                 tdx_hw_tag.prodid = COLIBRI_IMX6DL_IT;
325                         else if (is_cpu_type(MXC_CPU_MX6SOLO))
326                                 tdx_hw_tag.prodid = COLIBRI_IMX6S_IT;
327                 } else {
328                         if (is_cpu_type(MXC_CPU_MX6DL))
329                                 tdx_hw_tag.prodid = COLIBRI_IMX6DL;
330                         else if (is_cpu_type(MXC_CPU_MX6SOLO))
331                                 tdx_hw_tag.prodid = COLIBRI_IMX6S;
332                 }
333 #elif CONFIG_TARGET_COLIBRI_IMX6ULL
334                 char wb = 'n';
335
336                 sprintf(message, "Does the module have Wi-Fi / Bluetooth? " \
337                                  "[y/N] ");
338                 len = cli_readline(message);
339                 wb = console_buffer[0];
340                 if (it == 'y' || it == 'Y') {
341                         if (wb == 'y' || wb == 'Y')
342                                 tdx_hw_tag.prodid = COLIBRI_IMX6ULL_WIFI_BT_IT;
343                         else
344                                 tdx_hw_tag.prodid = COLIBRI_IMX6ULL_IT;
345                 } else {
346                         if (wb == 'y' || wb == 'Y')
347                                 tdx_hw_tag.prodid = COLIBRI_IMX6ULL_WIFI_BT;
348                         else
349                                 tdx_hw_tag.prodid = COLIBRI_IMX6ULL;
350                 }
351 #endif
352         } else if (!strcmp("imx7d", soc))
353                 tdx_hw_tag.prodid = COLIBRI_IMX7D;
354         else if (!strcmp("imx7s", soc))
355                 tdx_hw_tag.prodid = COLIBRI_IMX7S;
356         else if (is_cpu_type(MXC_CPU_IMX8QXP))
357                 tdx_hw_tag.prodid = COLIBRI_IMX8QXP_WIFI_BT_IT;
358         else if (!strcmp("tegra20", soc)) {
359                 if (it == 'y' || it == 'Y')
360                         if (gd->ram_size == 0x10000000)
361                                 tdx_hw_tag.prodid = COLIBRI_T20_256MB_IT;
362                         else
363                                 tdx_hw_tag.prodid = COLIBRI_T20_512MB_IT;
364                 else
365                         if (gd->ram_size == 0x10000000)
366                                 tdx_hw_tag.prodid = COLIBRI_T20_256MB;
367                         else
368                                 tdx_hw_tag.prodid = COLIBRI_T20_512MB;
369         } else if (cpu_is_pxa27x()) {
370                 if (it == 'y' || it == 'Y')
371                         tdx_hw_tag.prodid = COLIBRI_PXA270_312MHZ;
372                 else
373                         tdx_hw_tag.prodid = COLIBRI_PXA270_520MHZ;
374         }
375 #ifdef CONFIG_MACH_TYPE
376         else if (!strcmp("tegra30", soc)) {
377                 if (CONFIG_MACH_TYPE == MACH_TYPE_APALIS_T30) {
378                         if (it == 'y' || it == 'Y')
379                                 tdx_hw_tag.prodid = APALIS_T30_IT;
380                         else
381                                 if (gd->ram_size == 0x40000000)
382                                         tdx_hw_tag.prodid = APALIS_T30_1GB;
383                                 else
384                                         tdx_hw_tag.prodid = APALIS_T30_2GB;
385                 } else {
386                         if (it == 'y' || it == 'Y')
387                                 tdx_hw_tag.prodid = COLIBRI_T30_IT;
388                         else
389                                 tdx_hw_tag.prodid = COLIBRI_T30;
390                 }
391         }
392 #endif /* CONFIG_MACH_TYPE */
393         else if (!strcmp("tegra124", soc)) {
394                 tdx_hw_tag.prodid = APALIS_TK1_2GB;
395         } else if (!strcmp("vf500", soc)) {
396                 if (it == 'y' || it == 'Y')
397                         tdx_hw_tag.prodid = COLIBRI_VF50_IT;
398                 else
399                         tdx_hw_tag.prodid = COLIBRI_VF50;
400         } else if (!strcmp("vf610", soc)) {
401                 if (it == 'y' || it == 'Y')
402                         tdx_hw_tag.prodid = COLIBRI_VF61_IT;
403                 else
404                         tdx_hw_tag.prodid = COLIBRI_VF61;
405         }
406
407         if (!tdx_hw_tag.prodid) {
408                 printf("Module type not detectable due to unknown SoC\n");
409                 return -1;
410         }
411
412         while (len < 4) {
413                 sprintf(message, "Enter the module version (e.g. V1.1B): V");
414                 len = cli_readline(message);
415         }
416
417         tdx_hw_tag.ver_major = console_buffer[0] - '0';
418         tdx_hw_tag.ver_minor = console_buffer[2] - '0';
419         tdx_hw_tag.ver_assembly = console_buffer[3] - 'A';
420
421         if (cpu_is_pxa27x() && tdx_hw_tag.ver_major == 1)
422                 tdx_hw_tag.prodid -= (COLIBRI_PXA270_312MHZ -
423                                        COLIBRI_PXA270_V1_312MHZ);
424
425         while (len < 8) {
426                 sprintf(message, "Enter module serial number: ");
427                 len = cli_readline(message);
428         }
429
430         tdx_serial = simple_strtoul(console_buffer, NULL, 10);
431
432         return 0;
433 }
434
435 static int get_cfgblock_barcode(char *barcode)
436 {
437         if (strlen(barcode) < 16) {
438                 printf("Argument too short, barcode is 16 chars long\n");
439                 return -1;
440         }
441
442         /* Get hardware information from the first 8 digits */
443         tdx_hw_tag.ver_major = barcode[4] - '0';
444         tdx_hw_tag.ver_minor = barcode[5] - '0';
445         tdx_hw_tag.ver_assembly = barcode[7] - '0';
446
447         barcode[4] = '\0';
448         tdx_hw_tag.prodid = simple_strtoul(barcode, NULL, 10);
449
450         /* Parse second part of the barcode (serial number */
451         barcode += 8;
452         tdx_serial = simple_strtoul(barcode, NULL, 10);
453
454         return 0;
455 }
456
457 static int do_cfgblock_create(cmd_tbl_t *cmdtp, int flag, int argc,
458                               char * const argv[])
459 {
460         u8 *config_block;
461         struct toradex_tag *tag;
462         size_t size = TDX_CFG_BLOCK_MAX_SIZE;
463         int offset = 0;
464         int ret = CMD_RET_SUCCESS;
465         int err;
466         int force_overwrite = 0;
467
468         /* Allocate RAM area for config block */
469         config_block = memalign(ARCH_DMA_MINALIGN, size);
470         if (!config_block) {
471                 printf("Not enough malloc space available!\n");
472                 return CMD_RET_FAILURE;
473         }
474
475         memset(config_block, 0xff, size);
476
477         if (argc >= 3) {
478                 if (argv[2][0] == '-' && argv[2][1] == 'y')
479                         force_overwrite = 1;
480         }
481
482         read_tdx_cfg_block();
483         if (valid_cfgblock) {
484 #if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND)
485                 /*
486                  * On NAND devices, recreation is only allowed if the page is
487                  * empty (config block invalid...)
488                  */
489                 printf("NAND erase block %d need to be erased before creating" \
490                        " a Toradex config block\n",
491                        CONFIG_TDX_CFG_BLOCK_OFFSET /
492                        get_nand_dev_by_index(0)->erasesize);
493                 goto out;
494 #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR)
495                 /*
496                  * On NOR devices, recreation is only allowed if the sector is
497                  * empty and write protection is off (config block invalid...)
498                  */
499                 printf("NOR sector at offset 0x%02x need to be erased and " \
500                        "unprotected before creating a Toradex config block\n",
501                        CONFIG_TDX_CFG_BLOCK_OFFSET);
502                 goto out;
503 #else
504                 if (!force_overwrite) {
505                         char message[CONFIG_SYS_CBSIZE];
506
507                         sprintf(message,
508                                 "A valid Toradex config block is present, still recreate? [y/N] ");
509
510                         if (!cli_readline(message))
511                                 goto out;
512
513                         if (console_buffer[0] != 'y' &&
514                             console_buffer[0] != 'Y')
515                                 goto out;
516                 }
517 #endif
518         }
519
520         /* Parse new Toradex config block data... */
521         if (argc < 3 || (force_overwrite && argc < 4)) {
522                 err = get_cfgblock_interactive();
523         } else {
524                 if (force_overwrite)
525                         err = get_cfgblock_barcode(argv[3]);
526                 else
527                         err = get_cfgblock_barcode(argv[2]);
528         }
529         if (err) {
530                 ret = CMD_RET_FAILURE;
531                 goto out;
532         }
533
534         /* Convert serial number to MAC address (the storage format) */
535         tdx_eth_addr.oui = htonl(0x00142dUL << 8);
536         tdx_eth_addr.nic = htonl(tdx_serial << 8);
537
538         /* Valid Tag */
539         tag = (struct toradex_tag *)config_block;
540         tag->id = TAG_VALID;
541         tag->flags = TAG_FLAG_VALID;
542         tag->len = 0;
543         offset += 4;
544
545         /* Product Tag */
546         tag = (struct toradex_tag *)(config_block + offset);
547         tag->id = TAG_HW;
548         tag->flags = TAG_FLAG_VALID;
549         tag->len = 2;
550         offset += 4;
551
552         memcpy(config_block + offset, &tdx_hw_tag, 8);
553         offset += 8;
554
555         /* MAC Tag */
556         tag = (struct toradex_tag *)(config_block + offset);
557         tag->id = TAG_MAC;
558         tag->flags = TAG_FLAG_VALID;
559         tag->len = 2;
560         offset += 4;
561
562         memcpy(config_block + offset, &tdx_eth_addr, 6);
563         offset += 6;
564         memset(config_block + offset, 0, 32 - offset);
565
566 #if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_MMC)
567         err = tdx_cfg_block_mmc_storage(config_block, 1);
568 #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND)
569         err = write_tdx_cfg_block_to_nand(config_block);
570 #elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR)
571         err = write_tdx_cfg_block_to_nor(config_block);
572 #else
573         err = -EINVAL;
574 #endif
575         if (err) {
576                 printf("Failed to write Toradex config block: %d\n", ret);
577                 ret = CMD_RET_FAILURE;
578                 goto out;
579         }
580
581         printf("Toradex config block successfully written\n");
582
583 out:
584         free(config_block);
585         return ret;
586 }
587
588 static int do_cfgblock(cmd_tbl_t *cmdtp, int flag, int argc,
589                        char * const argv[])
590 {
591         int ret;
592
593         if (argc < 2)
594                 return CMD_RET_USAGE;
595
596         if (!strcmp(argv[1], "create")) {
597                 return do_cfgblock_create(cmdtp, flag, argc, argv);
598         } else if (!strcmp(argv[1], "reload")) {
599                 ret = read_tdx_cfg_block();
600                 if (ret) {
601                         printf("Failed to reload Toradex config block: %d\n",
602                                ret);
603                         return CMD_RET_FAILURE;
604                 }
605                 return CMD_RET_SUCCESS;
606         }
607
608         return CMD_RET_USAGE;
609 }
610
611 U_BOOT_CMD(
612         cfgblock, 4, 0, do_cfgblock,
613         "Toradex config block handling commands",
614         "create [-y] [barcode] - (Re-)create Toradex config block\n"
615         "cfgblock reload - Reload Toradex config block from flash"
616 );