[#3934] transmit_address writes incorrect address for Atmel spi flashes

Document created by Aaronwu Employee on Sep 25, 2013
Version 1Show Document
  • View in full screen mode

[#3934] transmit_address writes incorrect address for Atmel spi flashes

Submitted By: Alexander Kochetkov

Open Date

2008-02-26 11:20:52     Close Date

2008-02-26 13:08:06

Priority:

Low     Assignee:

Mike Frysinger

Category:

N/A     Fixed In Release:

N/A

Found In Release:

N/A     Status:

Closed

Board:

STAMP     Processor:

BF537

Silicon Revision:

02     Resolution:

Duplicated

Is the bug repeatable?:

yes     

Summary: transmit_address writes incorrect address for Atmel spi flashes

Details:

 

U-Boot version:

1.1.6, trunk

 

Source file:

/trunk/u-boot-1.1.6/board/bf537-stamp/spi_flash.c

 

For the Atmel flashes with "power of 2" mode disabled, the function transmit_address writes incorrect address into flash.

 

Follow-ups

 

--- Alexander Kochetkov                                      2008-02-26 11:22:22

Patch was attached.

 

--- Alexander Kochetkov                                      2008-02-26 11:27:54

--- ./spi_flash.c    2008-02-26 19:04:42.000000000 +0300

+++ ./spi_flash_new.c    2008-02-26 20:12:21.000000000 +0300

@@ -526,14 +526,37 @@

#endif

}

 

+/*

+ * find_last_set - find the last bit set in value and return the

+ * index of that bit.

+ */

+static int find_last_set (uint32_t value)

+{

+    int pos = 32;

+    uint32_t mask = (1 << (pos - 1));

+    while (pos > 0)

+    {

+        if (value & mask)

+            break;

+        mask >>= 1;

+        pos--;

+    }

+    return pos;

+}

+

static void transmit_address(uint32_t addr)

{

+    uint32_t nbits = find_last_set (flash.sector_size - 1);

+    uint32_t sector = addr / flash.sector_size;

+    uint32_t offs   = addr % flash.sector_size;

+    uint32_t addr0 = (sector << nbits) | offs;

+

     /* Send the highest byte of the 24 bit address at first */

-    spi_write_read_byte(addr >> 16);

+    spi_write_read_byte(addr0 >> 16);

     /* Send the middle byte of the 24 bit address  at second */

-    spi_write_read_byte(addr >> 8);

+    spi_write_read_byte(addr0 >> 8);

     /* Send the lowest byte of the 24 bit address finally */

-    spi_write_read_byte(addr);

+    spi_write_read_byte(addr0);

}

 

/*

 

--- Mike Frysinger                                           2008-02-26 13:08:06

dupe of [#3909]

 

 

 

    Files

    Changes

    Commits

    Dependencies

    Duplicates

    Associations

    Tags

 

File Name     File Type     File Size     Posted By

spi_flash.c.diff    application/octet-stream    1081    Alexander Kochetkov

Attachments

Outcomes