]> git.karo-electronics.de Git - karo-tx-redboot.git/blobdiff - packages/devs/flash/arm/mxc/v2_0/src/mxc_nfc.c
Starterkit 5 Release 1.5 Bugfix
[karo-tx-redboot.git] / packages / devs / flash / arm / mxc / v2_0 / src / mxc_nfc.c
index 4bcf00603d792217f80dd424c790ca50366f86d6..82309b94f4943bc58baa2fe707015aa2a8a8649b 100644 (file)
@@ -118,8 +118,8 @@ CYG_MACRO_END
 #define MXC_UNLOCK_BLK_END             0xFFFF
 
 extern unsigned int hal_timer_count(void);
-int nfc_program_region(flash_addr_t addr, u8 *buf, u32 len);
-int nfc_erase_region(flash_addr_t addr, u32 len, bool skip_bad, bool verbose);
+static int nfc_program_region(flash_addr_t addr, u8 *buf, u32 len);
+static int nfc_erase_region(flash_addr_t addr, u32 len, bool skip_bad, bool verbose);
 
 static int nfc_write_pg_random(u32 pg_no, u32 pg_off, u8 *buf, u32 ecc_force);
 static int nfc_read_pg_random(u32 pg_no, u32 pg_off, u32 ecc_force, u32 cs_line,
@@ -1063,7 +1063,7 @@ static int nfc_program_blk(u32 ra, u8 *buf, u32 len)
  *
  * @return                             FLASH_ERR_OK (0) if successful; non-zero otherwise
  */
-int nfc_erase_region(flash_addr_t addr, u32 len, bool skip_bad, bool verbose)
+static int nfc_erase_region(flash_addr_t addr, u32 len, bool skip_bad, bool verbose)
 {
        u32 sz, blk, update = 0, j = 0;
 
@@ -1122,7 +1122,7 @@ int nfc_erase_region(flash_addr_t addr, u32 len, bool skip_bad, bool verbose)
  * @param len                  number of bytes
  * @return                             FLASH_ERR_OK (0) if successful; non-zero otherwise
  */
-int nfc_program_region(flash_addr_t addr, u8 *buf, u32 len)
+static int nfc_program_region(flash_addr_t addr, u8 *buf, u32 len)
 {
        u32 sz, blk, update = 0, partial_block_size;
 
@@ -1138,7 +1138,7 @@ int nfc_program_region(flash_addr_t addr, u8 *buf, u32 len)
                return FLASH_ERR_INVALID;
        }
 
-       partial_block_size = addr % NF_BLK_SZ;
+       partial_block_size = NF_BLK_SZ - (addr % NF_BLK_SZ);
 
        mxc_nfc_buf_clear(NAND_SPAR_BUF0, 0xff, NF_SPARE_SZ);
        addr = nfc_l_to_p(addr);
@@ -1151,6 +1151,7 @@ int nfc_program_region(flash_addr_t addr, u8 *buf, u32 len)
                blk = OFFSET_TO_BLOCK(addr);
                if (nfc_is_badblock(blk, g_bbt)) {
                        diag_printf("\nSkipping bad block %u at addr 0x%08llx\n", blk, addr);
+                       g_block_offset++;
                        goto incr_address;
                }
 
@@ -1163,6 +1164,7 @@ int nfc_program_region(flash_addr_t addr, u8 *buf, u32 len)
                        mark_blk_bad(blk, g_bbt, BLK_BAD_RUNTIME);
                        // we don't need to update the table immediately here since even
                        // with power loss now, we should see the same program error again.
+                       g_block_offset++;
                        goto incr_address;
                }
                diag_printf(".");
@@ -1175,7 +1177,6 @@ int nfc_program_region(flash_addr_t addr, u8 *buf, u32 len)
 incr_address:
                addr += partial_block_size;
                partial_block_size = NF_BLK_SZ;
-               g_block_offset++;
        }
        if (update) {
                if (program_bbt_to_flash() != 0) {
@@ -1205,13 +1206,13 @@ int nfc_read_region(flash_addr_t addr, u8 *buf, u32 len)
        nfc_printf(NFC_DEBUG_MED, "%s: addr=0x%08llx, offset=%03x buf=0x%p, len=0x%08x\n",
                           __FUNCTION__, addr, offset, buf, len);
 
-       addr = nfc_l_to_p(addr);
        if (addr < (u32)flash_info.start || (addr + len) > (u32)flash_info.end || len == 0) {
                diag_printf("** Error: flash address 0x%08llx..0x%08llx outside valid range %p..%p\n",
                                        (u64)addr, (u64)addr + len - 1, flash_info.start, flash_info.end);
                return FLASH_ERR_INVALID;
        }
 
+       addr = nfc_l_to_p(addr);
        while (len > 0) {
                int i;