summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2017-10-06 12:10:40 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2017-10-06 12:10:40 +0200
commitd9da4833a7b7d3c16285809d6a42eebf90576d44 (patch)
tree767c9e8a2820450ec65341fc4ffbfa164313e7eb /utils
parent698779e3e898610800088b1ce6c6a2a25803b91c (diff)
downloadrockbox-d9da4833a7b7d3c16285809d6a42eebf90576d44.tar.gz
rockbox-d9da4833a7b7d3c16285809d6a42eebf90576d44.zip
nwztools/scsitool: various improvements
The tool now provides more useful information for developers when the device is not supported. Is also has a new verb "help_us" that also prints all this information (notably the device info and model ID). Change-Id: I04baec8fff23eb83a0408add6296b5d42e9aa8e7
Diffstat (limited to 'utils')
-rw-r--r--utils/nwztools/scsitools/scsitool.c74
1 files changed, 55 insertions, 19 deletions
diff --git a/utils/nwztools/scsitools/scsitool.c b/utils/nwztools/scsitools/scsitool.c
index a4aa853f46..236c2f5133 100644
--- a/utils/nwztools/scsitools/scsitool.c
+++ b/utils/nwztools/scsitools/scsitool.c
@@ -41,6 +41,8 @@ const char *g_force_series = NULL;
41char *g_out_prefix = NULL; 41char *g_out_prefix = NULL;
42rb_scsi_device_t g_dev; 42rb_scsi_device_t g_dev;
43 43
44void help_us(bool unsupported, unsigned long model_id);
45
44static void print_hex(void *_buffer, int buffer_size) 46static void print_hex(void *_buffer, int buffer_size)
45{ 47{
46 uint8_t *buffer = _buffer; 48 uint8_t *buffer = _buffer;
@@ -297,6 +299,28 @@ int get_dnk_prop(int argc, char **argv)
297 return 0; 299 return 0;
298} 300}
299 301
302/* get the model DID: code stolen from get_dnk_prop */
303int get_model_id(unsigned long *model_id)
304{
305 uint8_t mid_buf[4];
306 int mid_buf_size = sizeof(mid_buf);
307 int ret = do_dnk_cmd(true, 0x23, 9, 0, mid_buf, &mid_buf_size);
308 if(ret)
309 {
310 cprintf(RED, "Cannot get model ID from device: %d\n", ret);
311 cprintf(RED, "You device is most likely not compatible with this tool.\n");
312 return 2;
313 }
314 if(mid_buf_size != sizeof(mid_buf))
315 {
316 cprintf(RED, "Cannot get model ID from device: device didn't send the expected amount of data\n");
317 cprintf(RED, "You device is most likely not compatible with this tool.\n");
318 return 3;
319 }
320 *model_id = get_big_endian32(&mid_buf);
321 return 0;
322}
323
300int get_model_and_series(int *model_index, int *series_index) 324int get_model_and_series(int *model_index, int *series_index)
301{ 325{
302 /* if the user forced the series, simply match by name, special for '?' which 326 /* if the user forced the series, simply match by name, special for '?' which
@@ -322,28 +346,17 @@ int get_model_and_series(int *model_index, int *series_index)
322 } 346 }
323 else 347 else
324 { 348 {
325 /* we need to get the model ID: code stolen from get_dnk_prop */ 349 /* we need to get the model ID */
326 uint8_t mid_buf[4]; 350 unsigned long model_id;
327 int mid_buf_size = sizeof(mid_buf); 351 if(get_model_id(&model_id))
328 int ret = do_dnk_cmd(true, 0x23, 9, 0, mid_buf, &mid_buf_size); 352 return 1;
329 if(ret)
330 {
331 cprintf(RED, "Cannot get model ID from device: %d\n", ret);
332 return 2;
333 }
334 if(mid_buf_size != sizeof(mid_buf))
335 {
336 cprintf(RED, "Cannot get model ID from device: device didn't send the expected amount of data\n");
337 return 3;
338 }
339 unsigned long model_id = get_big_endian32(&mid_buf);
340 *model_index = -1; 353 *model_index = -1;
341 for(int i = 0; i < NWZ_MODEL_COUNT; i++) 354 for(int i = 0; i < NWZ_MODEL_COUNT; i++)
342 if(nwz_model[i].mid == model_id) 355 if(nwz_model[i].mid == model_id)
343 *model_index = i; 356 *model_index = i;
344 if(*model_index == -1) 357 if(*model_index == -1)
345 { 358 {
346 cprintf(RED, "Your device is not supported. Please contact developers.\n"); 359 help_us(true, model_id);
347 return 3; 360 return 3;
348 } 361 }
349 *series_index = -1; 362 *series_index = -1;
@@ -353,7 +366,7 @@ int get_model_and_series(int *model_index, int *series_index)
353 *series_index = i; 366 *series_index = i;
354 if(*series_index == -1) 367 if(*series_index == -1)
355 { 368 {
356 printf("Your device is not supported. Please contact developers.\n"); 369 help_us(true, model_id);
357 return 3; 370 return 3;
358 } 371 }
359 } 372 }
@@ -812,6 +825,8 @@ int do_dest(int argc, char **argv)
812 /* get model/series */ 825 /* get model/series */
813 int model_index, series_index; 826 int model_index, series_index;
814 int ret = get_model_and_series(&model_index, &series_index); 827 int ret = get_model_and_series(&model_index, &series_index);
828 if(ret)
829 return ret;
815 int shp_index = NWZ_NVP_INVALID; 830 int shp_index = NWZ_NVP_INVALID;
816 if(nwz_series[series_index].nvp_index) 831 if(nwz_series[series_index].nvp_index)
817 shp_index = (*nwz_series[series_index].nvp_index)[NWZ_NVP_SHP]; 832 shp_index = (*nwz_series[series_index].nvp_index)[NWZ_NVP_SHP];
@@ -843,9 +858,9 @@ int do_dest(int argc, char **argv)
843 for(size_t i = 0; i < DEST_COUNT; i++) 858 for(size_t i = 0; i < DEST_COUNT; i++)
844 if(dst == g_dest_list[i].dest) 859 if(dst == g_dest_list[i].dest)
845 dst_name = g_dest_list[i].name; 860 dst_name = g_dest_list[i].name;
846 printf("Destination: %s (%lx)\n", dst_name, dst); 861 cprintf_field("Destination: ", "%s (%lx)\n", dst_name, dst);
847 unsigned long sps = get_little_endian32(shp + 4); 862 unsigned long sps = get_little_endian32(shp + 4);
848 printf("Sound pressure: %lu (%s)\n", sps, sps == 0 ? "off" : "on"); 863 cprintf_field("Sound pressure: ", "%lu (%s)\n", sps, sps == 0 ? "off" : "on");
849 free(shp); 864 free(shp);
850 } 865 }
851 /* set */ 866 /* set */
@@ -905,6 +920,15 @@ int do_dest(int argc, char **argv)
905 return 0; 920 return 0;
906} 921}
907 922
923int do_help_us(int argc, char **argv)
924{
925 unsigned long model_id;
926 if(get_model_id(&model_id))
927 return 1;
928 help_us(false, model_id);
929 return 0;
930}
931
908typedef int (*cmd_fn_t)(int argc, char **argv); 932typedef int (*cmd_fn_t)(int argc, char **argv);
909 933
910struct cmd_t 934struct cmd_t
@@ -925,6 +949,7 @@ struct cmd_t cmd_list[] =
925 { "get_dhp", "Get destination headphones", get_dhp }, 949 { "get_dhp", "Get destination headphones", get_dhp },
926 { "do_fw_upgrade", "Do a firmware upgrade", do_fw_upgrade }, 950 { "do_fw_upgrade", "Do a firmware upgrade", do_fw_upgrade },
927 { "dest_tool", "Get/Set destination and sound pressure regulation", do_dest }, 951 { "dest_tool", "Get/Set destination and sound pressure regulation", do_dest },
952 { "help_us", "Provide useful information for developers to help us", do_help_us },
928}; 953};
929 954
930#define NR_CMDS (sizeof(cmd_list) / sizeof(cmd_list[0])) 955#define NR_CMDS (sizeof(cmd_list) / sizeof(cmd_list[0]))
@@ -953,6 +978,17 @@ static void usage(void)
953 exit(1); 978 exit(1);
954} 979}
955 980
981void help_us(bool unsupported, unsigned long model_id)
982{
983 if(unsupported)
984 cprintf(RED, "Your device is not supported yet.\n");
985 cprintf(RED, "Please contact developers and send them the information below.\n");
986 cprintf(RED, "See https://www.rockbox.org/wiki/SonyNWDestTool#ReportDevice\n");
987 cprintf(BLUE, "-------------------[ Paste information below ]-------------------\n");
988 cprintf_field("Model ID: ", "%#lx\n", model_id);
989 get_dev_info(0, NULL);
990}
991
956int main(int argc, char **argv) 992int main(int argc, char **argv)
957{ 993{
958 while(1) 994 while(1)