Lines Matching +full:nand +full:- +full:oob +full:- +full:sector +full:- +full:size
1 // SPDX-License-Identifier: GPL-2.0+
17 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
29 * Layout for 256Mb big NAND with 2048b page size, 64b OOB size and
30 * 128kb erase size.
32 * TWEAK this if you have different kind of NAND chip.
39 * Sector on which the SigmaTel boot partition (0x53) starts.
44 * Each of the U-Boot bootstreams is at maximum 1MB big.
50 /* i.MX28 NAND controller-specific constants. DO NOT TWEAK! */
111 uint32_t nand; member
153 * (page oob size - meta data size) * (bits per byte) in mx28_nand_get_ecc_strength()
155 ecc_strength = ((page_oob_size - MXS_NAND_METADATA_SIZE) * 8) in mx28_nand_get_ecc_strength()
182 block_mark_bit_offset -= MXS_NAND_METADATA_SIZE * 8; in mx28_nand_get_mark_offset()
195 block_mark_chunk_bit_offset = block_mark_bit_offset - in mx28_nand_get_mark_offset()
205 block_mark_bit_offset -= in mx28_nand_get_mark_offset()
225 static uint32_t mx28_nand_block_csum(uint8_t *block, uint32_t size) in mx28_nand_block_csum() argument
230 for (i = 0; i < size; i++) in mx28_nand_block_csum()
236 static struct mx28_nand_fcb *mx28_nand_get_fcb(uint32_t size) in mx28_nand_get_fcb() argument
247 printf("MX28 NAND: Unable to allocate FCB\n"); in mx28_nand_get_fcb()
253 fcb->fingerprint = 0x20424346; in mx28_nand_get_fcb()
254 fcb->version = 0x01000000; in mx28_nand_get_fcb()
257 * FIXME: These here are default values as found in kobs-ng. We should in mx28_nand_get_fcb()
258 * probably retrieve the data from NAND or something. in mx28_nand_get_fcb()
260 fcb->timing.data_setup = 80; in mx28_nand_get_fcb()
261 fcb->timing.data_hold = 60; in mx28_nand_get_fcb()
262 fcb->timing.address_setup = 25; in mx28_nand_get_fcb()
263 fcb->timing.dsample_time = 6; in mx28_nand_get_fcb()
265 fcb->page_data_size = nand_writesize; in mx28_nand_get_fcb()
266 fcb->total_page_size = nand_writesize + nand_oobsize; in mx28_nand_get_fcb()
267 fcb->sectors_per_block = nand_erasesize / nand_writesize; in mx28_nand_get_fcb()
269 fcb->num_ecc_blocks_per_page = (nand_writesize / 512) - 1; in mx28_nand_get_fcb()
270 fcb->ecc_block_0_size = 512; in mx28_nand_get_fcb()
271 fcb->ecc_block_n_size = 512; in mx28_nand_get_fcb()
272 fcb->metadata_bytes = 10; in mx28_nand_get_fcb()
273 fcb->ecc_block_n_ecc_type = mx28_nand_get_ecc_strength( in mx28_nand_get_fcb()
275 fcb->ecc_block_0_ecc_type = mx28_nand_get_ecc_strength( in mx28_nand_get_fcb()
277 if (fcb->ecc_block_n_ecc_type == 0) { in mx28_nand_get_fcb()
278 printf("MX28 NAND: Unsupported NAND geometry\n"); in mx28_nand_get_fcb()
282 fcb->boot_patch = 0; in mx28_nand_get_fcb()
283 fcb->patch_sectors = 0; in mx28_nand_get_fcb()
285 fcb->badblock_marker_byte = mx28_nand_mark_byte_offset(); in mx28_nand_get_fcb()
286 fcb->badblock_marker_start_bit = mx28_nand_mark_bit_offset(); in mx28_nand_get_fcb()
287 fcb->bb_marker_physical_offset = nand_writesize; in mx28_nand_get_fcb()
292 bootstream_size_pages = (size + (nand_writesize - 1)) / in mx28_nand_get_fcb()
299 fcb->firmware1_starting_sector = fw1_start_page; in mx28_nand_get_fcb()
300 fcb->firmware2_starting_sector = fw2_start_page; in mx28_nand_get_fcb()
301 fcb->sectors_in_firmware1 = bootstream_size_pages; in mx28_nand_get_fcb()
302 fcb->sectors_in_firmware2 = bootstream_size_pages; in mx28_nand_get_fcb()
304 fcb->dbbt_search_area_start_address = STRIDE_PAGES * STRIDE_COUNT; in mx28_nand_get_fcb()
319 printf("MX28 NAND: Unable to allocate DBBT\n"); in mx28_nand_get_dbbt()
325 dbbt->fingerprint = 0x54424244; in mx28_nand_get_dbbt()
326 dbbt->version = 0x1; in mx28_nand_get_dbbt()
362 printf("MX28 NAND: Unable to allocate FCB block\n"); in mx28_nand_fcb_block()
369 fcb->checksum = mx28_nand_block_csum(((uint8_t *)fcb) + 4, 508); in mx28_nand_fcb_block()
371 /* Figure 12-11. in iMX28RM, rev. 1, says FCB is at offset 12 */ in mx28_nand_fcb_block()
393 return -1; in mx28_nand_write_fcb()
398 /* Mark the NAND page is OK. */ in mx28_nand_write_fcb()
423 off_t size; in mx28_nand_write_firmware() local
426 size = lseek(infd, 0, SEEK_END); in mx28_nand_write_firmware()
429 offset1 = fcb->firmware1_starting_sector * nand_writesize; in mx28_nand_write_firmware()
430 offset2 = fcb->firmware2_starting_sector * nand_writesize; in mx28_nand_write_firmware()
432 ret = read(infd, buf + offset1, size); in mx28_nand_write_firmware()
433 if (ret != size) in mx28_nand_write_firmware()
434 return -1; in mx28_nand_write_firmware()
436 memcpy(buf + offset2, buf + offset1, size); in mx28_nand_write_firmware()
448 " \"nand\" for NAND image\n" in usage()
450 " <infile> input file, the u-boot.sb bootstream\n" in usage()
454 "For NAND boot, these options are accepted:\n" in usage()
455 " -w <size> NAND page size\n" in usage()
456 " -o <size> NAND OOB size\n" in usage()
457 " -e <size> NAND erase size\n" in usage()
460 " -p <sector> Sector where the SGTL partition starts\n" in usage()
468 int ret = -1; in mx28_create_nand_image()
470 int size; in mx28_create_nand_image() local
473 size = nand_writesize * 512 + 2 * MAX_BOOTSTREAM_SIZE; in mx28_create_nand_image()
475 buf = malloc(size); in mx28_create_nand_image()
477 printf("Can not allocate output buffer of %d bytes\n", size); in mx28_create_nand_image()
481 memset(buf, 0, size); in mx28_create_nand_image()
513 wr_size = write(outfd, buf, size); in mx28_create_nand_image()
514 if (wr_size != size) { in mx28_create_nand_image()
515 ret = -1; in mx28_create_nand_image()
533 int ret = -1; in mx28_create_sd_image()
535 int size; in mx28_create_sd_image() local
542 size = fsize + 4 * 512; in mx28_create_sd_image()
544 buf = malloc(size); in mx28_create_sd_image()
546 printf("Can not allocate output buffer of %d bytes\n", size); in mx28_create_sd_image()
552 ret = -1; in mx28_create_sd_image()
558 cb->signature = cpu_to_le32(0x00112233); in mx28_create_sd_image()
559 cb->primary_boot_tag = cpu_to_le32(0x1); in mx28_create_sd_image()
560 cb->secondary_boot_tag = cpu_to_le32(0x1); in mx28_create_sd_image()
561 cb->num_copies = cpu_to_le32(1); in mx28_create_sd_image()
562 cb->drv_info[0].chip_num = cpu_to_le32(0x0); in mx28_create_sd_image()
563 cb->drv_info[0].drive_type = cpu_to_le32(0x0); in mx28_create_sd_image()
564 cb->drv_info[0].tag = cpu_to_le32(0x1); in mx28_create_sd_image()
565 cb->drv_info[0].first_sector_number = cpu_to_le32(sd_sector + 4); in mx28_create_sd_image()
566 cb->drv_info[0].sector_count = cpu_to_le32((size - 4) / 512); in mx28_create_sd_image()
568 wr_size = write(outfd, buf, size); in mx28_create_sd_image()
569 if (wr_size != size) { in mx28_create_sd_image()
570 ret = -1; in mx28_create_sd_image()
598 return -1; in parse_ops()
601 if (!strncmp(argv[i], "-w", 2)) in parse_ops()
603 else if (!strncmp(argv[i], "-o", 2)) in parse_ops()
605 else if (!strncmp(argv[i], "-e", 2)) in parse_ops()
607 else if (!strncmp(argv[i], "-p", 2)) in parse_ops()
614 return -1; in parse_ops()
616 return -1; in parse_ops()
628 if (strcmp(argv[i], "sd") && strcmp(argv[i], "nand")) in parse_ops()
629 return -1; in parse_ops()
632 return -1; in parse_ops()
667 else if (!strcmp(argv[offset], "nand")) in main()