flash/nor: Use proper data types in driver API
[fw/openocd] / src / flash / nor / niietcm4.c
index 92382223d995d7ad4920d5c462d72f9413da27b0..1ab0a5a35d71812350472584f7b7a08b795233f2 100644 (file)
@@ -230,7 +230,8 @@ static int niietcm4_uopstatus_check(struct flash_bank *bank)
 static int niietcm4_dump_uflash_page(struct flash_bank *bank, uint32_t *dump, int page_num, int mem_type)
 {
        struct target *target = bank->target;
-       int i, retval;
+       int i;
+       int retval = ERROR_OK;
 
        uint32_t uflash_cmd;
        if (mem_type == INFO_MEM_TYPE)
@@ -265,7 +266,8 @@ static int niietcm4_dump_uflash_page(struct flash_bank *bank, uint32_t *dump, in
 static int niietcm4_load_uflash_page(struct flash_bank *bank, uint32_t *dump, int page_num, int mem_type)
 {
        struct target *target = bank->target;
-       int i, retval;
+       int i;
+       int retval = ERROR_OK;
 
        uint32_t uflash_cmd;
        if (mem_type == INFO_MEM_TYPE)
@@ -328,7 +330,8 @@ static int niietcm4_uflash_page_erase(struct flash_bank *bank, int page_num, int
 /**
  * Enable or disable protection of userflash pages
  */
-static int niietcm4_uflash_protect(struct flash_bank *bank, int mem_type, int set, int first, int last)
+static int niietcm4_uflash_protect(struct flash_bank *bank, int mem_type,
+               int set, unsigned int first, unsigned int last)
 {
        int retval;
        if (mem_type == INFO_MEM_TYPE) {
@@ -357,7 +360,7 @@ static int niietcm4_uflash_protect(struct flash_bank *bank, int mem_type, int se
                if (retval != ERROR_OK)
                        return retval;
                /* modify dump */
-               for (int i = first; i <= last; i++)     {
+               for (unsigned int i = first; i <= last; i++) {
                        uint32_t reg_num = i/8;
                        uint32_t bit_num = i%8;
                        if (set)
@@ -423,9 +426,9 @@ COMMAND_HANDLER(niietcm4_handle_uflash_read_byte_command)
        retval = target_read_u32(target, UFMD, &uflash_data);
        if (retval != ERROR_OK)
                return retval;
-       command_print(CMD_CTX,  "Read userflash %s region:\n"
-                                                       "address = 0x%04x,\n"
-                                                       "value   = 0x%02x.", CMD_ARGV[0], uflash_addr, uflash_data);
+       command_print(CMD,  "Read userflash %s region:\n"
+                                               "address = 0x%04x,\n"
+                                               "value   = 0x%02x.", CMD_ARGV[0], uflash_addr, uflash_data);
        return retval;
 }
 
@@ -465,10 +468,10 @@ COMMAND_HANDLER(niietcm4_handle_uflash_write_byte_command)
 
        int page_num = uflash_addr/USERFLASH_PAGE_SIZE;
 
-       command_print(CMD_CTX, "Write userflash %s region:\n"
-                                                  "address = 0x%04x,\n"
-                                                  "value   = 0x%02x.\n"
-                                                  "Please wait ... ", CMD_ARGV[0], uflash_addr, uflash_data);
+       command_print(CMD, "Write userflash %s region:\n"
+                                          "address = 0x%04x,\n"
+                                          "value   = 0x%02x.\n"
+                                          "Please wait ... ", CMD_ARGV[0], uflash_addr, uflash_data);
        /* dump */
        uint32_t uflash_dump[USERFLASH_PAGE_SIZE];
        niietcm4_dump_uflash_page(bank, uflash_dump, page_num, mem_type);
@@ -481,7 +484,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_write_byte_command)
 
        /* write dump to userflash */
        niietcm4_load_uflash_page(bank, uflash_dump, page_num, mem_type);
-       command_print(CMD_CTX, "done!");
+       command_print(CMD, "done!");
        return retval;
 }
 
@@ -518,7 +521,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_full_erase_command)
        retval = niietcm4_uopstatus_check(bank);
        if (retval != ERROR_OK)
                return retval;
-       command_print(CMD_CTX, "Userflash full erase done!");
+       command_print(CMD, "Userflash full erase done!");
 
        return retval;
 }
@@ -561,7 +564,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_erase_command)
                        return retval;
        }
 
-       command_print(CMD_CTX, "Erase %s userflash pages %d through %d done!", CMD_ARGV[0], first, last);
+       command_print(CMD, "Erase %s userflash pages %u through %u done!", CMD_ARGV[0], first, last);
 
        return retval;
 }
@@ -619,9 +622,9 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_check_command)
                        return retval;
 
                if (uflash_data & INFOWORD3_LOCK_IFB_UF)
