]> git.gag.com Git - fw/openocd/blobdiff - src/flash/nor/stellaris.c
optimize: replace while loop by memcpy
[fw/openocd] / src / flash / nor / stellaris.c
index 6fa9fe25ffaeaf2f5a2e72edef002598d5ede6e4..13b7071e3f813b7f57350347d7510435751660f9 100644 (file)
@@ -438,8 +438,7 @@ FLASH_BANK_COMMAND_HANDLER(stellaris_flash_bank_command)
 
        if (CMD_ARGC < 6)
        {
-               LOG_WARNING("incomplete flash_bank stellaris configuration");
-               return ERROR_FLASH_BANK_INVALID;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        stellaris_info = calloc(sizeof(struct stellaris_flash_bank), 1);
@@ -897,7 +896,7 @@ static int stellaris_protect(struct flash_bank *bank, int set, int first, int la
        {
                LOG_ERROR("Hardware doesn't support page-level unprotect. "
                        "Try the 'recover' command.");
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        if (stellaris_info->did1 == 0)
@@ -1215,14 +1214,9 @@ static int stellaris_write(struct flash_bank *bank, uint8_t *buffer, uint32_t of
        if (bytes_remaining)
        {
                uint8_t last_word[4] = {0xff, 0xff, 0xff, 0xff};
-               int i = 0;
 
-               while (bytes_remaining > 0)
-               {
-                       last_word[i++] = *(buffer + bytes_written);
-                       bytes_remaining--;
-                       bytes_written++;
-               }
+               /* copy the last remaining bytes into the write buffer */
+               memcpy(last_word, buffer+bytes_written, bytes_remaining);
 
                if (!(address & 0xff))
                        LOG_DEBUG("0x%" PRIx32 "", address);
@@ -1351,8 +1345,7 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command)
 
        if (CMD_ARGC < 1)
        {
-               command_print(CMD_CTX, "stellaris mass_erase <bank>");
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        struct flash_bank *bank;
@@ -1439,9 +1432,9 @@ done:
 static const struct command_registration stellaris_exec_command_handlers[] = {
        {
                .name = "mass_erase",
+               .usage = "<bank>",
                .handler = stellaris_handle_mass_erase_command,
                .mode = COMMAND_EXEC,
-               .usage = "bank_id",
                .help = "erase entire device",
        },
        {