nand_command_get_device_by_num: make COMMAND_HELPER
authorZachary T Welch <zw@superlucidity.net>
Sun, 15 Nov 2009 15:20:19 +0000 (07:20 -0800)
committerZachary T Welch <zw@superlucidity.net>
Mon, 16 Nov 2009 16:44:38 +0000 (08:44 -0800)
Use COMMAND_HELPER macro to define nand_command_get_device_by_num.
Use CALL_COMMAND_HANDLER to invoke it.

src/flash/nand.c
src/flash/nand.h

index 46ac728..fba8104 100644 (file)
@@ -304,9 +304,10 @@ struct nand_device *get_nand_device_by_num(int num)
        return NULL;
 }
 
-int nand_command_get_device_by_num(struct command_context *cmd_ctx,
-               const char *str, struct nand_device **nand)
+COMMAND_HELPER(nand_command_get_device_by_num, unsigned name_index,
+               struct nand_device **nand)
 {
+       const char *str = args[name_index];
        unsigned num;
        COMMAND_PARSE_NUMBER(uint, str, num);
        *nand = get_nand_device_by_num(num);
@@ -1077,7 +1078,7 @@ COMMAND_HANDLER(handle_nand_info_command)
        int last = -1;
 
        struct nand_device *p;
-       int retval = nand_command_get_device_by_num(cmd_ctx, args[0], &p);
+       int retval = CALL_COMMAND_HANDLER(nand_command_get_device_by_num, 0, &p);
        if (ERROR_OK != retval)
                return retval;
 
@@ -1152,7 +1153,7 @@ COMMAND_HANDLER(handle_nand_probe_command)
        }
 
        struct nand_device *p;
-       int retval = nand_command_get_device_by_num(cmd_ctx, args[0], &p);
+       int retval = CALL_COMMAND_HANDLER(nand_command_get_device_by_num, 0, &p);
        if (ERROR_OK != retval)
                return retval;
 
@@ -1181,7 +1182,7 @@ COMMAND_HANDLER(handle_nand_erase_command)
        }
 
        struct nand_device *p;
-       int retval = nand_command_get_device_by_num(cmd_ctx, args[0], &p);
+       int retval = CALL_COMMAND_HANDLER(nand_command_get_device_by_num, 0, &p);
        if (ERROR_OK != retval)
                return retval;
 
@@ -1240,7 +1241,7 @@ COMMAND_HANDLER(handle_nand_check_bad_blocks_command)
        }
 
        struct nand_device *p;
-       int retval = nand_command_get_device_by_num(cmd_ctx, args[0], &p);
+       int retval = CALL_COMMAND_HANDLER(nand_command_get_device_by_num, 0, &p);
        if (ERROR_OK != retval)
                return retval;
 
@@ -1392,7 +1393,7 @@ static COMMAND_HELPER(nand_fileio_parse_args, struct nand_fileio_state *state,
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        struct nand_device *nand;
-       int retval = nand_command_get_device_by_num(cmd_ctx, args[0], &nand);
+       int retval = CALL_COMMAND_HANDLER(nand_command_get_device_by_num, 0, &nand);
        if (ERROR_OK != retval)
                return retval;
 
@@ -1651,7 +1652,7 @@ COMMAND_HANDLER(handle_nand_raw_access_command)
        }
 
        struct nand_device *p;
-       int retval = nand_command_get_device_by_num(cmd_ctx, args[0], &p);
+       int retval = CALL_COMMAND_HANDLER(nand_command_get_device_by_num, 0, &p);
        if (ERROR_OK != retval)
                return retval;
 
index afec9a7..ddc4520 100644 (file)
@@ -230,8 +230,8 @@ int nand_register_commands(struct command_context *cmd_ctx);
 int nand_init(struct command_context *cmd_ctx);
 
 /// helper for parsing a nand device command argument string
-int nand_command_get_device_by_num(struct command_context *cmd_ctx,
-               const char *str, struct nand_device **nand);
+COMMAND_HELPER(nand_command_get_device_by_num, unsigned name_index,
+               struct nand_device **nand);
 
 
 #define                ERROR_NAND_DEVICE_INVALID               (-1100)