-                       command_print(CMD_CTX, "All sectors of info userflash are not protected!");
+                       command_print(CMD, "All sectors of info userflash are not protected!");
                else
-                       command_print(CMD_CTX, "All sectors of info userflash are protected!");
+                       command_print(CMD, "All sectors of info userflash are protected!");
        } else {
                uflash_addr = UF_LOCK_ADDR;
                uflash_cmd = UFMC_MAGIC_KEY | UFMC_READ_IFB;
@@ -643,10 +646,10 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_check_command)
 
                        for (j = 0; j < 8; j++) {
                                if (uflash_data & 0x1)
-                                       command_print(CMD_CTX, "Userflash sector #%03d: 0x%04x (0x100) is not protected!",
+                                       command_print(CMD, "Userflash sector #%03d: 0x%04x (0x100) is not protected!",
                                                                                        i*8+j, (i*8+j)*USERFLASH_PAGE_SIZE);
                                else
-                                       command_print(CMD_CTX, "Userflash sector #%03d: 0x%04x (0x100) is protected!",
+                                       command_print(CMD, "Userflash sector #%03d: 0x%04x (0x100) is protected!",
                                                                                        i*8+j, (i*8+j)*USERFLASH_PAGE_SIZE);
                                uflash_data = uflash_data >> 1;
                        }
@@ -691,11 +694,11 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_command)
 
        int set;
        if (strcmp("on", CMD_ARGV[3]) == 0) {
-               command_print(CMD_CTX, "Try to enable %s userflash sectors %d through %d protection. Please wait ... ",
+               command_print(CMD, "Try to enable %s userflash sectors %u through %u protection. Please wait ... ",
                                                                CMD_ARGV[0], first, last);
                set = 1;
        } else if (strcmp("off", CMD_ARGV[3]) == 0) {
-               command_print(CMD_CTX, "Try to disable %s userflash sectors %d through %d protection. Please wait ... ",
+               command_print(CMD, "Try to disable %s userflash sectors %u through %u protection. Please wait ... ",
                                                                CMD_ARGV[0], first, last);
                set = 0;
        } else
@@ -705,7 +708,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_command)
                if (retval != ERROR_OK)
                        return retval;
 
-       command_print(CMD_CTX, "done!");
+       command_print(CMD, "done!");
        return retval;
 }
 
@@ -731,10 +734,10 @@ COMMAND_HANDLER(niietcm4_handle_bflash_info_remap_command)
 
        int set;
        if (strcmp("on", CMD_ARGV[0]) == 0) {
-               command_print(CMD_CTX, "Try to enable bootflash info region remap. Please wait ...");
+               command_print(CMD, "Try to enable bootflash info region remap. Please wait ...");
                set = 1;
        } else if (strcmp("off", CMD_ARGV[0]) == 0) {
-               command_print(CMD_CTX, "Try to disable bootflash info region remap. Please wait ...");
+               command_print(CMD, "Try to disable bootflash info region remap. Please wait ...");
                set = 0;
        } else
                return ERROR_COMMAND_SYNTAX_ERROR;
@@ -754,7 +757,7 @@ COMMAND_HANDLER(niietcm4_handle_bflash_info_remap_command)
 
        /* write dump to userflash */
        niietcm4_load_uflash_page(bank, uflash_dump, 0, 1);
-       command_print(CMD_CTX, "done!");
+       command_print(CMD, "done!");
 
        return retval;
 }
