flash/nor: Use proper data types in driver API
[openocd.git] / src / flash / nor / lpc2900.c
index 5412c93def3121c7fd4dc2588ee63f21f28f8461..af8bba092b9d65aa895a18d4d3fc914a87607547 100644 (file)
@@ -283,9 +283,9 @@ static uint32_t lpc2900_read_security_status(struct flash_bank *bank)
         * Anything else is undefined (is_protected = -1). This is treated as
         * a protected sector!
         */
-       int sector;
-       int index_t;
-       for (sector = 0; sector < bank->num_sectors; sector++) {
+       for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
+               unsigned int index_t;
+
                /* Convert logical sector number to physical sector number */
                if (sector <= 4)
                        index_t = sector + 11;
@@ -356,14 +356,13 @@ static uint32_t lpc2900_run_bist128(struct flash_bank *bank,
  * @param bank Pointer to the flash bank descriptor
  * @param offset Offset address relative to bank start
  */
-static uint32_t lpc2900_address2sector(struct flash_bank *bank,
+static unsigned int lpc2900_address2sector(struct flash_bank *bank,
        uint32_t offset)
 {
        uint32_t address = bank->base + offset;
 
        /* Run through all sectors of this bank */
-       int sector;
-       for (sector = 0; sector < bank->num_sectors; sector++) {
+       for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
                /* Return immediately if address is within the current sector */
                if (address < (bank->sectors[sector].offset + bank->sectors[sector].size))
                        return sector;
@@ -728,9 +727,9 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command)
        lpc2900_info->risky = 0;
 
        /* Read sector range, and do a sanity check. */
-       int first, last;
-       COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], first);
-       COMMAND_PARSE_NUMBER(int, CMD_ARGV[2], last);
+       unsigned int first, last;
+       COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], first);
+       COMMAND_PARSE_NUMBER(uint, CMD_ARGV[2], last);
        if ((first >= bank->num_sectors) ||
                        (last >= bank->num_sectors) ||
                        (first > last)) {
@@ -739,12 +738,11 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command)
        }
 
        uint8_t page[FLASH_PAGE_SIZE];
