flash: add error handling to get_flash_by_addr/name
[fw/openocd] / src / flash / nor / at91sam3.c
index 5f7e8d72fef687db93c29a0d69814b48cd961ec4..06b84cd317753177fd6f1ef06fbc93661b98bb8c 100644 (file)
 #endif
 
 
-#include <stdio.h>
-#include <string.h>
-#include <stddef.h>
-#include <helper/types.h>
-#include "flash.h"
-#include <helper/membuf.h>
+#include "imp.h"
 #include "at91sam3.h"
+#include <helper/membuf.h>
 #include <helper/time_support.h>
 
 #define REG_NAME_WIDTH  (12)
@@ -2050,9 +2046,7 @@ sam3_page_write_opcodes[] = {
        0x10,0xf0,0x01,0x0f,
        //  41 0024 FBD0                beq     .L4
        0xfb,0xd0,
-       //  42                  .done:
-       //  43 0026 FEE7                b       .done
-       0xfe,0xe7
+       0x00,0xBE                               /* bkpt #0 */
 };
 
 
@@ -2292,7 +2286,7 @@ COMMAND_HANDLER(sam3_handle_info_command)
                        return ERROR_FAIL;
                }
        }
-       // above garentees the "chip details" structure is valid
+       // above guarantees the "chip details" structure is valid
        // and thus, bank private areas are valid
        // and we have a SAM3 chip, what a concept!
 
@@ -2390,7 +2384,7 @@ COMMAND_HANDLER(sam3_handle_gpnvm_command)
 
        if (0 == strcmp("show", CMD_ARGV[0])) {
                if (who == -1) {
-               showall:
+showall:
                        r = ERROR_OK;
                        for (x = 0 ; x < pChip->details.n_gpnvms ; x++) {
                                r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), x, &v);
@@ -2470,24 +2464,27 @@ COMMAND_HANDLER(sam3_handle_slowclk_command)
 static const struct command_registration at91sam3_exec_command_handlers[] = {
        {
                .name = "gpnvm",
-               .handler = &sam3_handle_gpnvm_command,
+               .handler = sam3_handle_gpnvm_command,
                .mode = COMMAND_EXEC,
-               .usage = "[(set|clear) [<bit_id>]]",
-               .help = "Without arguments, shows the gpnvm register; "
-                       "otherwise, sets or clear the specified bit.",
+               .usage = "[('clr'|'set'|'show') bitnum]",
+               .help = "Without arguments, shows all bits in the gpnvm "
+                       "register.  Otherwise, clears, sets, or shows one "
+                       "General Purpose Non-Volatile Memory (gpnvm) bit.",
        },
        {
                .name = "info",
-               .handler = &sam3_handle_info_command,
+               .handler = sam3_handle_info_command,
                .mode = COMMAND_EXEC,
-               .help = "print information about the current sam3 chip",
+               .help = "Print information about the current at91sam3 chip"
+                       "and its flash configuration.",
        },
        {
                .name = "slowclk",
-               .handler = &sam3_handle_slowclk_command,
+               .handler = sam3_handle_slowclk_command,
                .mode = COMMAND_EXEC,
-               .usage = "<value>",
-               .help = "set the slowclock frequency (default 32768hz)",
+               .usage = "[clock_hz]",
+               .help = "Display or set the slowclock frequency "
+                       "(default 32768 Hz).",
        },
        COMMAND_REGISTRATION_DONE
 };
@@ -2502,15 +2499,16 @@ static const struct command_registration at91sam3_command_handlers[] = {
 };
 
 struct flash_driver at91sam3_flash = {
-               .name = "at91sam3",
-               .commands = at91sam3_command_handlers,
-               .flash_bank_command = &sam3_flash_bank_command,
-               .erase = &sam3_erase,
-               .protect = &sam3_protect,
-               .write = &sam3_write,
-               .probe = &sam3_probe,
-               .auto_probe = &sam3_auto_probe,
-               .erase_check = &sam3_erase_check,
-               .protect_check = &sam3_protect_check,
-               .info = &sam3_info,
-       };
+       .name = "at91sam3",
+       .commands = at91sam3_command_handlers,
+       .flash_bank_command = sam3_flash_bank_command,
+       .erase = sam3_erase,
+       .protect = sam3_protect,
+       .write = sam3_write,
+       .read = default_flash_read,
+       .probe = sam3_probe,
+       .auto_probe = sam3_auto_probe,
+       .erase_check = sam3_erase_check,
+       .protect_check = sam3_protect_check,
+       .info = sam3_info,
+};