From: Nathael Pajani Date: Wed, 16 May 2012 22:27:46 +0000 (+0200) Subject: Changed a few function headers and moved some code to ease X-Git-Tag: v1.0~32 X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=fb5ffa42523a4cfb816b7ec8586155c1e04624c5;p=soft%2Ftools%2Flpctools Changed a few function headers and moved some code to ease creation of the flash tool. --- diff --git a/isp_commands.c b/isp_commands.c index 5113cf1..d795233 100644 --- a/isp_commands.c +++ b/isp_commands.c @@ -28,12 +28,6 @@ extern int trace_on; -struct isp_command { - char* name; - int nb_args; - int (*handler)(int arg_count, char** args); -}; - /* Max should be 1270 for read memory, a little bit more for writes */ #define SERIAL_BUFSIZE 1300 @@ -202,7 +196,7 @@ int isp_send_cmd_no_args(char* cmd_name, char* cmd) return ret; } -int isp_cmd_unlock(int arg_count, char** args) +int isp_cmd_unlock(int quiet) { int ret = 0; @@ -211,12 +205,14 @@ int isp_cmd_unlock(int arg_count, char** args) printf("Unlock error.\n"); return -1; } - printf("Device memory protection unlocked.\n"); + if (quiet == 0) { + printf("Device memory protection unlocked.\n"); + } return 0; } -int isp_cmd_read_uid(int arg_count, char** args) +int isp_cmd_read_uid(void) { char buf[REP_BUFSIZE]; char* tmp = NULL; @@ -244,7 +240,7 @@ int isp_cmd_read_uid(int arg_count, char** args) return 0; } -int isp_cmd_part_id(int arg_count, char** args) +int isp_cmd_part_id(int quiet) { char buf[REP_BUFSIZE]; int ret = 0, len = 0; @@ -262,12 +258,14 @@ int isp_cmd_part_id(int arg_count, char** args) } /* FIXME : some part IDs are on two 32bits values */ part_id = strtoul(buf, NULL, 10); - printf("Part ID is 0x%08lx\n", part_id); + if (quiet == 0) { + printf("Part ID is 0x%08lx\n", part_id); + } - return 0; + return part_id; } -int isp_cmd_boot_version(int arg_count, char** args) +int isp_cmd_boot_version(void) { char buf[REP_BUFSIZE]; int ret = 0, len = 0; @@ -679,7 +677,7 @@ int isp_send_cmd_address(int arg_count, char** args, char* name, char cmd) unsigned long int addr1 = 0, addr2 = 0; unsigned long int length = 0; - /* Check compare arguments */ + /* Check arguments */ if (arg_count != 3) { printf("%s command needs two addresses and byte count.\n", name); return -7; @@ -717,13 +715,13 @@ int isp_send_cmd_address(int arg_count, char** args, char* name, char cmd) return -6; } - /* Create compare request */ + /* Create request */ len = snprintf(buf, SERIAL_BUFSIZE, "%c %lu %lu %lu\r\n", cmd, addr1, addr2, length); if (len > SERIAL_BUFSIZE) { len = SERIAL_BUFSIZE; } - /* Send compare request */ + /* Send request */ if (isp_serial_write(buf, len) != len) { printf("Unable to send %s request.\n", name); return -5; @@ -952,64 +950,4 @@ int isp_cmd_erase(int arg_count, char** args) } -static struct isp_command isp_cmds_list[] = { - {"unlock", 0, isp_cmd_unlock}, - {"write-to-ram", 2, isp_cmd_write_to_ram}, - {"read-memory", 3, isp_cmd_read_memory}, - {"prepare-for-write", 2, isp_cmd_prepare_for_write}, - {"copy-ram-to-flash", 3, isp_cmd_copy_ram_to_flash}, - {"go", 2, isp_cmd_go}, - {"erase", 2, isp_cmd_erase}, - {"blank-check", 2, isp_cmd_blank_check}, - {"read-part-id", 0, isp_cmd_part_id}, - {"read-boot-version", 0, isp_cmd_boot_version}, - {"compare", 3, isp_cmd_compare}, - {"read-uid", 0, isp_cmd_read_uid}, - {NULL, 0, NULL} -}; - -void isp_warn_trailing_args(int cmd_num, int arg_count, char** args) -{ - int i = 0; - printf("command \"%s\" needs %d args, got %d.\n", - isp_cmds_list[cmd_num].name, - isp_cmds_list[cmd_num].nb_args, arg_count); - for (i=0; i /* for serial config */ #include +#include /* strncmp, strlen */ + #include "isp_utils.h" #include "isp_commands.h" #define PROG_NAME "LPC11xx ISP" -#define VERSION "0.01" +#define VERSION "1.0" /* short explanation on exit values: * @@ -48,6 +50,9 @@ void help(char *prog_name) " Default baudrate is B115200\n" \ " is the (host) serial line used to programm the device\n" \ " is one of:\n" \ + " \t unlock, write-to-ram, read-memory, prepare-for-write, copy-ram-to-flash, go, erase,\n" \ + " \t blank-check, read-part-id, read-boot-version, compare, and read-uid.\n" \ + " command specific arguments are as follow:\n" \ " \t unlock \n" \ " \t write-to-ram address file : send 'file' to 'address' in ram\n" \ " \t read-memory address count file : read 'count' bytes from 'address', store then in 'file'\n" \ @@ -85,6 +90,7 @@ void help(char *prog_name) int trace_on = 0; +int isp_handle_command(char* cmd, int arg_count, char** args); int main(int argc, char** argv) { @@ -227,3 +233,87 @@ int main(int argc, char** argv) return 0; } +struct isp_command { + int cmd_num; + char* name; + int nb_args; + int (*handler)(int arg_count, char** args); +}; + + +static struct isp_command isp_cmds_list[] = { + {0, "unlock", 0, NULL}, + {1, "write-to-ram", 2, isp_cmd_write_to_ram}, + {2, "read-memory", 3, isp_cmd_read_memory}, + {3, "prepare-for-write", 2, isp_cmd_prepare_for_write}, + {4, "copy-ram-to-flash", 3, isp_cmd_copy_ram_to_flash}, + {5, "go", 2, isp_cmd_go}, + {6, "erase", 2, isp_cmd_erase}, + {7, "blank-check", 2, isp_cmd_blank_check}, + {8, "read-part-id", 0, NULL}, + {9, "read-boot-version", 0, NULL}, + {10, "compare", 3, isp_cmd_compare}, + {11, "read-uid", 0, NULL}, + {-1, NULL, 0, NULL} +}; + +void isp_warn_args(int cmd_num, int arg_count, char** args) +{ + int i = 0; + printf("command \"%s\" needs %d args, got %d.\n", + isp_cmds_list[cmd_num].name, + isp_cmds_list[cmd_num].nb_args, arg_count); + for (i=0; i