diff --git a/fel.c b/fel.c index 2e4c33648..79a7c24d0 100644 --- a/fel.c +++ b/fel.c @@ -1249,6 +1249,7 @@ void usage(const char *cmd) { " -l, --list Enumerate all (USB) FEL devices and exit\n" " -d, --dev bus:devnum Use specific USB bus and device number\n" " --sid SID Select device by SID key (exact match)\n" + " --list-socs Print a list of all supported SoCs\n" "\n" " spl file Load and execute U-Boot SPL\n" " If file additionally contains a main U-Boot binary\n" @@ -1297,6 +1298,7 @@ int main(int argc, char **argv) bool uboot_autostart = false; /* flag for "uboot" command = U-Boot autostart */ bool pflag_active = false; /* -p switch, causing "write" to output progress */ bool device_list = false; /* -l switch, prints device list and exits */ + bool socs_list = false; /* list all supported SoCs and exit */ feldev_handle *handle; int busnum = -1, devnum = -1; char *sid_arg = NULL; @@ -1315,6 +1317,9 @@ int main(int argc, char **argv) else if (strcmp(argv[1], "--list") == 0 || strcmp(argv[1], "-l") == 0 || strcmp(argv[1], "list") == 0) device_list = true; + else if (strcmp(argv[1], "--list-socs") == 0 || + strcmp(argv[1], "list-socs") == 0) + socs_list = true; else if (strncmp(argv[1], "--dev", 5) == 0 || strncmp(argv[1], "-d", 2) == 0) { char *dev_arg = argv[1]; dev_arg += strspn(dev_arg, "-dev="); /* skip option chars, ignore '=' */ @@ -1353,6 +1358,14 @@ int main(int argc, char **argv) /* Process options that don't require a FEL device handle */ if (device_list) felusb_list_devices(); /* and exit program afterwards */ + if (socs_list) { + const soc_info_t *soc_info = NULL; + + printf("SoCID name\n"); + while ((soc_info = get_next_soc(soc_info)) != NULL) + printf("%04x: %s\n", soc_info->soc_id, soc_info->name); + return 0; + } if (sid_arg) { /* try to set busnum and devnum according to "--sid" option */ select_by_sid(sid_arg, &busnum, &devnum); diff --git a/soc_info.c b/soc_info.c index 501c29306..08dd2cd4a 100644 --- a/soc_info.c +++ b/soc_info.c @@ -590,6 +590,33 @@ soc_info_t *get_soc_info_from_version(struct aw_fel_version *buf) return get_soc_info_from_id(buf->soc_id); } +/* + * Iterate through all supported SoCs. The first call will take NULL as + * an argument, subsequent calls pass in the pointer returned by the + * previous call. When we reach the end of the list, the function + * returns NULL. + */ +const soc_info_t *get_next_soc(const soc_info_t *prev) +{ + const soc_info_t *soc; + + if (prev == NULL) + return &soc_info_table[0]; + + for (soc = soc_info_table; soc->swap_buffers; soc++) { + if (soc != prev) + continue; + + soc++; + if (!soc->swap_buffers) /* end of list? */ + return NULL; + + return soc; + } + + return NULL; /* prev entry not found */ +} + void get_soc_name_from_id(soc_name_t buffer, uint32_t soc_id) { soc_info_t *soc; diff --git a/soc_info.h b/soc_info.h index 1e72ecbaf..508f29dab 100644 --- a/soc_info.h +++ b/soc_info.h @@ -143,5 +143,6 @@ typedef struct { void get_soc_name_from_id(soc_name_t buffer, uint32_t soc_id); soc_info_t *get_soc_info_from_id(uint32_t soc_id); soc_info_t *get_soc_info_from_version(struct aw_fel_version *buf); +const soc_info_t *get_next_soc(const soc_info_t *prev); #endif /* _SUNXI_TOOLS_SOC_INFO_H */ diff --git a/sunxi-fel.1 b/sunxi-fel.1 index 42aed744c..3923bc0e2 100644 --- a/sunxi-fel.1 +++ b/sunxi-fel.1 @@ -45,6 +45,11 @@ Enable verbose logging. Enumerate all (USB) FEL devices and exit. .RE .sp +.B \-\-list-socs +.RS 4 +Print a list of all supported SoCs and exit. +.RE +.sp .B \-d, \-\-dev bus:devnum .RS 4 Use specific USB bus and device number