@@ -812,11 +815,11 @@ COMMAND_HANDLER(niietcm4_handle_extmem_cfg_command)
        else
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       command_print(CMD_CTX,  "Try to configure external memory boot interface:\n"
-                                                       "port = %s\n"
-                                                       "pin  = %s\n"
-                                                       "func = %s\n"
-                                                       "Please wait ...", CMD_ARGV[0], CMD_ARGV[1], CMD_ARGV[2]);
+       command_print(CMD,  "Try to configure external memory boot interface:\n"
+                                               "port = %s\n"
+                                               "pin  = %s\n"
+                                               "func = %s\n"
+                                               "Please wait ...", CMD_ARGV[0], CMD_ARGV[1], CMD_ARGV[2]);
        /* dump */
        uint32_t uflash_dump[USERFLASH_PAGE_SIZE];
        niietcm4_dump_uflash_page(bank, uflash_dump, 0, 1);
@@ -831,7 +834,7 @@ COMMAND_HANDLER(niietcm4_handle_extmem_cfg_command)
 
        /* write dump to userflash */
        niietcm4_load_uflash_page(bank, uflash_dump, 0, 1);
-       command_print(CMD_CTX, "done!");
+       command_print(CMD, "done!");
 
        return retval;
 }
@@ -859,10 +862,10 @@ COMMAND_HANDLER(niietcm4_handle_extmem_boot_command)
        int set;
 
        if (strcmp("on", CMD_ARGV[0]) == 0) {
-               command_print(CMD_CTX, "Try to enable boot from external memory. Please wait ...");
+               command_print(CMD, "Try to enable boot from external memory. Please wait ...");
                set = 1;
        } else if (strcmp("off", CMD_ARGV[0]) == 0) {
-               command_print(CMD_CTX, "Try to disable boot from external memory. Please wait ...");
+               command_print(CMD, "Try to disable boot from external memory. Please wait ...");
                set = 0;
        } else
                return ERROR_COMMAND_SYNTAX_ERROR;
@@ -882,7 +885,7 @@ COMMAND_HANDLER(niietcm4_handle_extmem_boot_command)
 
        /* write dump to userflash */
        niietcm4_load_uflash_page(bank, uflash_dump, 0, 1);
-       command_print(CMD_CTX, "done!");
+       command_print(CMD, "done!");
 
        return retval;
 }
@@ -898,7 +901,7 @@ COMMAND_HANDLER(niietcm4_handle_service_mode_erase_command)
                return retval;
        struct target *target = bank->target;
 
-       command_print(CMD_CTX, "Try to perform service mode erase. Please wait ...");
+       command_print(CMD, "Try to perform service mode erase. Please wait ...");
 
        retval = target_write_u32(target, SERVICE_MODE_ERASE_ADDR, 1);
        if (retval != ERROR_OK)
@@ -921,7 +924,7 @@ COMMAND_HANDLER(niietcm4_handle_service_mode_erase_command)
                        }
                busy_sleep(1);  /* can use busy sleep for short times. */
        }
-       command_print(CMD_CTX, "done! All data erased.");
+       command_print(CMD, "done! All data erased.");
 
        return retval;
 }
@@ -936,7 +939,7 @@ COMMAND_HANDLER(niietcm4_handle_driver_info_command)
        if (retval != ERROR_OK)
                return retval;
 
