#define DFU_DELIMITER " :,\t\n"
#define DFU_ENTRY_LIST_MAXLEN 100
#define DFU_MOUNT_PATH "/mnt/tfm-temp"
+#define DFU_MOUNT_B_PATH "/mnt/tfm-temp-b"
+
+#define PATH_A 0
+#define PATH_B 1
#define DFU_INFO_MODE_PARTITION 'p'
#define DFU_INFO_MODE_FILE 'f'
return fstype;
}
-static int mount_dev(const char *dev)
+static int mount_dev(const char *dev, int is_b)
{
int ret;
char *fstype;
+ char *mount_path;
+
+ mount_path = is_b ? DFU_MOUNT_B_PATH : DFU_MOUNT_PATH;
- ret = mkdir(DFU_MOUNT_PATH, 0600);
+ ret = mkdir(mount_path, 0600);
if (ret < 0) {
- fprintf(stderr, "Failed to create target directory\n");
+ fprintf(stderr, "Failed to create target directory %s\n", mount_path);
return ret;
}
return -EINVAL;
}
- ret = mount(dev, DFU_MOUNT_PATH, fstype, 0, NULL);
+ ret = mount(dev, mount_path, fstype, 0, NULL);
if (ret < 0) {
fprintf(stderr, "Failed to mount target partition\n");
- rmdir(DFU_MOUNT_PATH);
+ rmdir(mount_path);
}
free(fstype);
return ret;
}
-static void umount_dev(void)
+static void umount_dev(int is_b)
{
int ret;
+ char *mount_path;
- ret = umount(DFU_MOUNT_PATH);
+ mount_path = is_b ? DFU_MOUNT_B_PATH : DFU_MOUNT_PATH;
+
+ ret = umount(mount_path);
if (ret < 0)
fprintf(stderr, "Failed to unmount target partition\n");
/* whether umount is succeed or not, continue to try deleting mount point */
- rmdir(DFU_MOUNT_PATH);
+ rmdir(mount_path);
}
static void dfu_thread_cleanup(void *ptr)
break;
case DFU_INFO_MODE_FILE:
{
- int path_prefix = strlen(DFU_MOUNT_PATH);
+ int path_prefix = strlen(DFU_MOUNT_B_PATH);
int path_suffix = strlen(entry[DFU_INFO_PATH]);
int path_name = strlen(entry[DFU_INFO_NAME]);
- ret = mount_dev(entry[DFU_INFO_PARTITION]);
+ ret = mount_dev(entry[DFU_INFO_PARTITION], PATH_B);
if (ret < 0)
return -EINVAL;
file = malloc(path_prefix + path_suffix + path_name + 1);
if (!file) {
- umount_dev();
+ umount_dev(PATH_B);
return -ENOMEM;
}
- strncpy(file, DFU_MOUNT_PATH, path_prefix + 1);
+ strncpy(file, DFU_MOUNT_B_PATH, path_prefix + 1);
strncat(file, entry[DFU_INFO_PATH], path_suffix + 1);
strncat(file, entry[DFU_INFO_NAME], path_name + 1);
break;
int path_suffix = strlen(entry[DFU_INFO_PATH]);
int path_name = strlen(entry[DFU_INFO_NAME]);
- ret = mount_dev(entry[DFU_INFO_PARTITION]);
+ ret = mount_dev(entry[DFU_INFO_PARTITION], PATH_A);
if (ret < 0)
return -EINVAL;
file = malloc(path_prefix + path_suffix + path_name + 1);
if (!file) {
- umount_dev();
+ umount_dev(PATH_A);
return -ENOMEM;
}
close(e->fd);
close(e->fd_b);
- if (*info[DFU_INFO_MODE] == DFU_INFO_MODE_FILE)
- umount_dev();
+ if (*info[DFU_INFO_MODE] == DFU_INFO_MODE_FILE) {
+ umount_dev(PATH_A);
+ if (e->is_update_ab)
+ umount_dev(PATH_B);
+ }
pthread_cond_signal(&ctx->sync_done);
}