From bd13c70d2be7c5f4cfe36b9b44ec293acb2b2f6f Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Fri, 21 Dec 2018 13:05:33 +0900 Subject: [PATCH] Use static partition node Label-based search for target partition node cannot be successfully proceed for all cases. So, this patch removes label-based search, and adds static partition node to information file to be used for target partition node. Change-Id: I2636ddabe9ea46f916d0faa4dd02a7a5bed3242a Signed-off-by: Dongwoo Lee --- partition.info | 16 +++++------ src/dfu.c | 83 ++++++++-------------------------------------------------- src/dfu.h | 5 +++- 3 files changed, 23 insertions(+), 81 deletions(-) diff --git a/partition.info b/partition.info index 833f9c2..6ad1cb6 100644 --- a/partition.info +++ b/partition.info @@ -1,8 +1,8 @@ -p:BOOT:boot.img:x -p:rootfs:rootfs.img:x -p:system-data:system-data.img:x -p:user:user.img:x -p:modules:modules.img:x -p:ramdisk:ramdisk.img:x -p:ramdisk-recovery:ramdisk-recovery.img:x -f:BOOT:Image:/ +p:/dev/mmcblk0p1:boot.img:x +p:/dev/mmcblk0p2:rootfs.img:x +p:/dev/mmcblk0p3:system-data.img:x +p:/dev/mmcblk0p5:user.img:x +p:/dev/mmcblk0p6:modules.img:x +p:/dev/mmcblk0p7:ramdisk.img:x +p:/dev/mmcblk0p8:ramdisk-recovery.img:x +f:/dev/mmcblk0p1:Image:/ diff --git a/src/dfu.c b/src/dfu.c index 4abfdf1..c7048f6 100644 --- a/src/dfu.c +++ b/src/dfu.c @@ -141,12 +141,12 @@ void dfu_sync(struct tfm_context *ctx) pthread_mutex_unlock(&ctx->dfu_sync_mutex); switch (*info[DFU_INFO_MODE]) { - case 'f': + case DFU_INFO_MODE_FILE: fsync(ctx->dfu_fd); close(ctx->dfu_fd); umount_dev(); break; - case 'p': + case DFU_INFO_MODE_PARTITION: close(ctx->dfu_fd); break; default: @@ -158,57 +158,6 @@ void dfu_sync(struct tfm_context *ctx) fprintf(stdout, "finished\n"); } -static char *get_partition_devname(const char *label) -{ - blkid_dev_iterate dev_iter; - blkid_tag_iterate tag_iter; - blkid_dev dev; - blkid_cache cache = NULL; - const char *type, *value; - int ret; - - ret = blkid_get_cache(&cache, NULL); - if (ret < 0) - return NULL; - - blkid_probe_all(cache); - - dev_iter = blkid_dev_iterate_begin(cache); - blkid_dev_set_search(dev_iter, NULL, NULL); - while (blkid_dev_next(dev_iter, &dev) == 0) { - dev = blkid_verify(cache, dev); - if (!dev) - continue; - - tag_iter = blkid_tag_iterate_begin(dev); - while (blkid_tag_next(tag_iter, &type, &value) == 0) { - if (!strncmp(type, "LABEL", 5) && !strncmp(value, label, strlen(label))) { - char *devname = strdup(blkid_dev_devname(dev)); - - /* - * To distinguish physical partition and ram mounted partition, - * continue to search the next entry if the devname includes - * 'ram'(eg. /dev/ram0). - */ - if (strstr(devname, "ram")) { - free(devname); - continue; - } - - blkid_tag_iterate_end(tag_iter); - blkid_dev_iterate_end(dev_iter); - blkid_put_cache(cache); - return devname; - } - } - blkid_tag_iterate_end(tag_iter); - } - blkid_dev_iterate_end(dev_iter); - blkid_put_cache(cache); - - return NULL; -} - static char *get_partition_fstype(const char *devname) { blkid_tag_iterate tag_iter; @@ -254,34 +203,25 @@ static int dfu_start_entity(struct tfm_context *ctx, int idx, unsigned long size int fd; switch (*info[DFU_INFO_MODE]) { - case 'p': - file = get_partition_devname(info[DFU_INFO_LABEL]); - if (!file) { - fprintf(stderr, "failed to get partition devname: %s", info[DFU_INFO_LABEL]); - return -EINVAL; - } + case DFU_INFO_MODE_PARTITION: + file = strdup(info[DFU_INFO_PARTITION]); + if (!file) + return -ENOMEM; break; - case 'f': + case DFU_INFO_MODE_FILE: { int path_prefix = strlen(DFU_MOUNT_PATH); int path_suffix = strlen(info[DFU_INFO_PATH]); int path_name = strlen(info[DFU_INFO_NAME]); - char *devname, *fstype; + char fstype; - devname = get_partition_devname(info[DFU_INFO_LABEL]); - if (!devname) { - fprintf(stderr, "failed to get partition devname: %s", info[DFU_INFO_LABEL]); - return -EINVAL; - } - - fstype = get_partition_fstype(devname); + fstype = get_partition_fstype(info[DFU_INFO_PARTITION]); if (!fstype) { - fprintf(stderr, "failed to get partition filesystem type: %s", devname); + fprintf(stderr, "failed to get partition filesystem type: %s", info[DFU_INFO_PARTITION]); return -EINVAL; } - mount_dev(devname, fstype); - free(devname); + mount_dev(info[DFU_INFO_PARTITION], fstype); free(fstype); file = malloc(path_prefix + path_suffix + path_name + 1); @@ -315,7 +255,6 @@ static int dfu_start_entity(struct tfm_context *ctx, int idx, unsigned long size return 0; } - int dfu_start(struct tfm_context *ctx, const char *entity) { unsigned long size = ctx->thor_file_size; diff --git a/src/dfu.h b/src/dfu.h index afc3e28..589a9a1 100644 --- a/src/dfu.h +++ b/src/dfu.h @@ -24,9 +24,12 @@ #define DFU_INFO_NUM 100 #define DFU_MOUNT_PATH "/mnt/tfm-temp" +#define DFU_INFO_MODE_PARTITION 'p' +#define DFU_INFO_MODE_FILE 'f' + enum dfu_info_entry { DFU_INFO_MODE = 0, - DFU_INFO_LABEL, + DFU_INFO_PARTITION, DFU_INFO_NAME, DFU_INFO_PATH, DFU_INFO_MAX, -- 2.7.4