diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c index 92b33b89..cd27679f 100644 --- a/drivers/fastboot/fb_command.c +++ b/drivers/fastboot/fb_command.c @@ -294,6 +294,56 @@ int check_image_board_id(uint8_t *image_data) return 0; } +int hibernate_image_cleaned_flag = 0; +static void clean_hibernate_image_header(char *response) +{ + struct blk_desc *dev_desc; + disk_partition_t info; + if(0x03 == hibernate_image_cleaned_flag) //already erased all + { + return; + } + dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); + if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { + fastboot_fail("invalid mmc device", response); + return; + } + char * buf = memalign(CONFIG_SYS_CACHELINE_SIZE,4096); + if(!buf) { + printf(" mem alloc for hibernate partition header failed!\n"); + return; + } + /* if fastresume partition exists, earse the old image header */ + if(part_get_info_by_name(dev_desc, "fastresume", &info)) { + printf(" find fastresume partition , erase the header:\n"); + memset(buf,0xff,4096); + if(blk_dwrite(dev_desc, info.start, 4096/info.blksz, buf) != 4096/info.blksz) + { + printf(" fastresume header write failed!\n"); + hibernate_image_cleaned_flag = 0; + } + else + { + hibernate_image_cleaned_flag |= 0x1; + } + } + /* if swap partition exists, earse the old image header */ + if(part_get_info_by_name(dev_desc, "swap", &info)) { + printf(" find swap partition , erase the header:\n"); + memset(buf,0xff,4096); + if(blk_dwrite(dev_desc, info.start, 4096/info.blksz, buf) != 4096/info.blksz) + { + printf(" swap header write failed!\n"); + hibernate_image_cleaned_flag = 0; + } + else + { + hibernate_image_cleaned_flag |= 0x2; + } + } + free(buf); +} + #if CONFIG_IS_ENABLED(FASTBOOT_FLASH) /** * flash() - write the downloaded image to the indicated partition. @@ -352,25 +402,16 @@ static void flash(char *cmd_parameter, char *response) memcpy((void *)LIGHT_TF_FW_ADDR, fastboot_buf_addr, image_size); } else if ((strcmp(cmd_parameter, TEE_PART_NAME) == 0)) { memcpy((void *)LIGHT_TEE_FW_ADDR, fastboot_buf_addr, image_size); - } else if ((strcmp(cmd_parameter, "boot") == 0)) { - dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); - if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { - fastboot_fail("invalid mmc device", response); - return; - } - /* if fastresume partition exists, earse the old image header */ - if(part_get_info_by_name(dev_desc, "fastresume", &info)) { - printf(" find fastresume partition , erase the header:\n"); - char * buf = memalign(CONFIG_SYS_CACHELINE_SIZE,4096); - if(!buf) { - printf(" fastresume partition header mem alloc failed\n"); - return; - } - memset(buf,0xff,4096); - blk_dwrite(dev_desc, info.start, 4096/info.blksz, buf); - free(buf); - } } + + //If version is updated, hibernate image may not compatible with current,erase it. + if ((strcmp(cmd_parameter, "boot") == 0) + || (strcmp(cmd_parameter, "uboot") == 0) + || (strcmp(cmd_parameter, "root") == 0)) { + + clean_hibernate_image_header(response); + } + if(strcmp(cmd_parameter, "uboot") == 0 || (strcmp(cmd_parameter, "fw") == 0) || (strcmp(cmd_parameter, "uImage") == 0) || (strcmp(cmd_parameter, "dtb") == 0) || (strcmp(cmd_parameter, "rootfs") == 0) || (strcmp(cmd_parameter, "aon") == 0)) {