diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 70 |
1 files changed, 53 insertions, 17 deletions
@@ -143,7 +143,7 @@ int simulate; int noverify; int verbose; -/* arg = [[[dev:[hw:]]ver:]type:]file[%%lay] */ +/* arg = [[[dev:[hw:]]ver:]type:]file[%file2%file3...%lay] */ static void parse_image_arg(char * arg, struct image_list ** image_first) { struct stat st; @@ -154,14 +154,16 @@ static void parse_image_arg(char * arg, struct image_list ** image_first) { char * hwrevs; char * version; char * layout; + char * parts; char * layout_file; + char * ptr; int fd; /* First check if arg is file, then try to parse arg format */ fd = open(arg, O_RDONLY); if ( fd >= 0 ) { if ( fstat(fd, &st) == 0 && !S_ISDIR(st.st_mode) ) { - image = image_alloc_from_fd(fd, arg, NULL, NULL, NULL, NULL, NULL); + image = image_alloc_from_fd(fd, arg, NULL, NULL, NULL, NULL, NULL, NULL); if ( ! image ) { ERROR("Cannot load image file %s", arg); exit(1); @@ -175,9 +177,15 @@ static void parse_image_arg(char * arg, struct image_list ** image_first) { exit(1); } - layout_file = strchr(arg, '%'); - if ( layout_file ) - *(layout_file++) = 0; + parts = strchr(arg, '%'); + if ( parts ) + *(parts++) = 0; + + layout_file = parts; + if ( layout_file ) { + while ( ( ptr = strchr(layout_file, '%') ) ) + layout_file = ptr+1; + } type = NULL; device = NULL; @@ -237,7 +245,9 @@ static void parse_image_arg(char * arg, struct image_list ** image_first) { close(fd); } - image = image_alloc_from_file(file, type, device, hwrevs, version, layout); + /* TODO: alloc parts */ + + image = image_alloc_from_file(file, type, device, hwrevs, version, layout, NULL); if ( layout ) free(layout); @@ -426,6 +436,8 @@ int main(int argc, char **argv) { int i; char buf[512]; char * ptr = NULL; + char * ptr1 = NULL; + char * ptr2 = NULL; char * tmp = NULL; char nolo_ver[512]; @@ -1036,9 +1048,9 @@ int main(int argc, char **argv) { /* filter images by device & hwrev */ if ( detected_device ) filter_images_by_device(dev->detected_device, &image_first); - if ( detected_hwrev ) + if ( detected_hwrev > 0 ) filter_images_by_hwrev(dev->detected_hwrev, &image_first); - if ( fiasco_in && ( detected_device || detected_hwrev ) ) + if ( fiasco_in && ( detected_device || detected_hwrev > 0 ) ) fiasco_in->first = image_first; /* set kernel and initfs images for loading */ @@ -1096,7 +1108,7 @@ int main(int argc, char **argv) { if ( dev_load ) { if ( image_kernel ) { ret = dev_load_image(dev, image_kernel->image); - if ( ret < 0 ) + if ( ret == -EAGAIN ) goto again; if ( image_kernel == image_first ) @@ -1110,7 +1122,7 @@ int main(int argc, char **argv) { if ( image_initfs ) { ret = dev_load_image(dev, image_initfs->image); - if ( ret < 0 ) + if ( ret == -EAGAIN ) goto again; if ( image_initfs == image_first ) @@ -1129,7 +1141,7 @@ int main(int argc, char **argv) { while ( image_ptr ) { struct image_list * next = image_ptr->next; ret = dev_flash_image(dev, image_ptr->image); - if ( ret < 0 ) + if ( ret == -EAGAIN ) goto again; if ( image_ptr == image_first ) @@ -1265,7 +1277,8 @@ int main(int argc, char **argv) { continue; buf[0] = 0; - snprintf(buf, sizeof(buf), "%hd", dev->detected_hwrev); + if ( dev->detected_hwrev > 0 ) + snprintf(buf, sizeof(buf), "%hd", dev->detected_hwrev); switch ( i ) { case IMAGE_2ND: @@ -1295,7 +1308,9 @@ int main(int argc, char **argv) { break; } - image_dump = image_alloc_from_file(image_tmp_name(i), image_type_to_string(i), device_to_string(dev->detected_device), buf, ptr, NULL); + /* TODO: add support for dumping mmc layout and also other mmc partitions as image data parts */ + + image_dump = image_alloc_from_file(image_tmp_name(i), image_type_to_string(i), device_to_string(dev->detected_device), buf, ptr, NULL, NULL); if ( ! image_dump ) continue; @@ -1366,7 +1381,20 @@ int main(int argc, char **argv) { } buf[0] = 0; - snprintf(buf, sizeof(buf), "%s-%s:%hd_%s", image_type_to_string(i), device_to_string(dev->detected_device), dev->detected_hwrev, ptr); + snprintf(buf, sizeof(buf), "%s", image_type_to_string(i)); + ptr1 = buf + strlen(buf); + + if ( dev->detected_device ) { + snprintf(ptr1, sizeof(buf)-(ptr1-buf), "-%s", device_to_string(dev->detected_device)); + ptr1 += strlen(ptr1); + } + + if ( dev->detected_hwrev > 0 ) + snprintf(ptr1, sizeof(buf)-(ptr1-buf), ":%hd", dev->detected_hwrev); + ptr2 = ptr1 + strlen(ptr1); + + if ( ptr && ptr[0] ) + snprintf(ptr2, sizeof(buf)-(ptr2-buf), "_%s", ptr); rename_ret = rename(image_tmp_name(i), buf); rename_errno = errno; @@ -1381,13 +1409,21 @@ int main(int argc, char **argv) { errno = rename_errno; ERROR_INFO("Renaming failed"); - buf[0] = 0; - snprintf(buf, sizeof(buf), "%s-%s_%s", image_type_to_string(i), device_to_string(dev->detected_device), ptr); + *ptr2 = 0; printf("Trying to rename %s image file to %s...\n", image_type_to_string(i), buf); - if ( rename(image_tmp_name(i), buf) < 0 ) + if ( rename(image_tmp_name(i), buf) < 0 ) { + ERROR_INFO("Renaming failed"); + *ptr1 = 0; + printf("Trying to rename %s image file to %s...\n", image_type_to_string(i), buf); + + if ( rename(image_tmp_name(i), buf) < 0 ) + ERROR_INFO("Renaming failed"); + + } + } } |