[U-Boot-Users] [PATCH 0/3] More cfi_flash refactoring

The following three patches should be applied on top of the previous cfi_flash cleanup patches. With these in place, I can access the on-board flash on the ATNGW100 using the CFI driver, eliminating the final reason why I haven't submitted the NGW100 board patches for inclusion in mainline.
I've tested it by programming a 7MB JFFS2 image into the on-board AT49BV642D flash. It went almost successfully -- I got two erase timeouts and one programming timeout. On the second try, it worked with no problems.
It looks like I have a bug in my timing code, since "sleep 10" terminates early from time to time as well. So I feel pretty confident that the CFI driver is doing its job properly -- the timeouts are simply triggered too early every now and then.
The last patch in the series changes behaviour, so it probably needs more extensive testing than the others. But this patch is essential for the AT49BV642D to work -- without it, the geometry reversal fixup is incorrectly triggered, and the erase regions become wrong.
I think the new behaviour makes more sense, especially since the code uses the device_id to determine whether or not to apply the fixup; it's IMO wrong to depend on the device_id without also checking the manufacturer_id.
Haavard Skinnemoen (3): cfi_flash: Read whole QRY structure in one go cfi_flash: Add cmdset-specific init functions cfi_flash: Add manufacturer-specific fixups
drivers/mtd/cfi_flash.c | 377 +++++++++++++++++++++++++++++------------------ 1 files changed, 234 insertions(+), 143 deletions(-)

