use ARRAY_SIZE macro
[fw/openocd] / src / flash / avrf.c
index 692992f4cdede0932182f214417197d9fcf0c2e0..687dd4b59ea2acf79bf263bfe9ee47532d938ae4 100644 (file)
@@ -290,7 +290,7 @@ static int avrf_probe(struct flash_bank *bank)
                LOG_ERROR("0x%" PRIx32 " is invalid Manufacturer for avr, 0x%X is expected", EXTRACT_MFG(device_id), 0x1F);
        }
 
-       for (i = 0; i < (int)(sizeof(avft_chips_info) / sizeof(avft_chips_info[0])); i++)
+       for (i = 0; i < (int)ARRAY_SIZE(avft_chips_info); i++)
        {
                if (avft_chips_info[i].chip_id == EXTRACT_PART(device_id))
                {
@@ -369,7 +369,7 @@ static int avrf_info(struct flash_bank *bank, char *buf, int buf_size)
                LOG_ERROR("0x%" PRIx32 " is invalid Manufacturer for avr, 0x%X is expected", EXTRACT_MFG(device_id), 0x1F);
        }
 
-       for (i = 0; i < (int)(sizeof(avft_chips_info) / sizeof(avft_chips_info[0])); i++)
+       for (i = 0; i < (int)ARRAY_SIZE(avft_chips_info); i++)
        {
                if (avft_chips_info[i].chip_id == EXTRACT_PART(device_id))
                {
@@ -449,21 +449,28 @@ COMMAND_HANDLER(avrf_handle_mass_erase_command)
        return ERROR_OK;
 }
 
-static int avrf_register_commands(struct command_context *cmd_ctx)
-{
-       struct command *avr_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "avr",
-                       NULL, COMMAND_ANY, "avr flash specific commands");
-
-       COMMAND_REGISTER(cmd_ctx, avr_cmd, "mass_erase",
-                       avrf_handle_mass_erase_command, COMMAND_EXEC,
-                       "mass erase device");
-
-       return ERROR_OK;
-}
+static const struct command_registration avrf_exec_command_handlers[] = {
+       {
+               .name = "mass_erase",
+               .handler = &avrf_handle_mass_erase_command,
+               .mode = COMMAND_EXEC,
+               .help = "erase entire device",
+       },
+       COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration avrf_command_handlers[] = {
+       {
+               .name = "avrf",
+               .mode = COMMAND_ANY,
+               .help = "AVR flash command group",
+               .chain = avrf_exec_command_handlers,
+       },
+       COMMAND_REGISTRATION_DONE
+};
 
 struct flash_driver avr_flash = {
                .name = "avr",
-               .register_commands = &avrf_register_commands,
+               .commands = avrf_command_handlers,
                .flash_bank_command = &avrf_flash_bank_command,
                .erase = &avrf_erase,
                .protect = &avrf_protect,