-       int sector;
 
        /* Sectors in page 6 */
        if ((first <= 4) || (last >= 8)) {
                memset(&page, 0xff, FLASH_PAGE_SIZE);
-               for (sector = first; sector <= last; sector++) {
+               for (unsigned int sector = first; sector <= last; sector++) {
                        if (sector <= 4)
                                memset(&page[0xB0 + 16*sector], 0, 16);
                        else if (sector >= 8)
@@ -761,7 +759,7 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command)
        /* Sectors in page 7 */
        if ((first <= 7) && (last >= 5)) {
                memset(&page, 0xff, FLASH_PAGE_SIZE);
-               for (sector = first; sector <= last; sector++) {
+               for (unsigned int sector = first; sector <= last; sector++) {
                        if ((sector >= 5) && (sector <= 7))
                                memset(&page[0x00 + 16*(sector - 5)], 0, 16);
                }
@@ -945,11 +943,12 @@ FLASH_BANK_COMMAND_HANDLER(lpc2900_flash_bank_command)
  * @param first First sector to be erased
  * @param last Last sector (including) to be erased
  */
-static int lpc2900_erase(struct flash_bank *bank, int first, int last)
+static int lpc2900_erase(struct flash_bank *bank, unsigned int first,
+               unsigned int last)
 {
        uint32_t status;
-       int sector;
-       int last_unsecured_sector;
+       unsigned int last_unsecured_sector;
+       bool has_unsecured_sector;
        struct target *target = bank->target;
        struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
 
@@ -959,7 +958,7 @@ static int lpc2900_erase(struct flash_bank *bank, int first, int last)
                return status;
 
        /* Sanity check on sector range */
-       if ((first < 0) || (last < first) || (last >= bank->num_sectors)) {
+       if ((last < first) || (last >= bank->num_sectors)) {
                LOG_INFO("Bad sector range");
                return ERROR_FLASH_SECTOR_INVALID;
        }
@@ -974,16 +973,19 @@ static int lpc2900_erase(struct flash_bank *bank, int first, int last)
         * a special way.
         */
        last_unsecured_sector = -1;
-       for (sector = first; sector <= last; sector++) {
-               if (!bank->sectors[sector].is_protected)
+       has_unsecured_sector = false;
+       for (unsigned int sector = first; sector <= last; sector++) {
+               if (!bank->sectors[sector].is_protected) {
                        last_unsecured_sector = sector;
+                       has_unsecured_sector = true;
+               }
        }
 
        /* Exit now, in case of the rare constellation where all sectors in range
         * are secured. This is regarded a success, since erasing/programming of
         * secured sectors shall be handled transparently.
         */
-       if (last_unsecured_sector == -1)
+       if (!has_unsecured_sector)
                return ERROR_OK;
 
        /* Enable flash block and set the correct CRA clock of 66 kHz */
@@ -998,7 +1000,7 @@ static int lpc2900_erase(struct flash_bank *bank, int first, int last)
                        FLASH_ERASE_TIME));
 
        /* Sectors are marked for erasure, then erased all together */
-       for (sector = first; sector <= last_unsecured_sector; sector++) {
+       for (unsigned int sector = first; sector <= last_unsecured_sector; sector++) {
                /* Only mark sectors that aren't secured. Any attempt to erase a group
                 * of sectors will fail if any single one of them is secured!
                 */
@@ -1059,7 +1061,6 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
        uint32_t num_bytes;
        struct target *target = bank->target;
        struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
-       int sector;
        int retval;
 
        static const uint32_t write_target_code[] = {
@@ -1111,7 +1112,7 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
        lpc2900_read_security_status(bank);
 
        /* Unprotect all involved sectors */
-       for (sector = 0; sector < bank->num_sectors; sector++) {
+       for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
                /* Start address in or before this sector?
                 * End address in or behind this sector? */
                if (((bank->base + offset) <
@@ -1179,7 +1180,7 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
                while (count != 0) {
                        uint32_t this_npages;
                        const uint8_t *this_buffer;
-                       int start_sector = lpc2900_address2sector(bank, offset);
+                       unsigned int start_sector = lpc2900_address2sector(bank, offset);
 
                        /* First page / last page / rest */
                        if (offset % FLASH_PAGE_SIZE) {
@@ -1208,7 +1209,7 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
                                this_buffer = buffer;
 
                                /* Make sure we stop at the next secured sector */
-                               sector = start_sector + 1;
+                               unsigned int sector = start_sector + 1;
                                while (sector < bank->num_sectors) {
                                        /* Secured? */
                                        if (bank->sectors[sector].is_protected) {
@@ -1230,7 +1231,7 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
 
                        /* Skip the current sector if it is secured */
                        if (bank->sectors[start_sector].is_protected) {
-                               LOG_DEBUG("Skip secured sector %d",
+                               LOG_DEBUG("Skip secured sector %u",
                                        start_sector);
 
                                /* Stop if this is the last sector */
@@ -1371,7 +1372,6 @@ static int lpc2900_probe(struct flash_bank *bank)
 {
        struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
        struct target *target = bank->target;
-       int i = 0;
        uint32_t offset;
 
 
@@ -1467,8 +1467,8 @@ static int lpc2900_probe(struct flash_bank *bank)
        }
 
        /* Show detected device */
-       LOG_INFO("Flash bank %d: Device %s, %" PRIu32
-               " KiB in %d sectors",
+       LOG_INFO("Flash bank %u: Device %s, %" PRIu32
+               " KiB in %u sectors",
                bank->bank_number,
                lpc2900_info->target_name, bank->size / KiB,
                bank->num_sectors);
@@ -1487,7 +1487,7 @@ static int lpc2900_probe(struct flash_bank *bank)
        bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
 
        offset = 0;
-       for (i = 0; i < bank->num_sectors; i++) {
+       for (unsigned int i = 0; i < bank->num_sectors; i++) {
                bank->sectors[i].offset = offset;
                bank->sectors[i].is_erased = -1;
                bank->sectors[i].is_protected = -1;
@@ -1501,7 +1501,7 @@ static int lpc2900_probe(struct flash_bank *bank)
                         * that has more than 19 sectors. Politely ask for a fix then.
                         */
                        bank->sectors[i].size = 0;
-                       LOG_ERROR("Never heard about sector %d", i);
+                       LOG_ERROR("Never heard about sector %u", i);
                }
 
                offset += bank->sectors[i].size;
@@ -1538,8 +1538,7 @@ static int lpc2900_erase_check(struct flash_bank *bank)
        /* Use the BIST (Built-In Selft Test) to generate a signature of each flash
         * sector. Compare against the expected signature of an empty sector.
         */
-       int sector;
-       for (sector = 0; sector < bank->num_sectors; sector++) {
+       for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
                uint32_t signature[4];
                status = lpc2900_run_bist128(bank, bank->sectors[sector].offset,
                                bank->sectors[sector].offset + (bank->sectors[sector].size - 1), signature);

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)