Read out the whole CFI Standard Query structure after successful cfi identification. This allows subsequent code to access this information directly without having to go through flash_read_uchar() and friends.
Signed-off-by: Haavard Skinnemoen hskinnemoen@atmel.com --- drivers/mtd/cfi_flash.c | 176 ++++++++++++++++++++++++----------------------- 1 files changed, 90 insertions(+), 86 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 6c18252..14c2061 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -171,6 +171,38 @@ flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* FLASH chips info */
typedef unsigned long flash_sect_t;
+/* CFI standard query structure */ +struct cfi_qry { + u8 qry[3]; + u16 p_id; + u16 p_adr; + u16 a_id; + u16 a_adr; + u8 vcc_min; + u8 vcc_max; + u8 vpp_min; + u8 vpp_max; + u8 word_write_timeout_typ; + u8 buf_write_timeout_typ; + u8 block_erase_timeout_typ; + u8 chip_erase_timeout_typ; + u8 word_write_timeout_max; + u8 buf_write_timeout_max; + u8 block_erase_timeout_max; + u8 chip_erase_timeout_max; + u8 dev_size; + u16 interface_desc; + u16 max_buf_write_size; + u8 num_erase_regions; + u32 erase_region_info[NUM_ERASE_REGIONS]; +} __attribute__((packed)); + +struct cfi_pri_hdr { + u8 pri[3]; + u8 major_version; + u8 minor_version; +} __attribute__((packed)); + static void flash_write8(u8 value, void *addr) { __raw_writeb(value, addr); @@ -291,28 +323,24 @@ static void print_longlong (char *str, unsigned long long data) sprintf (&str[i * 2], "%2.2x", *cp++); }
-static void flash_printqry (flash_info_t * info, flash_sect_t sect) +static void flash_printqry (struct cfi_qry *qry) { - void *addr; + u8 *p = (u8 *)qry; int x, y;
- for (x = 0; x < 0x40; x += 16U / info->portwidth) { - addr = flash_map(info, sect, x + FLASH_OFFSET_CFI_RESP); - debug ("%p : ", addr); - for (y = 0; y < 16; y++) { - debug ("%2.2x ", flash_read8(addr + y)); - } - debug (" "); + for (x = 0; x < sizeof(struct cfi_qry); x += 16) { + debug("%02x : ", x); + for (y = 0; y < 16; y++) + debug("%2.2x ", p[x + y]); + debug(" "); for (y = 0; y < 16; y++) { - unsigned char c = flash_read8(addr + y); - if (c >= 0x20 && c <= 0x7e) { - debug ("%c", c); - } else { - debug ("."); - } + unsigned char c = p[x + y]; + if (c >= 0x20 && c <= 0x7e) + debug("%c", c); + else + debug("."); } - debug ("\n"); - flash_unmap(info, sect, x + FLASH_OFFSET_CFI_RESP, addr); + debug("\n"); } } #endif @@ -337,41 +365,6 @@ static inline uchar flash_read_uchar (flash_info_t * info, uint offset) }
/*----------------------------------------------------------------------- - * read a short word by swapping for ppc format. - */ -static ushort flash_read_ushort (flash_info_t * info, flash_sect_t sect, - uint offset) -{ - uchar *addr; - ushort retval; - -#ifdef DEBUG - int x; -#endif - addr = flash_map (info, sect, offset); - -#ifdef DEBUG - debug ("ushort addr is at %p info->portwidth = %d\n", addr, - info->portwidth); - for (x = 0; x < 2 * info->portwidth; x++) { - debug ("addr[%x] = 0x%x\n", x, flash_read8(addr + x)); - } -#endif -#if defined(__LITTLE_ENDIAN) || defined(CFG_WRITE_SWAPPED_DATA) - retval = ((flash_read8(addr + info->portwidth) << 8) | - flash_read8(addr)); -#else - retval = ((flash_read8(addr + 2 * info->portwidth - 1) << 8) | - flash_read8(addr + info->portwidth - 1)); -#endif - - debug ("retval = 0x%x\n", retval); - flash_unmap (info, sect, offset, addr); - - return retval; -} - -/*----------------------------------------------------------------------- * read a long word by picking the least significant byte of each maximum * port size word. Swap for ppc format. */ @@ -1427,7 +1420,17 @@ static inline int flash_detect_legacy(ulong base, int banknum) * detect if flash is compatible with the Common Flash Interface (CFI) * http://www.jedec.org/download/search/jesd68.pdf */ -static int __flash_detect_cfi (flash_info_t * info) +static void flash_read_cfi (flash_info_t *info, void *buf, + unsigned int start, size_t len) +{ + u8 *p = buf; + unsigned int i; + + for (i = 0; i < len; i++) + p[i] = flash_read_uchar(info, start + i); +} + +static int __flash_detect_cfi (flash_info_t * info, struct cfi_qry *qry) { int cfi_offset;
@@ -1440,8 +1443,10 @@ static int __flash_detect_cfi (flash_info_t * info) if (flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP, 'Q') && flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R') && flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) { - info->interface = flash_read_ushort (info, 0, - FLASH_OFFSET_INTERFACE); + flash_read_cfi(info, qry, FLASH_OFFSET_CFI_RESP, + sizeof(struct cfi_qry)); + info->interface = le16_to_cpu(qry->interface_desc); + info->cfi_offset = flash_offset_cfi[cfi_offset]; debug ("device interface is %d\n", info->interface); @@ -1478,7 +1483,7 @@ static int __flash_detect_cfi (flash_info_t * info) return 0; }
-static int flash_detect_cfi (flash_info_t * info) +static int flash_detect_cfi (flash_info_t * info, struct cfi_qry *qry) { debug ("flash detect cfi\n");
@@ -1487,7 +1492,7 @@ static int flash_detect_cfi (flash_info_t * info) for (info->chipwidth = FLASH_CFI_BY8; info->chipwidth <= info->portwidth; info->chipwidth <<= 1) - if (__flash_detect_cfi(info)) + if (__flash_detect_cfi(info, qry)) return 1; } debug ("not found\n"); @@ -1510,6 +1515,7 @@ ulong flash_get_size (ulong base, int banknum) int erase_region_size; int erase_region_count; int geometry_reversed = 0; + struct cfi_qry qry;
info->ext_addr = 0; info->cfi_version = 0; @@ -1519,15 +1525,14 @@ ulong flash_get_size (ulong base, int banknum)
info->start[0] = base;
- if (flash_detect_cfi (info)) { - info->vendor = flash_read_ushort (info, 0, - FLASH_OFFSET_PRIMARY_VENDOR); + if (flash_detect_cfi (info, &qry)) { + info->vendor = le16_to_cpu(qry.p_id); + info->ext_addr = le16_to_cpu(qry.p_adr); + num_erase_regions = qry.num_erase_regions; + flash_read_jedec_ids (info); flash_write_cmd (info, 0, info->cfi_offset, FLASH_CMD_CFI); - num_erase_regions = flash_read_uchar (info, - FLASH_OFFSET_NUM_ERASE_REGIONS); - info->ext_addr = flash_read_ushort (info, 0, - FLASH_OFFSET_EXT_QUERY_T_P_ADDR); + if (info->ext_addr) { info->cfi_version = (ushort) flash_read_uchar (info, info->ext_addr + 3) << 8; @@ -1535,7 +1540,7 @@ ulong flash_get_size (ulong base, int banknum) info->ext_addr + 4); } #ifdef DEBUG - flash_printqry (info, 0); + flash_printqry (&qry); #endif switch (info->vendor) { case CFI_CMDSET_INTEL_STANDARD: @@ -1591,23 +1596,23 @@ ulong flash_get_size (ulong base, int banknum) sect_cnt = 0; sector = base; for (i = 0; i < num_erase_regions; i++) { + unsigned int region = i; + if (i > NUM_ERASE_REGIONS) { printf ("%d erase regions found, only %d used\n", num_erase_regions, NUM_ERASE_REGIONS); break; } if (geometry_reversed) - tmp = flash_read_long (info, 0, - FLASH_OFFSET_ERASE_REGIONS + - (num_erase_regions - 1 - i) * 4); - else - tmp = flash_read_long (info, 0, - FLASH_OFFSET_ERASE_REGIONS + - i * 4); + region = num_erase_regions - 1 - i; + + tmp = le32_to_cpu(qry.erase_region_info[region]); + debug("erase region %u: 0x%08lx\n", region, tmp); + + erase_region_count = (tmp & 0xffff) + 1; + tmp >>= 16; erase_region_size = (tmp & 0xffff) ? ((tmp & 0xffff) * 256) : 128; - tmp >>= 16; - erase_region_count = (tmp & 0xffff) + 1; debug ("erase_region_count = %d erase_region_size = %d\n", erase_region_count, erase_region_size); for (j = 0; j < erase_region_count; j++) { @@ -1640,23 +1645,22 @@ ulong flash_get_size (ulong base, int banknum) }
info->sector_count = sect_cnt; - info->size = 1 << flash_read_uchar (info, FLASH_OFFSET_SIZE); + info->size = 1 << qry.dev_size; /* multiply the size by the number of chips */ info->size *= size_ratio; - info->buffer_size = 1 << flash_read_ushort (info, 0, - FLASH_OFFSET_BUFFER_SIZE); - tmp = 1 << flash_read_uchar (info, FLASH_OFFSET_ETOUT); + info->buffer_size = 1 << le16_to_cpu(qry.max_buf_write_size); + tmp = 1 << qry.block_erase_timeout_typ; info->erase_blk_tout = tmp * - (1 << flash_read_uchar ( - info, FLASH_OFFSET_EMAX_TOUT)); - tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WBTOUT)) * - (1 << flash_read_uchar (info, FLASH_OFFSET_WBMAX_TOUT)); + (1 << qry.block_erase_timeout_max); + tmp = (1 << qry.buf_write_timeout_typ) * + (1 << qry.buf_write_timeout_max); + /* round up when converting to ms */ - info->buffer_write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); - tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WTOUT)) * - (1 << flash_read_uchar (info, FLASH_OFFSET_WMAX_TOUT)); + info->buffer_write_tout = (tmp + 999) / 1000; + tmp = (1 << qry.word_write_timeout_typ) * + (1 << qry.word_write_timeout_max); /* round up when converting to ms */ - info->write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); + info->write_tout = (tmp + 999) / 1000; info->flash_id = FLASH_MAN_CFI; if ((info->interface == FLASH_CFI_X8X16) && (info->chipwidth == FLASH_CFI_BY8)) {

Move things like reading JEDEC IDs and fixing up geometry reversal into separate functions. The geometry reversal fixup is now performed by altering the qry structure directly, which makes the sector init code slightly cleaner.
Signed-off-by: Haavard Skinnemoen hskinnemoen@atmel.com --- drivers/mtd/cfi_flash.c | 174 ++++++++++++++++++++++++++++++----------------- 1 files changed, 111 insertions(+), 63 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 14c2061..effcce4 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -1302,13 +1302,105 @@ void flash_read_factory_serial (flash_info_t * info, void *buffer, int offset,
#endif /* CFG_FLASH_PROTECTION */
+/*----------------------------------------------------------------------- + * Reverse the order of the erase regions in the CFI QRY structure. + * This is needed for chips that are either a) correctly detected as + * top-boot, or b) buggy. + */ +static void cfi_reverse_geometry(struct cfi_qry *qry) +{ + unsigned int i, j; + u32 tmp; + + for (i = 0, j = qry->num_erase_regions - 1; i < j; i++, j--) { + tmp = qry->erase_region_info[i]; + qry->erase_region_info[i] = qry->erase_region_info[j]; + qry->erase_region_info[j] = tmp; + } +}
/*----------------------------------------------------------------------- * read jedec ids from device and set corresponding fields in info struct * * Note: assume cfi->vendor, cfi->portwidth and cfi->chipwidth are correct * -*/ + */ +static void cmdset_intel_read_jedec_ids(flash_info_t *info) +{ + flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); + flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID); + udelay(1000); /* some flash are slow to respond */ + info->manufacturer_id = flash_read_uchar (info, + FLASH_OFFSET_MANUFACTURER_ID); + info->device_id = flash_read_uchar (info, + FLASH_OFFSET_DEVICE_ID); + flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); +} + +static int cmdset_intel_init(flash_info_t *info, struct cfi_qry *qry) +{ + info->cmd_reset = FLASH_CMD_RESET; + + cmdset_intel_read_jedec_ids(info); + flash_write_cmd(info, 0, info->cfi_offset, FLASH_CMD_CFI); + +#ifdef CFG_FLASH_PROTECTION + /* read legacy lock/unlock bit from intel flash */ + if (info->ext_addr) { + info->legacy_unlock = flash_read_uchar (info, + info->ext_addr + 5) & 0x08; + } +#endif + + return 0; +} + +static void cmdset_amd_read_jedec_ids(flash_info_t *info) +{ + flash_write_cmd(info, 0, 0, AMD_CMD_RESET); + flash_unlock_seq(info, 0); + flash_write_cmd(info, 0, info->addr_unlock1, FLASH_CMD_READ_ID); + udelay(1000); /* some flash are slow to respond */ + info->manufacturer_id = flash_read_uchar (info, + FLASH_OFFSET_MANUFACTURER_ID); + info->device_id = flash_read_uchar (info, + FLASH_OFFSET_DEVICE_ID); + if (info->device_id == 0x7E) { + /* AMD 3-byte (expanded) device ids */ + info->device_id2 = flash_read_uchar (info, + FLASH_OFFSET_DEVICE_ID2); + info->device_id2 <<= 8; + info->device_id2 |= flash_read_uchar (info, + FLASH_OFFSET_DEVICE_ID3); + } + flash_write_cmd(info, 0, 0, AMD_CMD_RESET); +} + +static int cmdset_amd_init(flash_info_t *info, struct cfi_qry *qry) +{ + info->cmd_reset = AMD_CMD_RESET; + + cmdset_amd_read_jedec_ids(info); + flash_write_cmd(info, 0, info->cfi_offset, FLASH_CMD_CFI); + + /* check if flash geometry needs reversal */ + if (qry->num_erase_regions > 1) { + /* reverse geometry if top boot part */ + if (info->cfi_version < 0x3131) { + /* CFI < 1.1, try to guess from device id */ + if ((info->device_id & 0x80) != 0) + cfi_reverse_geometry(qry); + } else if (flash_read_uchar(info, info->ext_addr + 0xf) == 3) { + /* CFI >= 1.1, deduct from top/bottom flag */ + /* note: ext_addr is valid since cfi_version > 0 */ + cfi_reverse_geometry(qry); + } + } + + return 0; +} + +#ifdef CONFIG_FLASH_CFI_LEGACY static void flash_read_jedec_ids (flash_info_t * info) { info->manufacturer_id = 0; @@ -1318,41 +1410,17 @@ static void flash_read_jedec_ids (flash_info_t * info) switch (info->vendor) { case CFI_CMDSET_INTEL_STANDARD: case CFI_CMDSET_INTEL_EXTENDED: - flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); - flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID); - udelay(1000); /* some flash are slow to respond */ - info->manufacturer_id = flash_read_uchar (info, - FLASH_OFFSET_MANUFACTURER_ID); - info->device_id = flash_read_uchar (info, - FLASH_OFFSET_DEVICE_ID); - flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); + flash_read_jedec_ids_intel(info); break; case CFI_CMDSET_AMD_STANDARD: case CFI_CMDSET_AMD_EXTENDED: - flash_write_cmd(info, 0, 0, AMD_CMD_RESET); - flash_unlock_seq(info, 0); - flash_write_cmd(info, 0, info->addr_unlock1, FLASH_CMD_READ_ID); - udelay(1000); /* some flash are slow to respond */ - info->manufacturer_id = flash_read_uchar (info, - FLASH_OFFSET_MANUFACTURER_ID); - info->device_id = flash_read_uchar (info, - FLASH_OFFSET_DEVICE_ID); - if (info->device_id == 0x7E) { - /* AMD 3-byte (expanded) device ids */ - info->device_id2 = flash_read_uchar (info, - FLASH_OFFSET_DEVICE_ID2); - info->device_id2 <<= 8; - info->device_id2 |= flash_read_uchar (info, - FLASH_OFFSET_DEVICE_ID3); - } - flash_write_cmd(info, 0, 0, AMD_CMD_RESET); + flash_read_jedec_ids_amd(info); break; default: break; } }
-#ifdef CONFIG_FLASH_CFI_LEGACY /*----------------------------------------------------------------------- * Call board code to request info about non-CFI flash. * board_flash_get_legacy needs to fill in at least: @@ -1514,7 +1582,6 @@ ulong flash_get_size (ulong base, int banknum) uchar num_erase_regions; int erase_region_size; int erase_region_count; - int geometry_reversed = 0; struct cfi_qry qry;
info->ext_addr = 0; @@ -1530,51 +1597,36 @@ ulong flash_get_size (ulong base, int banknum) info->ext_addr = le16_to_cpu(qry.p_adr); num_erase_regions = qry.num_erase_regions;
- flash_read_jedec_ids (info); - flash_write_cmd (info, 0, info->cfi_offset, FLASH_CMD_CFI); - if (info->ext_addr) { info->cfi_version = (ushort) flash_read_uchar (info, info->ext_addr + 3) << 8; info->cfi_version |= (ushort) flash_read_uchar (info, info->ext_addr + 4); } + #ifdef DEBUG flash_printqry (&qry); #endif + switch (info->vendor) { case CFI_CMDSET_INTEL_STANDARD: case CFI_CMDSET_INTEL_EXTENDED: - default: - info->cmd_reset = FLASH_CMD_RESET; -#ifdef CFG_FLASH_PROTECTION - /* read legacy lock/unlock bit from intel flash */ - if (info->ext_addr) { - info->legacy_unlock = flash_read_uchar (info, - info->ext_addr + 5) & 0x08; - } -#endif + cmdset_intel_init(info, &qry); break; case CFI_CMDSET_AMD_STANDARD: case CFI_CMDSET_AMD_EXTENDED: - info->cmd_reset = AMD_CMD_RESET; - /* check if flash geometry needs reversal */ - if (num_erase_regions <= 1) - break; - /* reverse geometry if top boot part */ - if (info->cfi_version < 0x3131) { - /* CFI < 1.1, try to guess from device id */ - if ((info->device_id & 0x80) != 0) { - geometry_reversed = 1; - } - break; - } - /* CFI >= 1.1, deduct from top/bottom flag */ - /* note: ext_addr is valid since cfi_version > 0 */ - if (flash_read_uchar(info, info->ext_addr + 0xf) == 3) { - geometry_reversed = 1; - } + cmdset_amd_init(info, &qry); break; + default: + printf("CFI: Unknown command set 0x%x\n", + info->vendor); + /* + * Unfortunately, this means we don't know how + * to get the chip back to Read mode. Might + * as well try an Intel-style reset... + */ + flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); + return 0; }
debug ("manufacturer is %d\n", info->vendor); @@ -1596,18 +1648,14 @@ ulong flash_get_size (ulong base, int banknum) sect_cnt = 0; sector = base; for (i = 0; i < num_erase_regions; i++) { - unsigned int region = i; - if (i > NUM_ERASE_REGIONS) { printf ("%d erase regions found, only %d used\n", num_erase_regions, NUM_ERASE_REGIONS); break; } - if (geometry_reversed) - region = num_erase_regions - 1 - i;
- tmp = le32_to_cpu(qry.erase_region_info[region]); - debug("erase region %u: 0x%08lx\n", region, tmp); + tmp = le32_to_cpu(qry.erase_region_info[i]); + debug("erase region %u: 0x%08lx\n", i, tmp);
erase_region_count = (tmp & 0xffff) + 1; tmp >>= 16;

Run fixups based on the JEDEC manufacturer ID independent of the command set ID.
This changes current behaviour: Previously, geometry reversal for AMD chips were done based on the command set ID, while they are now done based on the JEDEC manufacturer and device ID.
Also add fixup for top-boot Atmel chips. A fixup is needed for AT49BV6416(T) too, but since u-boot currently only reads the low byte of the device ID, there's no way to tell it apart from AT49BV642D, which should not have this fixup. Since AT49BV642D support is necessary to get ATNGW100 board support into mainline, I've commented out the fixup for now.
Signed-off-by: Haavard Skinnemoen hskinnemoen@atmel.com --- drivers/mtd/cfi_flash.c | 67 +++++++++++++++++++++++++++++++++++++---------- 1 files changed, 53 insertions(+), 14 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index effcce4..f370e4f 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -1383,20 +1383,6 @@ static int cmdset_amd_init(flash_info_t *info, struct cfi_qry *qry) cmdset_amd_read_jedec_ids(info); flash_write_cmd(info, 0, info->cfi_offset, FLASH_CMD_CFI);
- /* check if flash geometry needs reversal */ - if (qry->num_erase_regions > 1) { - /* reverse geometry if top boot part */ - if (info->cfi_version < 0x3131) { - /* CFI < 1.1, try to guess from device id */ - if ((info->device_id & 0x80) != 0) - cfi_reverse_geometry(qry); - } else if (flash_read_uchar(info, info->ext_addr + 0xf) == 3) { - /* CFI >= 1.1, deduct from top/bottom flag */ - /* note: ext_addr is valid since cfi_version > 0 */ - cfi_reverse_geometry(qry); - } - } - return 0; }
@@ -1568,6 +1554,49 @@ static int flash_detect_cfi (flash_info_t * info, struct cfi_qry *qry) }
/* + * Manufacturer-specific quirks. Add workarounds for geometry + * reversal, etc. here. + */ +static void flash_fixup_amd(flash_info_t *info, struct cfi_qry *qry) +{ + /* check if flash geometry needs reversal */ + if (qry->num_erase_regions > 1) { + /* reverse geometry if top boot part */ + if (info->cfi_version < 0x3131) { + /* CFI < 1.1, try to guess from device id */ + if ((info->device_id & 0x80) != 0) + cfi_reverse_geometry(qry); + } else if (flash_read_uchar(info, info->ext_addr + 0xf) == 3) { + /* CFI >= 1.1, deduct from top/bottom flag */ + /* note: ext_addr is valid since cfi_version > 0 */ + cfi_reverse_geometry(qry); + } + } +} + +static void flash_fixup_atmel(flash_info_t *info, struct cfi_qry *qry) +{ + int reverse_geometry = 0; + + /* Check the "top boot" bit in the PRI */ + if (info->ext_addr && !(flash_read_uchar(info, info->ext_addr + 6) & 1)) + reverse_geometry = 1; + + /* AT49BV6416(T) list the erase regions in the wrong order. + * However, the device ID is identical with the non-broken + * AT49BV642D since u-boot only reads the low byte (they + * differ in the high byte.) So leave out this fixup for now. + */ +#if 0 + if (info->device_id == 0xd6 || info->device_id == 0xd2) + reverse_geometry = !reverse_geometry; +#endif + + if (reverse_geometry) + cfi_reverse_geometry(qry); +} + +/* * The following code cannot be run from FLASH! * */ @@ -1629,6 +1658,16 @@ ulong flash_get_size (ulong base, int banknum) return 0; }
+ /* Do manufacturer-specific fixups */ + switch (info->manufacturer_id) { + case 0x0001: + flash_fixup_amd(info, &qry); + break; + case 0x001f: + flash_fixup_atmel(info, &qry); + break; + } + debug ("manufacturer is %d\n", info->vendor); debug ("manufacturer id is 0x%x\n", info->manufacturer_id); debug ("device id is 0x%x\n", info->device_id);

On Fri, 14 Dec 2007 15:36:15 +0100 Haavard Skinnemoen hskinnemoen@atmel.com wrote:
I've tested it by programming a 7MB JFFS2 image into the on-board AT49BV642D flash. It went almost successfully -- I got two erase timeouts and one programming timeout. On the second try, it worked with no problems.
It looks like I have a bug in my timing code, since "sleep 10" terminates early from time to time as well. So I feel pretty confident that the CFI driver is doing its job properly -- the timeouts are simply triggered too early every now and then.
Turns out that interrupts were never enabled, so the cycle counter lost its upper 32 bits. After applying the patch below, I've successfully erased and programmed the flash two times in a row.
So as far as I can tell, the CFI driver works. I'll send a merge request with this and a couple of other avr32 fixes soon.
Haavard
From: Haavard Skinnemoen hskinnemoen@atmel.com Subject: [PATCH] AVR32: Enable interrupts at bootup
The timer code depends on the timer interrupt to keep track of the upper 32 bits of the cycle counter. This obviously doesn't work when interrupts are disabled the whole time.
Signed-off-by: Haavard Skinnemoen hskinnemoen@atmel.com --- lib_avr32/board.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/lib_avr32/board.c b/lib_avr32/board.c index 4729e58..d6423d4 100644 --- a/lib_avr32/board.c +++ b/lib_avr32/board.c @@ -312,6 +312,8 @@ void board_init_r(gd_t *new_gd, ulong dest_addr) dma_alloc_init(); board_init_info();
+ enable_interrupts(); + bd->bi_flashstart = 0; bd->bi_flashsize = 0; bd->bi_flashoffset = 0;
participants (1)
-
Haavard Skinnemoen