diff --git a/tools/sysupgrade.c b/tools/sysupgrade.c index a74705e807..e195c9efc0 100644 --- a/tools/sysupgrade.c +++ b/tools/sysupgrade.c @@ -794,7 +794,7 @@ int get_ubi_volume_id(char *vol_name) fgets(ubi_vol_name, sizeof(ubi_vol_name), fp); if (strstr(ubi_vol_name, vol_name)) { printf("%s volume id = %d\n", vol_name, i); - close(fp); + fclose(fp); return i; } } @@ -811,10 +811,11 @@ int get_ubi_volume_id(char *vol_name) * to get the ELF header of rootfs metadata. */ -void extract_binary(struct image_section *section) +int extract_binary(struct image_section *section) { extract_kernel_binary(section, "kernel"); parse_elf_image_phdr(section); + return 1; } /** @@ -1013,7 +1014,7 @@ int extract_rootfs_binary(char *filename) fp = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, ifd, 0); if (fp == MAP_FAILED) { perror("mmap"); - close(fp); + close(ifd); return 0; } @@ -1049,13 +1050,16 @@ int compute_sha_hash(struct image_section *section) int retval; #ifdef USE_SHA384 - snprintf(command, sizeof(command), + retval = snprintf(command, sizeof(command), "openssl dgst -sha384 -binary -out %s %s", sha_hash, section->tmp_file); #endif #ifdef USE_SHA256 - snprintf(command, sizeof(command), + retval = snprintf(command, sizeof(command), "openssl dgst -sha256 -binary -out %s %s", sha_hash, section->tmp_file); #endif + if (retval < 0) { + return retval; + } retval = system(command); if (retval != 0) { printf("Error generating sha-hash, command : %s\n",command); diff --git a/tools/sysupgrade.h b/tools/sysupgrade.h index f0bd19a67e..bdca2405bf 100644 --- a/tools/sysupgrade.h +++ b/tools/sysupgrade.h @@ -113,8 +113,10 @@ int is_version_check_enabled(void); int get_sw_id_from_component_bin(struct image_section *); int get_sw_id_from_component_bin_elf(struct image_section *); int get_sw_id_from_component_bin_elf64(struct image_section *); -void extract_binary(struct image_section *); +int extract_binary(struct image_section *); int extract_kernel_binary(struct image_section *, char *); +int extract_ubi_volume(char *, char *, char *); +int extract_rootfs_binary(char *); int is_image_version_higher(void); int update_version(void); int check_image_version(void);