-       command_print(CMD_CTX, "niietcm4 flash driver\n"
+       command_print(CMD, "niietcm4 flash driver\n"
                                                   "version: %d.%d\n"
                                                   "author: Bogdan Kolbov\n"
                                                   "mail: kolbov@niiet.ru",
@@ -1109,7 +1112,7 @@ static int niietcm4_protect_check(struct flash_bank *bank)
        } else {
                uflash_addr = BF_LOCK_ADDR;
                uflash_cmd = UFMC_MAGIC_KEY | UFMC_READ_IFB;
-               for (int i = 0; i < bank->num_sectors/8; i++) {
+               for (unsigned int i = 0; i < bank->num_sectors/8; i++) {
                        retval = target_write_u32(target, UFMA, uflash_addr);
                        if (retval != ERROR_OK)
                                return retval;
@@ -1161,7 +1164,8 @@ static int niietcm4_mass_erase(struct flash_bank *bank)
        return retval;
 }
 
-static int niietcm4_erase(struct flash_bank *bank, int first, int last)
+static int niietcm4_erase(struct flash_bank *bank, unsigned int first,
+               unsigned int last)
 {
        struct target *target = bank->target;
        struct niietcm4_flash_bank *niietcm4_info = bank->driver_priv;
@@ -1186,7 +1190,7 @@ static int niietcm4_erase(struct flash_bank *bank, int first, int last)
 
        /* erasing pages */
        unsigned int page_size = bank->size / bank->num_sectors;
-       for (int i = first; i <= last; i++) {
+       for (unsigned int i = first; i <= last; i++) {
                /* current page addr */
                flash_addr = i*page_size;
                retval = target_write_u32(target, FMA, flash_addr);
@@ -1209,7 +1213,8 @@ static int niietcm4_erase(struct flash_bank *bank, int first, int last)
        return retval;
 }
 
-static int niietcm4_protect(struct flash_bank *bank, int set, int first, int last)
+static int niietcm4_protect(struct flash_bank *bank, int set,
+               unsigned int first, unsigned int last)
 {
        struct target *target = bank->target;
        struct niietcm4_flash_bank *niietcm4_info = bank->driver_priv;
@@ -1249,7 +1254,7 @@ static int niietcm4_protect(struct flash_bank *bank, int set, int first, int las
                if (retval != ERROR_OK)
                        return retval;
                /* modify dump */
-               for (int i = first; i <= last; i++)     {
+               for (unsigned int i = first; i <= last; i++)    {
                        uint32_t reg_num = i/8;
                        uint32_t bit_num = i%8;
                        if (set)
@@ -1582,9 +1587,11 @@ static int niietcm4_probe_k1921vk01t(struct flash_bank *bank)
 
                char info_bootflash_addr_str[64];
                if (niietcm4_info->bflash_info_remap)
-                       snprintf(info_bootflash_addr_str, sizeof(info_bootflash_addr_str), "0x%08x base adress", bank->base);
+                       snprintf(info_bootflash_addr_str, sizeof(info_bootflash_addr_str),
+                                       TARGET_ADDR_FMT " base adress", bank->base);
                else
-                       snprintf(info_bootflash_addr_str, sizeof(info_bootflash_addr_str), "not maped to global adress space");
+                       snprintf(info_bootflash_addr_str, sizeof(info_bootflash_addr_str),
+                                       "not mapped to global adress space");
 
                snprintf(niietcm4_info->chip_brief,
                                sizeof(niietcm4_info->chip_brief),
@@ -1725,7 +1732,7 @@ static int get_niietcm4_info(struct flash_bank *bank, char *buf, int buf_size)
 }
 
 
-struct flash_driver niietcm4_flash = {
+const struct flash_driver niietcm4_flash = {
        .name = "niietcm4",
        .usage = "flash bank <name> niietcm4 <base> <size> 0 0 <target#>",
        .commands = niietcm4_command_handlers,
@@ -1739,4 +1746,5 @@ struct flash_driver niietcm4_flash = {
        .erase_check = default_flash_blank_check,
        .protect_check = niietcm4_protect_check,
        .info = get_niietcm4_info,
+       .free_driver_priv = default_flash_free_driver_priv,
 };