main: Move image fitering to functions, do not fail if device or hwrev is not detected
This commit is contained in:
1 parent
3c4c0088f0
commit
cb25a8bd3e
1 file changed
+77
-54
+77
-54
@@ -241,6 +241,51 @@ static void parse_image_arg(char * arg, struct image_list ** image_first) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void filter_images_by_type(enum image_type type, struct image_list ** image_first) {
|
||||||
|
|
||||||
|
struct image_list * image_ptr = *image_first;
|
||||||
|
while ( image_ptr ) {
|
||||||
|
struct image_list * next = image_ptr->next;
|
||||||
|
if ( image_ptr->image->type != type ) {
|
||||||
|
image_list_del(image_ptr);
|
||||||
|
if ( image_ptr == *image_first )
|
||||||
|
*image_first = next;
|
||||||
|
}
|
||||||
|
image_ptr = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void filter_images_by_device(enum device device, struct image_list ** image_first) {
|
||||||
|
|
||||||
|
struct image_list * image_ptr = *image_first;
|
||||||
|
while ( image_ptr ) {
|
||||||
|
struct image_list * next = image_ptr->next;
|
||||||
|
if ( image_ptr->image->device != device && image_ptr->image->device != DEVICE_ANY ) {
|
||||||
|
image_list_del(image_ptr);
|
||||||
|
if ( image_ptr == *image_first )
|
||||||
|
*image_first = next;
|
||||||
|
}
|
||||||
|
image_ptr = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void filter_images_by_hwrev(const char * hwrev, struct image_list ** image_first) {
|
||||||
|
|
||||||
|
struct image_list * image_ptr = *image_first;
|
||||||
|
while ( image_ptr ) {
|
||||||
|
struct image_list * next = image_ptr->next;
|
||||||
|
if ( ! image_hwrev_is_valid(image_ptr->image, hwrev) ) {
|
||||||
|
image_list_del(image_ptr);
|
||||||
|
if ( image_ptr == *image_first )
|
||||||
|
*image_first = next;
|
||||||
|
}
|
||||||
|
image_ptr = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
const char * optstring = ""
|
const char * optstring = ""
|
||||||
@@ -348,14 +393,12 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
struct usb_device_info * usb_dev = NULL;
|
struct usb_device_info * usb_dev = NULL;
|
||||||
|
|
||||||
char hwrev[20];
|
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
||||||
simulate = 0;
|
simulate = 0;
|
||||||
noverify = 0;
|
noverify = 0;
|
||||||
verbose = 0;
|
verbose = 0;
|
||||||
|
|
||||||
memset(hwrev, 0, sizeof(hwrev));
|
|
||||||
show_title();
|
show_title();
|
||||||
|
|
||||||
while ( ( c = getopt(argc, argv, optstring) ) != -1 ) {
|
while ( ( c = getopt(argc, argv, optstring) ) != -1 ) {
|
||||||
@@ -547,54 +590,24 @@ int main(int argc, char **argv) {
|
|||||||
/* filter images by type */
|
/* filter images by type */
|
||||||
if ( filter_type ) {
|
if ( filter_type ) {
|
||||||
enum image_type type = image_type_from_string(filter_type_arg);
|
enum image_type type = image_type_from_string(filter_type_arg);
|
||||||
if ( ! type ) {
|
if ( ! type )
|
||||||
ERROR("Specified unknown image type for filtering: %s", filter_type_arg);
|
ERROR("Specified unknown image type for filtering: %s", filter_type_arg);
|
||||||
} else {
|
else
|
||||||
image_ptr = image_first;
|
filter_images_by_type(type, &image_first);
|
||||||
while ( image_ptr ) {
|
|
||||||
struct image_list * next = image_ptr->next;
|
|
||||||
if ( image_ptr->image->type != type ) {
|
|
||||||
image_list_del(image_ptr);
|
|
||||||
if ( image_ptr == image_first )
|
|
||||||
image_first = next;
|
|
||||||
}
|
|
||||||
image_ptr = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* filter images by device */
|
/* filter images by device */
|
||||||
if ( filter_device ) {
|
if ( filter_device ) {
|
||||||
enum device device = device_from_string(filter_device_arg);
|
enum device device = device_from_string(filter_device_arg);
|
||||||
if ( ! device ) {
|
if ( ! device )
|
||||||
ERROR("Specified unknown device for filtering: %s", filter_device_arg);
|
ERROR("Specified unknown device for filtering: %s", filter_device_arg);
|
||||||
} else {
|
else
|
||||||
image_ptr = image_first;
|
filter_images_by_device(device, &image_first);
|
||||||
while ( image_ptr ) {
|
|
||||||
struct image_list * next = image_ptr->next;
|
|
||||||
if ( image_ptr->image->device != device && image_ptr->image->device != DEVICE_ANY ) {
|
|
||||||
image_list_del(image_ptr);
|
|
||||||
if ( image_ptr == image_first )
|
|
||||||
image_first = next;
|
|
||||||
}
|
|
||||||
image_ptr = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* filter images by hwrev */
|
/* filter images by hwrev */
|
||||||
if ( filter_hwrev ) {
|
if ( filter_hwrev )
|
||||||
image_ptr = image_first;
|
filter_images_by_hwrev(filter_hwrev_arg, &image_first);
|
||||||
while ( image_ptr ) {
|
|
||||||
struct image_list * next = image_ptr->next;
|
|
||||||
if ( ! image_hwrev_is_valid(image_ptr->image, filter_hwrev_arg) ) {
|
|
||||||
image_list_del(image_ptr);
|
|
||||||
if ( image_ptr == image_first )
|
|
||||||
image_first = next;
|
|
||||||
}
|
|
||||||
image_ptr = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reorder images for flashing (first x-loader, second secondary) */
|
/* reorder images for flashing (first x-loader, second secondary) */
|
||||||
/* set 2nd and secondary images for cold-flashing */
|
/* set 2nd and secondary images for cold-flashing */
|
||||||
@@ -749,6 +762,12 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( dev_load && dev_flash ) {
|
||||||
|
ERROR("Options load and flash cannot de used together");
|
||||||
|
ret = 1;
|
||||||
|
goto clean;
|
||||||
|
}
|
||||||
|
|
||||||
if ( dev_boot || dev_reboot || dev_load || dev_flash || dev_cold_flash || dev_ident || set_root || set_usb || set_rd || set_rd_flags || set_hw || set_kernel || set_nolo || set_sw || set_emmc ) {
|
if ( dev_boot || dev_reboot || dev_load || dev_flash || dev_cold_flash || dev_ident || set_root || set_usb || set_rd || set_rd_flags || set_hw || set_kernel || set_nolo || set_sw || set_emmc ) {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -789,23 +808,17 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
usb_dev->detected_device = nolo_get_device(usb_dev);
|
usb_dev->detected_device = nolo_get_device(usb_dev);
|
||||||
if ( ! usb_dev->detected_device ) {
|
if ( ! usb_dev->detected_device )
|
||||||
printf("Cannot detect device\n");
|
printf("Device: (not detected)\n");
|
||||||
usb_close_device(usb_dev);
|
else
|
||||||
usb_dev = NULL;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Device: %s\n", device_to_string(usb_dev->detected_device));
|
printf("Device: %s\n", device_to_string(usb_dev->detected_device));
|
||||||
|
|
||||||
if ( nolo_get_hwrev(usb_dev, hwrev, sizeof(hwrev)) < 0 ) {
|
buf[0] = 0;
|
||||||
printf("Cannot detect HW revision\n");
|
nolo_get_hwrev(usb_dev, buf, sizeof(buf));
|
||||||
usb_close_device(usb_dev);
|
printf("HW revision: %s\n", buf[0] ? buf : "(not detected)");
|
||||||
usb_dev = NULL;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("HW revision: %s\n", hwrev);
|
if ( buf[0] )
|
||||||
|
usb_dev->detected_hwrev = strdup(buf);
|
||||||
|
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
nolo_get_nolo_ver(usb_dev, buf, sizeof(buf));
|
nolo_get_nolo_ver(usb_dev, buf, sizeof(buf));
|
||||||
@@ -874,11 +887,21 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
/* filter images by device & hwrev */
|
||||||
|
if ( usb_dev->detected_device )
|
||||||
|
filter_images_by_device(usb_dev->detected_device, &image_first);
|
||||||
|
if ( usb_dev->detected_hwrev )
|
||||||
|
filter_images_by_hwrev(usb_dev->detected_hwrev, &image_first);
|
||||||
|
|
||||||
/* load */
|
/* load */
|
||||||
|
if ( dev_load ) {
|
||||||
// if ( image_first )
|
// if ( image_first )
|
||||||
|
}
|
||||||
|
|
||||||
/* flash */
|
/* flash */
|
||||||
|
if ( dev_flash) {
|
||||||
// if ( image_first )
|
// if ( image_first )
|
||||||
|
}
|
||||||
|
|
||||||
/* configuration */
|
/* configuration */
|
||||||
if ( set_rd_flags ) {
|
if ( set_rd_flags ) {
|
||||||
|
|||||||
Reference in new issue
Block a user