return 0;
}
-int isp_cmd_part_id(int quiet)
+int isp_cmd_part_id(unsigned long int* part_id, int quiet)
{
char buf[REP_BUFSIZE];
int ret = 0, len = 0;
- unsigned long int part_id = 0;
ret = isp_send_cmd_no_args("read-part-id", READ_PART_ID, quiet);
if (ret != 0) {
return -2;
}
/* FIXME : some part IDs are on two 32bits values */
- part_id = strtoul(buf, NULL, 10);
+ *part_id = strtoul(buf, NULL, 10);
if (quiet == 0) {
- printf("Part ID is 0x%08lx\n", part_id);
+ printf("Part ID is 0x%08lx\n", *part_id);
}
- return part_id;
+ return 0;
}
int isp_cmd_boot_version(void)
#define DEFAULT_PART_FILE_NAME_ETC "/etc/lpctools_parts.def"
#define DEFAULT_PART_FILE_NAME_CURRENT "./lpctools_parts.def"
-static int prog_connect_and_id(int freq);
-static int prog_handle_command(char* cmd, int dev_id, int arg_count, char** args);
+static int prog_connect_and_id(unsigned long int* id, int freq);
+static int prog_handle_command(char* cmd, unsigned long int dev_id, int arg_count, char** args);
int main(int argc, char** argv)
{
int baudrate = SERIAL_BAUD;
int crystal_freq = 10000;
char* isp_serial_device = NULL;
- int dev_id = 0;
+ unsigned long int dev_id = 0;
/* For "command" handling */
char* command = NULL;
char** cmd_args = NULL;
int nb_cmd_args = 0;
+ int ret = 0;
/* parameter parsing */
}
/* First : sync with device */
- dev_id = prog_connect_and_id(crystal_freq);
- if (dev_id < 0) {
+ ret = prog_connect_and_id(&dev_id, crystal_freq);
+ if (ret < 0) {
printf("Unable to connect to target, consider hard reset of target or link\n");
return -1;
}
* Try to connect to the target and identify the device.
* First try sync, and if it fails, try to read id twice. if both fail, then we are not connected
*/
-static int prog_connect_and_id(int freq)
+static int prog_connect_and_id(unsigned long int* id, int freq)
{
int sync_ret = 0;
if (sync_ret < 0) {
/* If already synchronized, then sync command and the next command fail.
Sync failed, maybe we are already sync'ed, then send one command for nothing */
- isp_cmd_part_id(1);
+ isp_cmd_part_id(id, 1);
}
- return isp_cmd_part_id(1);
+ return isp_cmd_part_id(id, 1);
}
-static int prog_handle_command(char* cmd, int dev_id, int arg_count, char** args)
+static int prog_handle_command(char* cmd, unsigned long int dev_id, int arg_count, char** args)
{
int cmd_found = -1;
int ret = 0;
part = find_part_in_file(dev_id, parts_file_name);
if (part == NULL) {
- printf("Unknown part number : 0x%08x.\n", dev_id);
+ printf("Unknown part number : 0x%08lx.\n", dev_id);
return -2;
}