mxsboot.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /*
  2. * Freescale i.MX28 image generator
  3. *
  4. * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  5. * on behalf of DENX Software Engineering GmbH
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <fcntl.h>
  10. #include <sys/stat.h>
  11. #include <sys/types.h>
  12. #include <unistd.h>
  13. #include "compiler.h"
  14. /*
  15. * Default BCB layout.
  16. *
  17. * TWEAK this if you have blown any OCOTP fuses.
  18. */
  19. #define STRIDE_PAGES 64
  20. #define STRIDE_COUNT 4
  21. /*
  22. * Layout for 256Mb big NAND with 2048b page size, 64b OOB size and
  23. * 128kb erase size.
  24. *
  25. * TWEAK this if you have different kind of NAND chip.
  26. */
  27. static uint32_t nand_writesize = 2048;
  28. static uint32_t nand_oobsize = 64;
  29. static uint32_t nand_erasesize = 128 * 1024;
  30. /*
  31. * Sector on which the SigmaTel boot partition (0x53) starts.
  32. */
  33. static uint32_t sd_sector = 2048;
  34. /*
  35. * Each of the U-Boot bootstreams is at maximum 1MB big.
  36. *
  37. * TWEAK this if, for some wild reason, you need to boot bigger image.
  38. */
  39. #define MAX_BOOTSTREAM_SIZE (1 * 1024 * 1024)
  40. /* i.MX28 NAND controller-specific constants. DO NOT TWEAK! */
  41. #define MXS_NAND_DMA_DESCRIPTOR_COUNT 4
  42. #define MXS_NAND_CHUNK_DATA_CHUNK_SIZE 512
  43. #define MXS_NAND_METADATA_SIZE 10
  44. #define MXS_NAND_COMMAND_BUFFER_SIZE 32
  45. struct mx28_nand_fcb {
  46. uint32_t checksum;
  47. uint32_t fingerprint;
  48. uint32_t version;
  49. struct {
  50. uint8_t data_setup;
  51. uint8_t data_hold;
  52. uint8_t address_setup;
  53. uint8_t dsample_time;
  54. uint8_t nand_timing_state;
  55. uint8_t rea;
  56. uint8_t rloh;
  57. uint8_t rhoh;
  58. } timing;
  59. uint32_t page_data_size;
  60. uint32_t total_page_size;
  61. uint32_t sectors_per_block;
  62. uint32_t number_of_nands; /* Ignored */
  63. uint32_t total_internal_die; /* Ignored */
  64. uint32_t cell_type; /* Ignored */
  65. uint32_t ecc_block_n_ecc_type;
  66. uint32_t ecc_block_0_size;
  67. uint32_t ecc_block_n_size;
  68. uint32_t ecc_block_0_ecc_type;
  69. uint32_t metadata_bytes;
  70. uint32_t num_ecc_blocks_per_page;
  71. uint32_t ecc_block_n_ecc_level_sdk; /* Ignored */
  72. uint32_t ecc_block_0_size_sdk; /* Ignored */
  73. uint32_t ecc_block_n_size_sdk; /* Ignored */
  74. uint32_t ecc_block_0_ecc_level_sdk; /* Ignored */
  75. uint32_t num_ecc_blocks_per_page_sdk; /* Ignored */
  76. uint32_t metadata_bytes_sdk; /* Ignored */
  77. uint32_t erase_threshold;
  78. uint32_t boot_patch;
  79. uint32_t patch_sectors;
  80. uint32_t firmware1_starting_sector;
  81. uint32_t firmware2_starting_sector;
  82. uint32_t sectors_in_firmware1;
  83. uint32_t sectors_in_firmware2;
  84. uint32_t dbbt_search_area_start_address;
  85. uint32_t badblock_marker_byte;
  86. uint32_t badblock_marker_start_bit;
  87. uint32_t bb_marker_physical_offset;
  88. };
  89. struct mx28_nand_dbbt {
  90. uint32_t checksum;
  91. uint32_t fingerprint;
  92. uint32_t version;
  93. uint32_t number_bb;
  94. uint32_t number_2k_pages_bb;
  95. };
  96. struct mx28_nand_bbt {
  97. uint32_t nand;
  98. uint32_t number_bb;
  99. uint32_t badblock[510];
  100. };
  101. struct mx28_sd_drive_info {
  102. uint32_t chip_num;
  103. uint32_t drive_type;
  104. uint32_t tag;
  105. uint32_t first_sector_number;
  106. uint32_t sector_count;
  107. };
  108. struct mx28_sd_config_block {
  109. uint32_t signature;
  110. uint32_t primary_boot_tag;
  111. uint32_t secondary_boot_tag;
  112. uint32_t num_copies;
  113. struct mx28_sd_drive_info drv_info[1];
  114. };
  115. static inline uint32_t mx28_nand_ecc_size_in_bits(uint32_t ecc_strength)
  116. {
  117. return ecc_strength * 13;
  118. }
  119. static inline uint32_t mx28_nand_get_ecc_strength(uint32_t page_data_size,
  120. uint32_t page_oob_size)
  121. {
  122. if (page_data_size == 2048)
  123. return 8;
  124. if (page_data_size == 4096) {
  125. if (page_oob_size == 128)
  126. return 8;
  127. if (page_oob_size == 218)
  128. return 16;
  129. if (page_oob_size == 224)
  130. return 16;
  131. }
  132. return 0;
  133. }
  134. static inline uint32_t mx28_nand_get_mark_offset(uint32_t page_data_size,
  135. uint32_t ecc_strength)
  136. {
  137. uint32_t chunk_data_size_in_bits;
  138. uint32_t chunk_ecc_size_in_bits;
  139. uint32_t chunk_total_size_in_bits;
  140. uint32_t block_mark_chunk_number;
  141. uint32_t block_mark_chunk_bit_offset;
  142. uint32_t block_mark_bit_offset;
  143. chunk_data_size_in_bits = MXS_NAND_CHUNK_DATA_CHUNK_SIZE * 8;
  144. chunk_ecc_size_in_bits = mx28_nand_ecc_size_in_bits(ecc_strength);
  145. chunk_total_size_in_bits =
  146. chunk_data_size_in_bits + chunk_ecc_size_in_bits;
  147. /* Compute the bit offset of the block mark within the physical page. */
  148. block_mark_bit_offset = page_data_size * 8;
  149. /* Subtract the metadata bits. */
  150. block_mark_bit_offset -= MXS_NAND_METADATA_SIZE * 8;
  151. /*
  152. * Compute the chunk number (starting at zero) in which the block mark
  153. * appears.
  154. */
  155. block_mark_chunk_number =
  156. block_mark_bit_offset / chunk_total_size_in_bits;
  157. /*
  158. * Compute the bit offset of the block mark within its chunk, and
  159. * validate it.
  160. */
  161. block_mark_chunk_bit_offset = block_mark_bit_offset -
  162. (block_mark_chunk_number * chunk_total_size_in_bits);
  163. if (block_mark_chunk_bit_offset > chunk_data_size_in_bits)
  164. return 1;
  165. /*
  166. * Now that we know the chunk number in which the block mark appears,
  167. * we can subtract all the ECC bits that appear before it.
  168. */
  169. block_mark_bit_offset -=
  170. block_mark_chunk_number * chunk_ecc_size_in_bits;
  171. return block_mark_bit_offset;
  172. }
  173. static inline uint32_t mx28_nand_mark_byte_offset(void)
  174. {
  175. uint32_t ecc_strength;
  176. ecc_strength = mx28_nand_get_ecc_strength(nand_writesize, nand_oobsize);
  177. return mx28_nand_get_mark_offset(nand_writesize, ecc_strength) >> 3;
  178. }
  179. static inline uint32_t mx28_nand_mark_bit_offset(void)
  180. {
  181. uint32_t ecc_strength;
  182. ecc_strength = mx28_nand_get_ecc_strength(nand_writesize, nand_oobsize);
  183. return mx28_nand_get_mark_offset(nand_writesize, ecc_strength) & 0x7;
  184. }
  185. static uint32_t mx28_nand_block_csum(uint8_t *block, uint32_t size)
  186. {
  187. uint32_t csum = 0;
  188. int i;
  189. for (i = 0; i < size; i++)
  190. csum += block[i];
  191. return csum ^ 0xffffffff;
  192. }
  193. static struct mx28_nand_fcb *mx28_nand_get_fcb(uint32_t size)
  194. {
  195. struct mx28_nand_fcb *fcb;
  196. uint32_t bcb_size_bytes;
  197. uint32_t stride_size_bytes;
  198. uint32_t bootstream_size_pages;
  199. uint32_t fw1_start_page;
  200. uint32_t fw2_start_page;
  201. fcb = malloc(nand_writesize);
  202. if (!fcb) {
  203. printf("MX28 NAND: Unable to allocate FCB\n");
  204. return NULL;
  205. }
  206. memset(fcb, 0, nand_writesize);
  207. fcb->fingerprint = 0x20424346;
  208. fcb->version = 0x01000000;
  209. /*
  210. * FIXME: These here are default values as found in kobs-ng. We should
  211. * probably retrieve the data from NAND or something.
  212. */
  213. fcb->timing.data_setup = 80;
  214. fcb->timing.data_hold = 60;
  215. fcb->timing.address_setup = 25;
  216. fcb->timing.dsample_time = 6;
  217. fcb->page_data_size = nand_writesize;
  218. fcb->total_page_size = nand_writesize + nand_oobsize;
  219. fcb->sectors_per_block = nand_erasesize / nand_writesize;
  220. fcb->num_ecc_blocks_per_page = (nand_writesize / 512) - 1;
  221. fcb->ecc_block_0_size = 512;
  222. fcb->ecc_block_n_size = 512;
  223. fcb->metadata_bytes = 10;
  224. if (nand_writesize == 2048) {
  225. fcb->ecc_block_n_ecc_type = 4;
  226. fcb->ecc_block_0_ecc_type = 4;
  227. } else if (nand_writesize == 4096) {
  228. if (nand_oobsize == 128) {
  229. fcb->ecc_block_n_ecc_type = 4;
  230. fcb->ecc_block_0_ecc_type = 4;
  231. } else if (nand_oobsize == 218) {
  232. fcb->ecc_block_n_ecc_type = 8;
  233. fcb->ecc_block_0_ecc_type = 8;
  234. } else if (nand_oobsize == 224) {
  235. fcb->ecc_block_n_ecc_type = 8;
  236. fcb->ecc_block_0_ecc_type = 8;
  237. }
  238. }
  239. if (fcb->ecc_block_n_ecc_type == 0) {
  240. printf("MX28 NAND: Unsupported NAND geometry\n");
  241. goto err;
  242. }
  243. fcb->boot_patch = 0;
  244. fcb->patch_sectors = 0;
  245. fcb->badblock_marker_byte = mx28_nand_mark_byte_offset();
  246. fcb->badblock_marker_start_bit = mx28_nand_mark_bit_offset();
  247. fcb->bb_marker_physical_offset = nand_writesize;
  248. stride_size_bytes = STRIDE_PAGES * nand_writesize;
  249. bcb_size_bytes = stride_size_bytes * STRIDE_COUNT;
  250. bootstream_size_pages = (size + (nand_writesize - 1)) /
  251. nand_writesize;
  252. fw1_start_page = 2 * bcb_size_bytes / nand_writesize;
  253. fw2_start_page = (2 * bcb_size_bytes + MAX_BOOTSTREAM_SIZE) /
  254. nand_writesize;
  255. fcb->firmware1_starting_sector = fw1_start_page;
  256. fcb->firmware2_starting_sector = fw2_start_page;
  257. fcb->sectors_in_firmware1 = bootstream_size_pages;
  258. fcb->sectors_in_firmware2 = bootstream_size_pages;
  259. fcb->dbbt_search_area_start_address = STRIDE_PAGES * STRIDE_COUNT;
  260. return fcb;
  261. err:
  262. free(fcb);
  263. return NULL;
  264. }
  265. static struct mx28_nand_dbbt *mx28_nand_get_dbbt(void)
  266. {
  267. struct mx28_nand_dbbt *dbbt;
  268. dbbt = malloc(nand_writesize);
  269. if (!dbbt) {
  270. printf("MX28 NAND: Unable to allocate DBBT\n");
  271. return NULL;
  272. }
  273. memset(dbbt, 0, nand_writesize);
  274. dbbt->fingerprint = 0x54424244;
  275. dbbt->version = 0x1;
  276. return dbbt;
  277. }
  278. static inline uint8_t mx28_nand_parity_13_8(const uint8_t b)
  279. {
  280. uint32_t parity = 0, tmp;
  281. tmp = ((b >> 6) ^ (b >> 5) ^ (b >> 3) ^ (b >> 2)) & 1;
  282. parity |= tmp << 0;
  283. tmp = ((b >> 7) ^ (b >> 5) ^ (b >> 4) ^ (b >> 2) ^ (b >> 1)) & 1;
  284. parity |= tmp << 1;
  285. tmp = ((b >> 7) ^ (b >> 6) ^ (b >> 5) ^ (b >> 1) ^ (b >> 0)) & 1;
  286. parity |= tmp << 2;
  287. tmp = ((b >> 7) ^ (b >> 4) ^ (b >> 3) ^ (b >> 0)) & 1;
  288. parity |= tmp << 3;
  289. tmp = ((b >> 6) ^ (b >> 4) ^ (b >> 3) ^
  290. (b >> 2) ^ (b >> 1) ^ (b >> 0)) & 1;
  291. parity |= tmp << 4;
  292. return parity;
  293. }
  294. static uint8_t *mx28_nand_fcb_block(struct mx28_nand_fcb *fcb)
  295. {
  296. uint8_t *block;
  297. uint8_t *ecc;
  298. int i;
  299. block = malloc(nand_writesize + nand_oobsize);
  300. if (!block) {
  301. printf("MX28 NAND: Unable to allocate FCB block\n");
  302. return NULL;
  303. }
  304. memset(block, 0, nand_writesize + nand_oobsize);
  305. /* Update the FCB checksum */
  306. fcb->checksum = mx28_nand_block_csum(((uint8_t *)fcb) + 4, 508);
  307. /* Figure 12-11. in iMX28RM, rev. 1, says FCB is at offset 12 */
  308. memcpy(block + 12, fcb, sizeof(struct mx28_nand_fcb));
  309. /* ECC is at offset 12 + 512 */
  310. ecc = block + 12 + 512;
  311. /* Compute the ECC parity */
  312. for (i = 0; i < sizeof(struct mx28_nand_fcb); i++)
  313. ecc[i] = mx28_nand_parity_13_8(block[i + 12]);
  314. return block;
  315. }
  316. static int mx28_nand_write_fcb(struct mx28_nand_fcb *fcb, uint8_t *buf)
  317. {
  318. uint32_t offset;
  319. uint8_t *fcbblock;
  320. int ret = 0;
  321. int i;
  322. fcbblock = mx28_nand_fcb_block(fcb);
  323. if (!fcbblock)
  324. return -1;
  325. for (i = 0; i < STRIDE_PAGES * STRIDE_COUNT; i += STRIDE_PAGES) {
  326. offset = i * nand_writesize;
  327. memcpy(buf + offset, fcbblock, nand_writesize + nand_oobsize);
  328. /* Mark the NAND page is OK. */
  329. buf[offset + nand_writesize] = 0xff;
  330. }
  331. free(fcbblock);
  332. return ret;
  333. }
  334. static int mx28_nand_write_dbbt(struct mx28_nand_dbbt *dbbt, uint8_t *buf)
  335. {
  336. uint32_t offset;
  337. int i = STRIDE_PAGES * STRIDE_COUNT;
  338. for (; i < 2 * STRIDE_PAGES * STRIDE_COUNT; i += STRIDE_PAGES) {
  339. offset = i * nand_writesize;
  340. memcpy(buf + offset, dbbt, sizeof(struct mx28_nand_dbbt));
  341. }
  342. return 0;
  343. }
  344. static int mx28_nand_write_firmware(struct mx28_nand_fcb *fcb, int infd,
  345. uint8_t *buf)
  346. {
  347. int ret;
  348. off_t size;
  349. uint32_t offset1, offset2;
  350. size = lseek(infd, 0, SEEK_END);
  351. lseek(infd, 0, SEEK_SET);
  352. offset1 = fcb->firmware1_starting_sector * nand_writesize;
  353. offset2 = fcb->firmware2_starting_sector * nand_writesize;
  354. ret = read(infd, buf + offset1, size);
  355. if (ret != size)
  356. return -1;
  357. memcpy(buf + offset2, buf + offset1, size);
  358. return 0;
  359. }
  360. static void usage(void)
  361. {
  362. printf(
  363. "Usage: mxsboot [ops] <type> <infile> <outfile>\n"
  364. "Augment BootStream file with a proper header for i.MX28 boot\n"
  365. "\n"
  366. " <type> type of image:\n"
  367. " \"nand\" for NAND image\n"
  368. " \"sd\" for SD image\n"
  369. " <infile> input file, the u-boot.sb bootstream\n"
  370. " <outfile> output file, the bootable image\n"
  371. "\n");
  372. printf(
  373. "For NAND boot, these options are accepted:\n"
  374. " -w <size> NAND page size\n"
  375. " -o <size> NAND OOB size\n"
  376. " -e <size> NAND erase size\n"
  377. "\n"
  378. "For SD boot, these options are accepted:\n"
  379. " -p <sector> Sector where the SGTL partition starts\n"
  380. );
  381. }
  382. static int mx28_create_nand_image(int infd, int outfd)
  383. {
  384. struct mx28_nand_fcb *fcb;
  385. struct mx28_nand_dbbt *dbbt;
  386. int ret = -1;
  387. uint8_t *buf;
  388. int size;
  389. ssize_t wr_size;
  390. size = nand_writesize * 512 + 2 * MAX_BOOTSTREAM_SIZE;
  391. buf = malloc(size);
  392. if (!buf) {
  393. printf("Can not allocate output buffer of %d bytes\n", size);
  394. goto err0;
  395. }
  396. memset(buf, 0, size);
  397. fcb = mx28_nand_get_fcb(MAX_BOOTSTREAM_SIZE);
  398. if (!fcb) {
  399. printf("Unable to compile FCB\n");
  400. goto err1;
  401. }
  402. dbbt = mx28_nand_get_dbbt();
  403. if (!dbbt) {
  404. printf("Unable to compile DBBT\n");
  405. goto err2;
  406. }
  407. ret = mx28_nand_write_fcb(fcb, buf);
  408. if (ret) {
  409. printf("Unable to write FCB to buffer\n");
  410. goto err3;
  411. }
  412. ret = mx28_nand_write_dbbt(dbbt, buf);
  413. if (ret) {
  414. printf("Unable to write DBBT to buffer\n");
  415. goto err3;
  416. }
  417. ret = mx28_nand_write_firmware(fcb, infd, buf);
  418. if (ret) {
  419. printf("Unable to write firmware to buffer\n");
  420. goto err3;
  421. }
  422. wr_size = write(outfd, buf, size);
  423. if (wr_size != size) {
  424. ret = -1;
  425. goto err3;
  426. }
  427. ret = 0;
  428. err3:
  429. free(dbbt);
  430. err2:
  431. free(fcb);
  432. err1:
  433. free(buf);
  434. err0:
  435. return ret;
  436. }
  437. static int mx28_create_sd_image(int infd, int outfd)
  438. {
  439. int ret = -1;
  440. uint32_t *buf;
  441. int size;
  442. off_t fsize;
  443. ssize_t wr_size;
  444. struct mx28_sd_config_block *cb;
  445. fsize = lseek(infd, 0, SEEK_END);
  446. lseek(infd, 0, SEEK_SET);
  447. size = fsize + 4 * 512;
  448. buf = malloc(size);
  449. if (!buf) {
  450. printf("Can not allocate output buffer of %d bytes\n", size);
  451. goto err0;
  452. }
  453. ret = read(infd, (uint8_t *)buf + 4 * 512, fsize);
  454. if (ret != fsize) {
  455. ret = -1;
  456. goto err1;
  457. }
  458. cb = (struct mx28_sd_config_block *)buf;
  459. cb->signature = 0x00112233;
  460. cb->primary_boot_tag = 0x1;
  461. cb->secondary_boot_tag = 0x1;
  462. cb->num_copies = 1;
  463. cb->drv_info[0].chip_num = 0x0;
  464. cb->drv_info[0].drive_type = 0x0;
  465. cb->drv_info[0].tag = 0x1;
  466. cb->drv_info[0].first_sector_number = sd_sector + 4;
  467. cb->drv_info[0].sector_count = (size - 4) / 512;
  468. wr_size = write(outfd, buf, size);
  469. if (wr_size != size) {
  470. ret = -1;
  471. goto err1;
  472. }
  473. ret = 0;
  474. err1:
  475. free(buf);
  476. err0:
  477. return ret;
  478. }
  479. static int parse_ops(int argc, char **argv)
  480. {
  481. int i;
  482. int tmp;
  483. char *end;
  484. enum param {
  485. PARAM_WRITE,
  486. PARAM_OOB,
  487. PARAM_ERASE,
  488. PARAM_PART,
  489. PARAM_SD,
  490. PARAM_NAND
  491. };
  492. int type;
  493. if (argc < 4)
  494. return -1;
  495. for (i = 1; i < argc; i++) {
  496. if (!strncmp(argv[i], "-w", 2))
  497. type = PARAM_WRITE;
  498. else if (!strncmp(argv[i], "-o", 2))
  499. type = PARAM_OOB;
  500. else if (!strncmp(argv[i], "-e", 2))
  501. type = PARAM_ERASE;
  502. else if (!strncmp(argv[i], "-p", 2))
  503. type = PARAM_PART;
  504. else /* SD/MMC */
  505. break;
  506. tmp = strtol(argv[++i], &end, 10);
  507. if (tmp % 2)
  508. return -1;
  509. if (tmp <= 0)
  510. return -1;
  511. if (type == PARAM_WRITE)
  512. nand_writesize = tmp;
  513. if (type == PARAM_OOB)
  514. nand_oobsize = tmp;
  515. if (type == PARAM_ERASE)
  516. nand_erasesize = tmp;
  517. if (type == PARAM_PART)
  518. sd_sector = tmp;
  519. }
  520. if (strcmp(argv[i], "sd") && strcmp(argv[i], "nand"))
  521. return -1;
  522. if (i + 3 != argc)
  523. return -1;
  524. return i;
  525. }
  526. int main(int argc, char **argv)
  527. {
  528. int infd, outfd;
  529. int ret = 0;
  530. int offset;
  531. offset = parse_ops(argc, argv);
  532. if (offset < 0) {
  533. usage();
  534. ret = 1;
  535. goto err1;
  536. }
  537. infd = open(argv[offset + 1], O_RDONLY);
  538. if (infd < 0) {
  539. printf("Input BootStream file can not be opened\n");
  540. ret = 2;
  541. goto err1;
  542. }
  543. outfd = open(argv[offset + 2], O_CREAT | O_TRUNC | O_WRONLY,
  544. S_IRUSR | S_IWUSR);
  545. if (outfd < 0) {
  546. printf("Output file can not be created\n");
  547. ret = 3;
  548. goto err2;
  549. }
  550. if (!strcmp(argv[offset], "sd"))
  551. ret = mx28_create_sd_image(infd, outfd);
  552. else if (!strcmp(argv[offset], "nand"))
  553. ret = mx28_create_nand_image(infd, outfd);
  554. close(outfd);
  555. err2:
  556. close(infd);
  557. err1:
  558. return ret;
  559. }