image: Use device_list
This commit is contained in:
1 parent
e41cf5236a
commit
55c158fc34
2 files changed
+68
-26
No files matched your search
+67
-24
@@ -73,15 +73,18 @@ static void image_missing_values_from_name(struct image * image, const char * na
|
|||||||
image->type = image_type_from_string(type);
|
image->type = image_type_from_string(type);
|
||||||
free(type);
|
free(type);
|
||||||
|
|
||||||
if ( ! image->device || image->device == DEVICE_ANY ) {
|
if ( ! image->devices || image->devices->device || image->devices->device == DEVICE_ANY ) {
|
||||||
new_device = device_from_string(device);
|
new_device = device_from_string(device);
|
||||||
if ( new_device )
|
if ( new_device ) {
|
||||||
image->device = new_device;
|
if ( ! image->devices ) image->devices = calloc(1, sizeof(struct device_list));
|
||||||
|
if ( image->devices )
|
||||||
|
image->devices->device = new_device;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free(device);
|
free(device);
|
||||||
|
|
||||||
if ( ! image->hwrevs )
|
if ( image->devices && image->devices->device && ! image->devices->hwrevs )
|
||||||
image->hwrevs = hwrevs;
|
image->devices->hwrevs = hwrevs_alloc_from_string(hwrevs);
|
||||||
else
|
else
|
||||||
free(hwrevs);
|
free(hwrevs);
|
||||||
|
|
||||||
@@ -97,22 +100,32 @@ char * image_name_alloc_from_values(struct image * image) {
|
|||||||
|
|
||||||
char * name;
|
char * name;
|
||||||
char * ptr;
|
char * ptr;
|
||||||
|
char * hwrevs;
|
||||||
size_t length;
|
size_t length;
|
||||||
const char * type;
|
const char * type;
|
||||||
const char * device;
|
const char * device;
|
||||||
|
|
||||||
type = image_type_to_string(image->type);
|
type = image_type_to_string(image->type);
|
||||||
device = device_to_string(image->device);
|
|
||||||
|
|
||||||
if ( ! type )
|
if ( ! type )
|
||||||
type = "unknown";
|
type = "unknown";
|
||||||
|
|
||||||
|
if ( image->devices )
|
||||||
|
device = device_to_string(image->devices->device);
|
||||||
|
else
|
||||||
|
device = NULL;
|
||||||
|
|
||||||
|
if ( image->devices && image->devices->hwrevs )
|
||||||
|
hwrevs = hwrevs_alloc_to_string(image->devices->hwrevs);
|
||||||
|
else
|
||||||
|
hwrevs = NULL;
|
||||||
|
|
||||||
length = 1 + strlen(type);
|
length = 1 + strlen(type);
|
||||||
|
|
||||||
if ( device )
|
if ( device )
|
||||||
length += 1 + strlen(device);
|
length += 1 + strlen(device);
|
||||||
if ( image->hwrevs )
|
if ( hwrevs )
|
||||||
length += 1 + strlen(image->hwrevs);
|
length += 1 + strlen(hwrevs);
|
||||||
if ( image->version )
|
if ( image->version )
|
||||||
length += 1 + strlen(image->version);
|
length += 1 + strlen(image->version);
|
||||||
|
|
||||||
@@ -125,11 +138,13 @@ char * image_name_alloc_from_values(struct image * image) {
|
|||||||
|
|
||||||
if ( device )
|
if ( device )
|
||||||
ptr += sprintf(ptr, "-%s", device);
|
ptr += sprintf(ptr, "-%s", device);
|
||||||
if ( image->hwrevs )
|
if ( hwrevs )
|
||||||
ptr += sprintf(ptr, ":%s", image->hwrevs);
|
ptr += sprintf(ptr, ":%s", hwrevs);
|
||||||
if ( image->version )
|
if ( image->version )
|
||||||
ptr += sprintf(ptr, "_%s", image->version);
|
ptr += sprintf(ptr, "_%s", image->version);
|
||||||
|
|
||||||
|
free(hwrevs);
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -139,11 +154,16 @@ static int image_append(struct image * image, const char * type, const char * de
|
|||||||
enum image_type detected_type;
|
enum image_type detected_type;
|
||||||
|
|
||||||
image->hash = image_hash_from_data(image);
|
image->hash = image_hash_from_data(image);
|
||||||
image->device = DEVICE_ANY;
|
|
||||||
|
image->devices = calloc(1, sizeof(struct device_list));
|
||||||
|
if ( ! image->devices )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
image->devices->device = DEVICE_ANY;
|
||||||
|
|
||||||
if ( device && device[0] ) {
|
if ( device && device[0] ) {
|
||||||
image->device = device_from_string(device);
|
image->devices->device = device_from_string(device);
|
||||||
if ( ! noverify && image->device == DEVICE_UNKNOWN ) {
|
if ( ! noverify && image->devices->device == DEVICE_UNKNOWN ) {
|
||||||
ERROR("Specified Device %s is unknown", device);
|
ERROR("Specified Device %s is unknown", device);
|
||||||
image_free(image);
|
image_free(image);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -168,9 +188,9 @@ static int image_append(struct image * image, const char * type, const char * de
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( hwrevs && hwrevs[0] )
|
if ( hwrevs && hwrevs[0] )
|
||||||
image->hwrevs = strdup(hwrevs);
|
image->devices->hwrevs = hwrevs_alloc_from_string(hwrevs);
|
||||||
else
|
else
|
||||||
image->hwrevs = NULL;
|
image->devices->hwrevs = NULL;
|
||||||
|
|
||||||
if ( version && version[0] )
|
if ( version && version[0] )
|
||||||
image->version = strdup(version);
|
image->version = strdup(version);
|
||||||
@@ -285,7 +305,13 @@ void image_free(struct image * image) {
|
|||||||
image->fd = -1;
|
image->fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(image->hwrevs);
|
while ( image->devices ) {
|
||||||
|
struct device_list * next = image->devices->next;
|
||||||
|
free(image->devices->hwrevs);
|
||||||
|
free(image->devices);
|
||||||
|
image->devices = next;
|
||||||
|
}
|
||||||
|
|
||||||
free(image->version);
|
free(image->version);
|
||||||
free(image->layout);
|
free(image->layout);
|
||||||
free(image->orig_filename);
|
free(image->orig_filename);
|
||||||
@@ -516,7 +542,7 @@ const char * image_type_to_string(enum image_type type) {
|
|||||||
|
|
||||||
int image_hwrev_is_valid(struct image * image, const char * hwrev) {
|
int image_hwrev_is_valid(struct image * image, const char * hwrev) {
|
||||||
|
|
||||||
const char * ptr = image->hwrevs;
|
/* const char * ptr = image->hwrevs;
|
||||||
const char * oldptr = ptr;
|
const char * oldptr = ptr;
|
||||||
|
|
||||||
if ( ! hwrev || ! ptr )
|
if ( ! hwrev || ! ptr )
|
||||||
@@ -532,13 +558,15 @@ int image_hwrev_is_valid(struct image * image, const char * hwrev) {
|
|||||||
if ( strcmp(hwrev, oldptr) == 0 )
|
if ( strcmp(hwrev, oldptr) == 0 )
|
||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;*/
|
||||||
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void image_print_info(struct image * image) {
|
void image_print_info(struct image * image) {
|
||||||
|
|
||||||
const char * str;
|
const char * str;
|
||||||
|
struct device_list * device = image->devices;
|
||||||
|
|
||||||
if ( image->orig_filename )
|
if ( image->orig_filename )
|
||||||
printf("File: %s\n", image->orig_filename);
|
printf("File: %s\n", image->orig_filename);
|
||||||
@@ -550,15 +578,30 @@ void image_print_info(struct image * image) {
|
|||||||
if ( image->version )
|
if ( image->version )
|
||||||
printf(" Image version: %s\n", image->version);
|
printf(" Image version: %s\n", image->version);
|
||||||
|
|
||||||
if ( image->device == DEVICE_UNKNOWN )
|
while ( device ) {
|
||||||
str = "unknown device";
|
|
||||||
|
char * str2 = NULL;
|
||||||
|
struct device_list * next = device->next;
|
||||||
|
|
||||||
|
if ( device->device == DEVICE_UNKNOWN )
|
||||||
|
str = "unknown";
|
||||||
else
|
else
|
||||||
str = device_to_string(image->device);
|
str = device_to_string(device->device);
|
||||||
|
|
||||||
if ( str )
|
if ( str )
|
||||||
printf(" Valid for device: %s\n", str);
|
printf(" Valid for: device %s", str);
|
||||||
|
|
||||||
if ( image->hwrevs )
|
if ( str && device->hwrevs )
|
||||||
printf(" Valid for HW revisions: %s\n", image->hwrevs);
|
str2 = hwrevs_alloc_to_string(device->hwrevs);
|
||||||
|
|
||||||
|
if ( str2 ) {
|
||||||
|
printf(", HW revisions: %s\n", str2);
|
||||||
|
free(str2);
|
||||||
|
} else {
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
device = next;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-2
@@ -42,8 +42,7 @@ enum image_type {
|
|||||||
|
|
||||||
struct image {
|
struct image {
|
||||||
enum image_type type;
|
enum image_type type;
|
||||||
enum device device;
|
struct device_list * devices;
|
||||||
char * hwrevs;
|
|
||||||
char * version;
|
char * version;
|
||||||
char * layout;
|
char * layout;
|
||||||
uint16_t hash;
|
uint16_t hash;
|
||||||
|
|||||||
Reference in new issue
Block a user