Lines Matching +full:use +full:- +full:advanced +full:- +full:sector +full:- +full:protection
1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2002-2004
34 * U-Boot.
41 * JEDEC Standard JESD68 - Common Flash Interface (CFI)
42 * JEDEC Standard JEP137-A Common Flash Interface (CFI) ID Codes
44 * Intel 290667-008 3 Volt Intel StrataFlash Memory datasheet
46 * AMD/Spansion Application Note: Migration from Single-byte to Three-byte
177 /*-----------------------------------------------------------------------
188 if (info->size && info->start[0] <= base && in flash_get_info()
189 base <= info->start[0] + info->size - 1) in flash_get_info()
199 if (sect != (info->sector_count - 1)) in flash_sector_size()
200 return info->start[sect + 1] - info->start[sect]; in flash_sector_size()
202 return info->start[0] + info->size - info->start[sect]; in flash_sector_size()
205 /*-----------------------------------------------------------------------
211 unsigned int byte_offset = offset * info->portwidth; in flash_map()
213 return (void *)(info->start[sect] + byte_offset); in flash_map()
221 /*-----------------------------------------------------------------------
235 for (i = info->portwidth; i > 0; i--) { in flash_make_cmd()
236 cword_offset = (info->portwidth - i) % info->chipwidth; in flash_make_cmd()
238 cp_offset = info->portwidth - i; in flash_make_cmd()
241 cp_offset = i - 1; in flash_make_cmd()
242 val = *((uchar *)&cmd + sizeof(u32) - cword_offset - 1); in flash_make_cmd()
249 /*-----------------------------------------------------------------------
285 /*-----------------------------------------------------------------------
297 retval = flash_read8(cp + info->portwidth - 1); in flash_read_uchar()
303 /*-----------------------------------------------------------------------
316 /*-----------------------------------------------------------------------
332 debug("long addr is at %p info->portwidth = %d\n", addr, in flash_read_long()
333 info->portwidth); in flash_read_long()
334 for (x = 0; x < 4 * info->portwidth; x++) in flash_read_long()
339 (flash_read8(addr + info->portwidth) << 24) | in flash_read_long()
340 (flash_read8(addr + 2 * info->portwidth)) | in flash_read_long()
341 (flash_read8(addr + 3 * info->portwidth) << 8)); in flash_read_long()
343 retval = ((flash_read8(addr + 2 * info->portwidth - 1) << 24) | in flash_read_long()
344 (flash_read8(addr + info->portwidth - 1) << 16) | in flash_read_long()
345 (flash_read8(addr + 4 * info->portwidth - 1) << 8) | in flash_read_long()
346 (flash_read8(addr + 3 * info->portwidth - 1))); in flash_read_long()
364 switch (info->portwidth) { in flash_write_cmd()
367 cword.w8, info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_write_cmd()
373 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_write_cmd()
379 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_write_cmd()
391 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_write_cmd()
406 flash_write_cmd(info, sect, info->addr_unlock1, AMD_CMD_UNLOCK_START); in flash_unlock_seq()
407 flash_write_cmd(info, sect, info->addr_unlock2, AMD_CMD_UNLOCK_ACK); in flash_unlock_seq()
410 /*-----------------------------------------------------------------------
423 switch (info->portwidth) { in flash_isequal()
458 /*-----------------------------------------------------------------------
469 switch (info->portwidth) { in flash_isset()
491 /*-----------------------------------------------------------------------
502 switch (info->portwidth) { in flash_toggle()
526 * flash_is_busy - check to see if the flash is busy
535 switch (info->vendor) { in flash_is_busy()
546 if (info->sr_supported) { in flash_is_busy()
547 flash_write_cmd(info, sect, info->addr_unlock1, in flash_is_busy()
564 /*-----------------------------------------------------------------------
566 * This routine does not set the flash to read-array mode.
568 static int flash_status_check(flash_info_t *info, flash_sect_t sector, in flash_status_check() argument
587 while (flash_is_busy(info, sector)) { in flash_status_check()
590 prompt, info->start[sector], in flash_status_check()
591 flash_read_long(info, sector, 0)); in flash_status_check()
592 flash_write_cmd(info, sector, 0, info->cmd_reset); in flash_status_check()
601 /*-----------------------------------------------------------------------
605 * This routine sets the flash to read-array mode.
607 static int flash_full_status_check(flash_info_t *info, flash_sect_t sector, in flash_full_status_check() argument
612 retcode = flash_status_check(info, sector, tout, prompt); in flash_full_status_check()
613 switch (info->vendor) { in flash_full_status_check()
618 !flash_isset(info, sector, 0, FLASH_STATUS_DONE)) { in flash_full_status_check()
621 info->start[sector]); in flash_full_status_check()
622 if (flash_isset(info, sector, 0, FLASH_STATUS_ECLBS | in flash_full_status_check()
625 } else if (flash_isset(info, sector, 0, in flash_full_status_check()
629 } else if (flash_isset(info, sector, 0, in flash_full_status_check()
633 if (flash_isset(info, sector, 0, FLASH_STATUS_DPS)) { in flash_full_status_check()
637 if (flash_isset(info, sector, 0, FLASH_STATUS_VPENS)) in flash_full_status_check()
640 flash_write_cmd(info, sector, 0, info->cmd_reset); in flash_full_status_check()
652 if (info->vendor == CFI_CMDSET_AMD_EXTENDED || in use_flash_status_poll()
653 info->vendor == CFI_CMDSET_AMD_STANDARD) in use_flash_status_poll()
681 switch (info->portwidth) { in flash_status_poll()
711 /*-----------------------------------------------------------------------
721 switch (info->portwidth) { in flash_add_byte()
723 cword->w8 = c; in flash_add_byte()
729 cword->w16 = (cword->w16 >> 8) | w; in flash_add_byte()
731 cword->w16 = (cword->w16 << 8) | c; in flash_add_byte()
738 cword->w32 = (cword->w32 >> 8) | l; in flash_add_byte()
740 cword->w32 = (cword->w32 << 8) | c; in flash_add_byte()
747 cword->w64 = (cword->w64 >> 8) | ll; in flash_add_byte()
749 cword->w64 = (cword->w64 << 8) | c; in flash_add_byte()
756 * Loop through the sector table starting from the previously found sector.
761 static flash_sect_t saved_sector; /* previously found sector */ in find_sector()
763 flash_sect_t sector = saved_sector; in find_sector() local
765 if (info != saved_info || sector >= info->sector_count) in find_sector()
766 sector = 0; in find_sector()
768 while ((sector < info->sector_count - 1) && in find_sector()
769 (info->start[sector] < addr)) in find_sector()
770 sector++; in find_sector()
771 while ((info->start[sector] > addr) && (sector > 0)) in find_sector()
773 * also decrements the sector in case of an overshot in find_sector()
776 sector--; in find_sector()
778 saved_sector = sector; in find_sector()
780 return sector; in find_sector()
783 /*-----------------------------------------------------------------------
793 switch (info->portwidth) { in flash_write_cfiword()
816 switch (info->vendor) { in flash_write_cfiword()
827 flash_write_cmd(info, sect, info->addr_unlock1, AMD_CMD_WRITE); in flash_write_cfiword()
834 flash_write_cmd(info, 0, info->addr_unlock1, AMD_CMD_WRITE); in flash_write_cfiword()
840 switch (info->portwidth) { in flash_write_cfiword()
855 /* re-enable interrupts if necessary */ in flash_write_cfiword()
864 info->write_tout, "write"); in flash_write_cfiword()
867 info->write_tout, "write"); in flash_write_cfiword()
875 flash_sect_t sector; in flash_write_cfibuffer() local
886 switch (info->portwidth) { in flash_write_cfibuffer()
906 while ((cnt-- > 0) && (flag == 1)) { in flash_write_cfibuffer()
907 switch (info->portwidth) { in flash_write_cfibuffer()
936 sector = find_sector(info, dest); in flash_write_cfibuffer()
938 switch (info->vendor) { in flash_write_cfibuffer()
942 write_cmd = (info->vendor == CFI_CMDSET_INTEL_PROG_REGIONS) ? in flash_write_cfibuffer()
945 flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS); in flash_write_cfibuffer()
946 flash_write_cmd(info, sector, 0, FLASH_CMD_READ_STATUS); in flash_write_cfibuffer()
947 flash_write_cmd(info, sector, 0, write_cmd); in flash_write_cfibuffer()
948 retcode = flash_status_check(info, sector, in flash_write_cfibuffer()
949 info->buffer_write_tout, in flash_write_cfibuffer()
956 flash_write_cmd(info, sector, 0, cnt - 1); in flash_write_cfibuffer()
957 while (cnt-- > 0) { in flash_write_cfibuffer()
958 switch (info->portwidth) { in flash_write_cfibuffer()
980 flash_write_cmd(info, sector, 0, in flash_write_cfibuffer()
983 info, sector, info->buffer_write_tout, in flash_write_cfibuffer()
991 flash_unlock_seq(info, sector); in flash_write_cfibuffer()
994 offset = ((unsigned long)dst - info->start[sector]) >> shift; in flash_write_cfibuffer()
996 flash_write_cmd(info, sector, offset, AMD_CMD_WRITE_TO_BUFFER); in flash_write_cfibuffer()
998 flash_write_cmd(info, sector, offset, cnt - 1); in flash_write_cfibuffer()
1000 switch (info->portwidth) { in flash_write_cfibuffer()
1002 while (cnt-- > 0) { in flash_write_cfibuffer()
1008 while (cnt-- > 0) { in flash_write_cfibuffer()
1014 while (cnt-- > 0) { in flash_write_cfibuffer()
1020 while (cnt-- > 0) { in flash_write_cfibuffer()
1030 flash_write_cmd(info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM); in flash_write_cfibuffer()
1032 retcode = flash_status_poll(info, src - (1 << shift), in flash_write_cfibuffer()
1033 dst - (1 << shift), in flash_write_cfibuffer()
1034 info->buffer_write_tout, in flash_write_cfibuffer()
1037 retcode = flash_full_status_check(info, sector, in flash_write_cfibuffer()
1038 info->buffer_write_tout, in flash_write_cfibuffer()
1053 /*-----------------------------------------------------------------------
1062 if (info->flash_id != FLASH_MAN_CFI) { in flash_erase()
1063 puts("Can't erase unknown flash type - aborted\n"); in flash_erase()
1067 puts("- no sectors to erase\n"); in flash_erase()
1073 if (info->protect[sect]) in flash_erase()
1076 printf("- Warning: %d protected sectors will not be erased!\n", in flash_erase()
1088 if (info->protect[sect] == 0) { /* not protected */ in flash_erase()
1096 * Check if whole sector is erased in flash_erase()
1100 flash = (u32 *)info->start[sect]; in flash_erase()
1115 switch (info->vendor) { in flash_erase()
1130 info->addr_unlock1, in flash_erase()
1134 info->cmd_erase_sector); in flash_erase()
1139 flash_write_cmd(info, 0, info->addr_unlock1, in flash_erase()
1148 info->vendor); in flash_erase()
1159 info->erase_blk_tout, in flash_erase()
1164 info->erase_blk_tout, in flash_erase()
1189 * Check if whole sector is erased in sector_erased()
1192 flash = (u32 *)info->start[i]; in sector_erased()
1209 if (info->flash_id != FLASH_MAN_CFI) { in flash_print_info()
1215 info->name, in flash_print_info()
1216 (info->portwidth << 3), (info->chipwidth << 3)); in flash_print_info()
1217 if (info->size < 1024 * 1024) in flash_print_info()
1219 info->size >> 10, info->sector_count); in flash_print_info()
1222 info->size >> 20, info->sector_count); in flash_print_info()
1224 switch (info->vendor) { in flash_print_info()
1246 printf("Unknown (%d)", info->vendor); in flash_print_info()
1250 info->manufacturer_id); in flash_print_info()
1251 printf(info->chipwidth == FLASH_CFI_16BIT ? "%04X" : "%02X", in flash_print_info()
1252 info->device_id); in flash_print_info()
1253 if ((info->device_id & 0xff) == 0x7E) { in flash_print_info()
1254 printf(info->chipwidth == FLASH_CFI_16BIT ? "%04X" : "%02X", in flash_print_info()
1255 info->device_id2); in flash_print_info()
1257 if (info->vendor == CFI_CMDSET_AMD_STANDARD && info->legacy_unlock) in flash_print_info()
1258 printf("\n Advanced Sector Protection (PPB) enabled"); in flash_print_info()
1260 info->erase_blk_tout, info->write_tout); in flash_print_info()
1261 if (info->buffer_size > 1) { in flash_print_info()
1263 info->buffer_write_tout); in flash_print_info()
1264 printf("buffer size: %d bytes\n", info->buffer_size); in flash_print_info()
1267 puts("\n Sector Start Addresses:"); in flash_print_info()
1268 for (i = 0; i < info->sector_count; ++i) { in flash_print_info()
1274 /* print empty and read-only info */ in flash_print_info()
1276 info->start[i], in flash_print_info()
1278 info->protect[i] ? "RO" : " "); in flash_print_info()
1281 info->start[i], in flash_print_info()
1282 info->protect[i] ? "RO" : " "); in flash_print_info()
1288 /*-----------------------------------------------------------------------
1297 dots -= dots_sub; \
1303 digit--; \
1311 /*-----------------------------------------------------------------------
1313 * 0 - OK
1314 * 1 - write timeout
1315 * 2 - Flash not erased
1336 scale = (int)((cnt + CONFIG_FLASH_SHOW_PROGRESS - 1) / in write_buff()
1342 wp = (addr & ~(info->portwidth - 1)); in write_buff()
1345 aln = addr - wp; in write_buff()
1352 for (; (i < info->portwidth) && (cnt > 0); i++) { in write_buff()
1354 cnt--; in write_buff()
1356 for (; (cnt == 0) && (i < info->portwidth); ++i) in write_buff()
1369 buffered_size = (info->portwidth / info->chipwidth); in write_buff()
1370 buffered_size *= info->buffer_size; in write_buff()
1371 while (cnt >= info->portwidth) { in write_buff()
1373 if (info->buffer_size == 1) { in write_buff()
1375 for (i = 0; i < info->portwidth; i++) in write_buff()
1380 wp += info->portwidth; in write_buff()
1381 cnt -= info->portwidth; in write_buff()
1386 i = buffered_size - (wp % buffered_size); in write_buff()
1392 i -= i & (info->portwidth - 1); in write_buff()
1395 cnt -= i; in write_buff()
1402 while (cnt >= info->portwidth) { in write_buff()
1404 for (i = 0; i < info->portwidth; i++) in write_buff()
1409 wp += info->portwidth; in write_buff()
1410 cnt -= info->portwidth; in write_buff()
1411 FLASH_SHOW_PROGRESS(scale, dots, digit, info->portwidth); in write_buff()
1413 if ((cnt & 0xFFFF) < info->portwidth && ctrlc()) in write_buff()
1426 for (i = 0; (i < info->portwidth) && (cnt > 0); ++i) { in write_buff()
1428 --cnt; in write_buff()
1430 for (; i < info->portwidth; ++i) in write_buff()
1438 return info->manufacturer_id == ((manu & FLASH_VENDMASK) >> 16); in manufact_match()
1441 /*-----------------------------------------------------------------------
1445 static int cfi_protect_bugfix(flash_info_t *info, long sector, int prot) in cfi_protect_bugfix() argument
1448 info->device_id == NUMONYX_256MBIT) { in cfi_protect_bugfix()
1453 flash_write_cmd(info, sector, 0, FLASH_CMD_READ_ID); in cfi_protect_bugfix()
1454 if (!flash_isequal(info, sector, FLASH_OFFSET_PROTECT, in cfi_protect_bugfix()
1468 flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT); in cfi_protect_bugfix()
1469 flash_write_cmd(info, sector, 0, cmd); in cfi_protect_bugfix()
1470 /* re-enable interrupts if necessary */ in cfi_protect_bugfix()
1479 int flash_real_protect(flash_info_t *info, long sector, int prot) in flash_real_protect() argument
1483 switch (info->vendor) { in flash_real_protect()
1487 if (!cfi_protect_bugfix(info, sector, prot)) { in flash_real_protect()
1488 flash_write_cmd(info, sector, 0, in flash_real_protect()
1490 flash_write_cmd(info, sector, 0, in flash_real_protect()
1493 flash_write_cmd(info, sector, 0, in flash_real_protect()
1496 flash_write_cmd(info, sector, 0, in flash_real_protect()
1502 /* U-Boot only checks the first byte */ in flash_real_protect()
1507 info->addr_unlock1, in flash_real_protect()
1510 flash_write_cmd(info, sector, 0, in flash_real_protect()
1514 info->addr_unlock1, in flash_real_protect()
1516 if (info->device_id == ATM_ID_BV6416) in flash_real_protect()
1517 flash_write_cmd(info, sector, in flash_real_protect()
1521 if (info->legacy_unlock) { in flash_real_protect()
1526 flash_write_cmd(info, 0, info->addr_unlock1, in flash_real_protect()
1528 lock_flag = flash_isset(info, sector, 0, 0x01); in flash_real_protect()
1531 flash_write_cmd(info, sector, 0, in flash_real_protect()
1533 flash_write_cmd(info, sector, 0, in flash_real_protect()
1536 debug("sector %ld %slocked\n", sector, in flash_real_protect()
1540 debug("unlock %ld\n", sector); in flash_real_protect()
1546 debug("sector %ld %sunlocked\n", sector, in flash_real_protect()
1552 if (flash_status_check(info, sector, in flash_real_protect()
1553 info->erase_blk_tout, in flash_real_protect()
1565 flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS); in flash_real_protect()
1566 flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT); in flash_real_protect()
1568 flash_write_cmd(info, sector, 0, in flash_real_protect()
1571 flash_write_cmd(info, sector, 0, in flash_real_protect()
1580 flash_write_cmd(info, sector, 0, FLASH_CMD_READ_STATUS); in flash_real_protect()
1581 retcode = flash_full_status_check(info, sector, info->erase_blk_tout, in flash_real_protect()
1584 info->protect[sector] = prot; in flash_real_protect()
1590 if (prot == 0 && info->legacy_unlock) { in flash_real_protect()
1593 for (i = 0; i < info->sector_count; i++) { in flash_real_protect()
1594 if (info->protect[i]) in flash_real_protect()
1602 /*-----------------------------------------------------------------------
1603 * flash_read_user_serial - read the OneTimeProgramming cells
1615 flash_write_cmd(info, 0, 0, info->cmd_reset); in flash_read_user_serial()
1621 * flash_read_factory_serial - read the device Id from the protection area
1631 flash_write_cmd(info, 0, 0, info->cmd_reset); in flash_read_factory_serial()
1638 /*-----------------------------------------------------------------------
1641 * top-boot, or b) buggy.
1648 for (i = 0, j = qry->num_erase_regions - 1; i < j; i++, j--) { in cfi_reverse_geometry()
1649 tmp = get_unaligned(&qry->erase_region_info[i]); in cfi_reverse_geometry()
1650 put_unaligned(get_unaligned(&qry->erase_region_info[j]), in cfi_reverse_geometry()
1651 &qry->erase_region_info[i]); in cfi_reverse_geometry()
1652 put_unaligned(tmp, &qry->erase_region_info[j]); in cfi_reverse_geometry()
1656 /*-----------------------------------------------------------------------
1659 * Note: assume cfi->vendor, cfi->portwidth and cfi->chipwidth are correct
1668 info->manufacturer_id = flash_read_uchar(info, in cmdset_intel_read_jedec_ids()
1670 info->device_id = (info->chipwidth == FLASH_CFI_16BIT) ? in cmdset_intel_read_jedec_ids()
1678 info->cmd_reset = FLASH_CMD_RESET; in cmdset_intel_init()
1681 flash_write_cmd(info, 0, info->cfi_offset, FLASH_CMD_CFI); in cmdset_intel_init()
1685 if (info->ext_addr) { in cmdset_intel_init()
1686 info->legacy_unlock = in cmdset_intel_init()
1687 flash_read_uchar(info, info->ext_addr + 5) & 0x08; in cmdset_intel_init()
1702 flash_write_cmd(info, 0, info->addr_unlock1, FLASH_CMD_READ_ID); in cmdset_amd_read_jedec_ids()
1712 info->manufacturer_id = manu_id; in cmdset_amd_read_jedec_ids()
1714 debug("info->ext_addr = 0x%x, cfi_version = 0x%x\n", in cmdset_amd_read_jedec_ids()
1715 info->ext_addr, info->cfi_version); in cmdset_amd_read_jedec_ids()
1716 if (info->ext_addr && info->cfi_version >= 0x3134) { in cmdset_amd_read_jedec_ids()
1718 feature = flash_read_uchar(info, info->ext_addr + 0x13); in cmdset_amd_read_jedec_ids()
1720 info->sr_supported = feature & 0x1; in cmdset_amd_read_jedec_ids()
1723 switch (info->chipwidth) { in cmdset_amd_read_jedec_ids()
1725 info->device_id = flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1727 if (info->device_id == 0x7E) { in cmdset_amd_read_jedec_ids()
1728 /* AMD 3-byte (expanded) device ids */ in cmdset_amd_read_jedec_ids()
1729 info->device_id2 = flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1731 info->device_id2 <<= 8; in cmdset_amd_read_jedec_ids()
1732 info->device_id2 |= flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1737 info->device_id = flash_read_word(info, in cmdset_amd_read_jedec_ids()
1739 if ((info->device_id & 0xff) == 0x7E) { in cmdset_amd_read_jedec_ids()
1740 /* AMD 3-byte (expanded) device ids */ in cmdset_amd_read_jedec_ids()
1741 info->device_id2 = flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1743 info->device_id2 <<= 8; in cmdset_amd_read_jedec_ids()
1744 info->device_id2 |= flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1757 info->cmd_reset = AMD_CMD_RESET; in cmdset_amd_init()
1758 info->cmd_erase_sector = AMD_CMD_ERASE_SECTOR; in cmdset_amd_init()
1761 flash_write_cmd(info, 0, info->cfi_offset, FLASH_CMD_CFI); in cmdset_amd_init()
1764 if (info->ext_addr) { in cmdset_amd_init()
1765 /* read sector protect/unprotect scheme (at 0x49) */ in cmdset_amd_init()
1766 if (flash_read_uchar(info, info->ext_addr + 9) == 0x8) in cmdset_amd_init()
1767 info->legacy_unlock = 1; in cmdset_amd_init()
1777 info->manufacturer_id = 0; in flash_read_jedec_ids()
1778 info->device_id = 0; in flash_read_jedec_ids()
1779 info->device_id2 = 0; in flash_read_jedec_ids()
1781 switch (info->vendor) { in flash_read_jedec_ids()
1796 /*-----------------------------------------------------------------------
1797 * Call board code to request info about non-CFI flash.
1799 * info->portwidth, info->chipwidth and info->interface for Jedec probing.
1807 * use JEDEC ID probing. in flash_detect_legacy()
1809 if (!info->vendor) { in flash_detect_legacy()
1817 info->vendor = modes[i]; in flash_detect_legacy()
1818 info->start[0] = in flash_detect_legacy()
1820 info->portwidth, in flash_detect_legacy()
1822 if (info->portwidth == FLASH_CFI_8BIT && in flash_detect_legacy()
1823 info->interface == FLASH_CFI_X8X16) { in flash_detect_legacy()
1824 info->addr_unlock1 = 0x2AAA; in flash_detect_legacy()
1825 info->addr_unlock2 = 0x5555; in flash_detect_legacy()
1827 info->addr_unlock1 = 0x5555; in flash_detect_legacy()
1828 info->addr_unlock2 = 0x2AAA; in flash_detect_legacy()
1832 info->manufacturer_id, in flash_detect_legacy()
1833 info->device_id, in flash_detect_legacy()
1834 info->device_id2); in flash_detect_legacy()
1835 if (jedec_flash_match(info, info->start[0])) in flash_detect_legacy()
1838 unmap_physmem((void *)info->start[0], in flash_detect_legacy()
1839 info->portwidth); in flash_detect_legacy()
1843 switch (info->vendor) { in flash_detect_legacy()
1847 info->cmd_reset = FLASH_CMD_RESET; in flash_detect_legacy()
1852 info->cmd_reset = AMD_CMD_RESET; in flash_detect_legacy()
1855 info->flash_id = FLASH_MAN_CFI; in flash_detect_legacy()
1858 return 0; /* use CFI */ in flash_detect_legacy()
1863 return 0; /* use CFI */ in flash_detect_legacy()
1867 /*-----------------------------------------------------------------------
1884 * We do not yet know what kind of commandset to use, so we issue in __flash_cmd_reset()
1912 info->interface = le16_to_cpu(qry->interface_desc); in __flash_detect_cfi()
1914 info->cfi_offset = flash_offset_cfi[cfi_offset]; in __flash_detect_cfi()
1916 info->interface); in __flash_detect_cfi()
1918 info->portwidth, info->chipwidth); in __flash_detect_cfi()
1920 info->portwidth << CFI_FLASH_SHIFT_WIDTH, in __flash_detect_cfi()
1921 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in __flash_detect_cfi()
1924 info->addr_unlock1 = 0x555; in __flash_detect_cfi()
1925 info->addr_unlock2 = 0x2aa; in __flash_detect_cfi()
1932 (info->chipwidth == FLASH_CFI_BY8 && in __flash_detect_cfi()
1933 info->interface == FLASH_CFI_X8X16) || in __flash_detect_cfi()
1935 (info->chipwidth == FLASH_CFI_BY16 && in __flash_detect_cfi()
1936 info->interface == FLASH_CFI_X16X32)) { in __flash_detect_cfi()
1937 info->addr_unlock1 = 0xaaa; in __flash_detect_cfi()
1938 info->addr_unlock2 = 0x555; in __flash_detect_cfi()
1941 info->name = "CFI conformant"; in __flash_detect_cfi()
1953 for (info->portwidth = CONFIG_SYS_FLASH_CFI_WIDTH; in flash_detect_cfi()
1954 info->portwidth <= FLASH_CFI_64BIT; info->portwidth <<= 1) { in flash_detect_cfi()
1955 for (info->chipwidth = FLASH_CFI_BY8; in flash_detect_cfi()
1956 info->chipwidth <= info->portwidth; in flash_detect_cfi()
1957 info->chipwidth <<= 1) in flash_detect_cfi()
1966 * Manufacturer-specific quirks. Add workarounds for geometry
1972 if (qry->num_erase_regions > 1) { in flash_fixup_amd()
1974 if (info->cfi_version < 0x3131) { in flash_fixup_amd()
1976 if ((info->device_id & 0x80) != 0) in flash_fixup_amd()
1978 } else if (flash_read_uchar(info, info->ext_addr + 0xf) == 3) { in flash_fixup_amd()
1991 if (info->ext_addr && !(flash_read_uchar(info, info->ext_addr + 6) & 1)) in flash_fixup_atmel()
1995 * However, the device ID is identical with the non-broken in flash_fixup_atmel()
1998 if (info->device_id == 0xd6 || info->device_id == 0xd2) in flash_fixup_atmel()
2008 if (qry->num_erase_regions > 1) { in flash_fixup_stm()
2010 if (info->cfi_version < 0x3131) { in flash_fixup_stm()
2012 if (info->device_id == 0x22CA || /* M29W320DT */ in flash_fixup_stm()
2013 info->device_id == 0x2256 || /* M29W320ET */ in flash_fixup_stm()
2014 info->device_id == 0x22D7) { /* M29W800DT */ in flash_fixup_stm()
2017 } else if (flash_read_uchar(info, info->ext_addr + 0xf) == 3) { in flash_fixup_stm()
2029 * CFI-conformant. This is not true, since qry struct. in flash_fixup_sst()
2031 * erase two different sector sizes for the same memory. in flash_fixup_sst()
2032 * 64KB sector (SST call it block) needs 0x30 to be erased. in flash_fixup_sst()
2033 * 4KB sector (SST call it sector) needs 0x50 to be erased. in flash_fixup_sst()
2035 * a sector granularity of 4KB, and it is here set. in flash_fixup_sst()
2037 if (info->device_id == 0x5D23 || /* SST39VF3201B */ in flash_fixup_sst()
2038 info->device_id == 0x5C23) { /* SST39VF3202B */ in flash_fixup_sst()
2039 /* set sector granularity to 4KB */ in flash_fixup_sst()
2040 info->cmd_erase_sector = 0x50; in flash_fixup_sst()
2050 * So adjust the buffer size for M29EW while operating in 8-bit mode in flash_fixup_num()
2052 if (qry->max_buf_write_size > 0x8 && in flash_fixup_num()
2053 info->device_id == 0x7E && in flash_fixup_num()
2054 (info->device_id2 == 0x2201 || in flash_fixup_num()
2055 info->device_id2 == 0x2301 || in flash_fixup_num()
2056 info->device_id2 == 0x2801 || in flash_fixup_num()
2057 info->device_id2 == 0x4801)) { in flash_fixup_num()
2060 qry->max_buf_write_size = 0x8; in flash_fixup_num()
2073 phys_addr_t sector; in flash_get_size() local
2084 info->ext_addr = 0; in flash_get_size()
2085 info->cfi_version = 0; in flash_get_size()
2087 info->legacy_unlock = 0; in flash_get_size()
2090 info->start[0] = (ulong)map_physmem(base, info->portwidth, MAP_NOCACHE); in flash_get_size()
2093 info->vendor = le16_to_cpu(get_unaligned(&qry.p_id)); in flash_get_size()
2094 info->ext_addr = le16_to_cpu(get_unaligned(&qry.p_adr)); in flash_get_size()
2097 if (info->ext_addr) { in flash_get_size()
2098 info->cfi_version = (ushort)flash_read_uchar(info, in flash_get_size()
2099 info->ext_addr + 3) << 8; in flash_get_size()
2100 info->cfi_version |= (ushort)flash_read_uchar(info, in flash_get_size()
2101 info->ext_addr + 4); in flash_get_size()
2108 switch (info->vendor) { in flash_get_size()
2120 info->vendor); in flash_get_size()
2124 * as well try an Intel-style reset... in flash_get_size()
2130 /* Do manufacturer-specific fixups */ in flash_get_size()
2131 switch (info->manufacturer_id) { in flash_get_size()
2150 debug("manufacturer is %d\n", info->vendor); in flash_get_size()
2151 debug("manufacturer id is 0x%x\n", info->manufacturer_id); in flash_get_size()
2152 debug("device id is 0x%x\n", info->device_id); in flash_get_size()
2153 debug("device id2 is 0x%x\n", info->device_id2); in flash_get_size()
2154 debug("cfi version is 0x%04x\n", info->cfi_version); in flash_get_size()
2156 size_ratio = info->portwidth / info->chipwidth; in flash_get_size()
2158 if (info->interface == FLASH_CFI_X8X16 && in flash_get_size()
2159 info->chipwidth == FLASH_CFI_BY8) { in flash_get_size()
2163 size_ratio, info->portwidth << CFI_FLASH_SHIFT_WIDTH, in flash_get_size()
2164 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_get_size()
2165 info->size = 1 << qry.dev_size; in flash_get_size()
2167 info->size *= size_ratio; in flash_get_size()
2169 if (max_size && info->size > max_size) { in flash_get_size()
2170 debug("[truncated from %ldMiB]", info->size >> 20); in flash_get_size()
2171 info->size = max_size; in flash_get_size()
2175 sector = base; in flash_get_size()
2194 if (sector - base >= info->size) in flash_get_size()
2200 info->start[sect_cnt] = in flash_get_size()
2201 (ulong)map_physmem(sector, in flash_get_size()
2202 info->portwidth, in flash_get_size()
2204 sector += (erase_region_size * size_ratio); in flash_get_size()
2207 * Only read protection status from in flash_get_size()
2210 switch (info->vendor) { in flash_get_size()
2215 * Set flash to read-id mode. Otherwise in flash_get_size()
2221 info->protect[sect_cnt] = in flash_get_size()
2230 if (!info->legacy_unlock) { in flash_get_size()
2232 info->protect[sect_cnt] = 0; in flash_get_size()
2236 /* Read protection (PPB) from sector */ in flash_get_size()
2238 info->cmd_reset); in flash_get_size()
2241 info->addr_unlock1, in flash_get_size()
2243 info->protect[sect_cnt] = in flash_get_size()
2251 info->protect[sect_cnt] = 0; in flash_get_size()
2258 info->sector_count = sect_cnt; in flash_get_size()
2259 info->buffer_size = 1 << le16_to_cpu(qry.max_buf_write_size); in flash_get_size()
2261 info->erase_blk_tout = tmp * in flash_get_size()
2267 info->buffer_write_tout = (tmp + 999) / 1000; in flash_get_size()
2271 info->write_tout = (tmp + 999) / 1000; in flash_get_size()
2272 info->flash_id = FLASH_MAN_CFI; in flash_get_size()
2273 if (info->interface == FLASH_CFI_X8X16 && in flash_get_size()
2274 info->chipwidth == FLASH_CFI_BY8) { in flash_get_size()
2275 /* XXX - Need to test on x8/x16 in parallel. */ in flash_get_size()
2276 info->portwidth >>= 1; in flash_get_size()
2279 flash_write_cmd(info, 0, 0, info->cmd_reset); in flash_get_size()
2282 return (info->size); in flash_get_size()
2310 * Finally issue reset-command to bring device back to in cfi_flash_set_config_reg()
2311 * read-array mode in cfi_flash_set_config_reg()
2317 /*-----------------------------------------------------------------------
2330 /* Monitor protection ON by default */ in flash_protect_default()
2335 CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1, in flash_protect_default()
2339 /* Environment protection ON by default */ in flash_protect_default()
2343 CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1, in flash_protect_default()
2347 /* Redundant environment protection ON by default */ in flash_protect_default()
2351 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1, in flash_protect_default()
2358 apl[i].start, apl[i].start + apl[i].size - 1); in flash_protect_default()
2361 apl[i].start + apl[i].size - 1, in flash_protect_default()
2397 printf("- Size = 0x%08lx = %ld MB\n", in flash_init()
2405 * Only the U-Boot image and it's environment in flash_init()
2408 * protection is used (CONFIG_SYS_FLASH_PROTECTION) in flash_init()
2424 * Legacy unlocking (e.g. Intel J3) -> in flash_init()
2425 * unlock only one sector. This will in flash_init()
2440 * No legancy unlocking -> unlock all sectors in flash_init()
2445 + flash_info[i].size - 1, in flash_init()
2473 return -ENOENT; in cfi_flash_probe()
2487 gd->bd->bi_flashstart = flash_info[0].base; in cfi_flash_probe()
2493 { .compatible = "cfi-flash" },
2494 { .compatible = "jedec-flash" },