How does OTA update emmc firmware

方案设计:
ota升级进程update-binary实现FFU方式升级EMMC固件
编译流程内安装EMMC固件到ota包内
ota升级进程update-binary解析ota包 获取emmc固件,如果能成功获取则调用升级EMMC固件函数DoEmmc50FFU

  1. ota升级进程update-binary实现FFU方式升级EMMC固件
    AOSP/bootable/recovery/upadter/updater.cpp:

升级EMMC固件函数DoEmmc50FFU实现:

//如下是需要包含的头文件 其中mmc.h是从AOSP/external/mmc-utils/mmc.h拷贝过来

#include “mmc.h”
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#define MMC_FFU_DOWNLOAD_OP 302
#define MMC_IOC_FFU_MAX_BYTES 10241024 //1M
#define MMC_IOC_FFU_CMD _IOWR(179, 2, struct mmc_ioc_cmd)
static constexpr const char
EMMC_FIRMWARE_NAME = “emmc_firmware_upgrade.bin”;

static int FFUExecute(int fwfd, int devfd)
{

int ret = 0;
struct mmc_ioc_cmd idata;
char data_buff[MMC_IOC_FFU_MAX_BYTES];
int file_size;
int data_length;

memset(data_buff, 0, sizeof(data_buff));
/* get file size */
file_size = lseek(fwfd, 0, SEEK_END);
if (file_size < 0) {
    ret = -1;
    LOG(ERROR) << "Failed to lseek file";
    goto exit;
}
lseek(fwfd, 0, SEEK_SET);

if (file_size > MMC_IOC_FFU_MAX_BYTES)  {

     ret = -1;

    LOG(ERROR) << "Fimware file size too large, max size: " << MMC_IOC_FFU_MAX_BYTES << " , but file size: " << file_size;
    goto exit;
} else {

    /* Read FW data from file */
    data_length = read(fwfd, data_buff, file_size);
    if (data_length == -1) {
        ret = -1;
        LOG(ERROR) << "Failed to read fwfd";
        goto exit;
    }

    /* prepare and send ioctl */
    memset(&idata, 0, sizeof(idata));
    idata.write_flag = 1;
    idata.opcode = MMC_FFU_DOWNLOAD_OP;
    idata.arg = 0;
    idata.blksz = 512;
    idata.blocks = (data_length + idata.blksz - 1) / idata.blksz;
    idata.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
    mmc_ioc_cmd_set_data(idata, data_buff);

    ret = ioctl(devfd, MMC_IOC_FFU_CMD, &idata);
   if (ret < 0) {
       LOG(ERROR) << "Failed to execute ioctl";
       goto exit;
    }
}

exit:
return ret;
}

static int DoEmmc50FFU(const std::string & firmware, const std::string & bootdevice, int (*ffu_execute)(int , int))
{
int devfd, fwfd, ret = 0;
const char *emmc_firmware, *boot_device;

boot_device = bootdevice.c_str();
devfd = open(boot_device, O_RDWR);
if (devfd < 0) {
    LOG(ERROR) << "Failed to open boot device: " << boot_device;
    ret = -1;
    return ret;
}

emmc_firmware = firmware.c_str();
fwfd = open(emmc_firmware, O_RDONLY);
if (fwfd < 0) {
    LOG(ERROR) << "Failed to open emmc firmware: " << emmc_firmware;
    ret = -1;
    goto exit;
}

ret = ffu_execute(fwfd, devfd);//callback
if (ret) {
    LOG(ERROR) << "Failed to update emmc firmware";
}
close(fwfd);

exit:
close(devfd);
return ret;
}

2.编译流程内安装EMMC固件到ota包内

//build/make/core/Makefile

//Makefile 将EMMC固件拷贝到make otapackage生成的临时文件内

diff --git a/core/Makefile b/core/Makefile
old mode 100644
new mode 100755
index a11db20…067d8f3
— a/core/Makefile
+++ b/core/Makefile
@@ -2358,6 +2358,10 @@ ifeq ($(TARGET_BUILD_TYPE),debug)
endif
name := ( n a m e ) − t a r g e t f i l e s − (name)-target_files- (name)targetfiles(FILE_NAME_TAG)

+#[BSP] add 20180917 start
+EMMC_FIRMWARE_FILE := $(PRODUCT_OUT)/emmc_firmware_upgrade.bin
+#[BSP] add 20180917 end
+
intermediates := $(call intermediates-dir-for,PACKAGING,target_files)
BUILT_TARGET_FILES_PACKAGE := ( i n t e r m e d i a t e s ) / (intermediates)/ (intermediates)/(name).zip
$(BUILT_TARGET_FILES_PACKAGE): intermediates := ( i n t e r m e d i a t e s ) @ @ − 2543 , 6 + 2547 , 13 @ @ i f n e q ( (intermediates) @@ -2543,6 +2547,13 @@ ifneq ( (intermediates)@@2543,6+2547,13@@ifneq((built_ota_tools),)
$(hide) cp $(PRIVATE_OTA_TOOLS) KaTeX parse error: Expected 'EOF', got '#' at position 36: …endif endif + +#̲[BSP] add star…(EMMC_FIRMWARE_FILE),$(wildcard $(EMMC_FIRMWARE_FILE)))

  • $(hide) cp $(EMMC_FIRMWARE_FILE) $(zip_root)/OTA/
    +endif
    +#[BSP] add end

@# Files that do not end up in any images, but are necessary to
@# build them.
$(hide) mkdir -p $(zip_root)/META

//差分OTA脚本从临时包内将EMMC固件提取压缩到OTA包内

//build/make/tools/releasetools/ota_from_target_files.py

diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py
index a742e29…7a30588 100755
— a/tools/releasetools/ota_from_target_files.py
+++ b/tools/releasetools/ota_from_target_files.py
@@ -368,6 +368,19 @@ def AddCompatibilityArchive(target_zip, output_zip, system_included=True,
arcname=“compatibility.zip”,
compress_type=zipfile.ZIP_STORED)

+#[BSP] add start
+def AddEmmcFirmware(script, input_zip, output_zip):

  • def hasFile(filename):
  • try:
  • input_zip.getinfo(filename)
  • return True
  • except KeyError:
  • return False
  • if hasFile(“OTA/emmc_firmware_upgrade.bin”):
  • data = input_zip.read(“OTA/emmc_firmware_upgrade.bin”)
  • common.ZipWriteStr(output_zip, “emmc_firmware_upgrade.bin”,data)
    +#[BSP] add end

def WriteFullOTAPackage(input_zip, output_zip):

TODO: how to determine this? We don’t know what version it will

@@ -538,7 +551,9 @@ endif;
script.AddToZip(input_zip, output_zip, input_path=OPTIONS.updater_binary)
metadata[“ota-required-cache”] = str(script.required_cache)
WriteMetadata(metadata, output_zip)

  • #[BSP] add start
  • AddEmmcFirmware(script, input_zip, output_zip)
  • #[BSP] add end

def WritePolicyConfig(file_name, output_zip):
common.ZipWrite(output_zip, file_name, os.path.basename(file_name))
@@ -896,6 +911,9 @@ endif;

def WriteBlockIncrementalOTAPackage(target_zip, source_zip, output_zip):
script.AddToZip(target_zip, output_zip, input_path=OPTIONS.updater_binary)
metadata[“ota-required-cache”] = str(script.required_cache)
WriteMetadata(metadata, output_zip)

  • #[BSP] add start
  • AddEmmcFirmware(script, target_zip, output_zip);
  • #[BSP] add end

def WriteVerifyPackage(input_zip, output_zip):

EMMC固件——Beta1_CAM53216_V25_180903.Bin 放到/AOSP/device/transsion/id3a/内,并修改device.mk将固件拷贝到编译目录下

diff --git a/id3a_h612/device.mk b/id3a_h612/device.mk
index 0ec4b34…1e8862a 100755
— a/id3a_h612/device.mk
+++ b/id3a_h612/device.mk
@@ -137,3 +137,10 @@ ifeq ($(strip KaTeX parse error: Expected 'EOF', got '#' at position 98: …ram=true endif #̲[PPD] add by f…(strip $(TRAN_UPDATE_EMMC_FIMRWARE)), yes)
+PRODUCT_COPY_FILES += ( L O C A L P A T H ) / B e t a 1 C A M 5321 6 V 2 5 1 80903. B i n : (LOCAL_PATH)/Beta1_CAM53216_V25_180903.Bin: (LOCALPATH)/Beta1CAM53216V25180903.Bin:(PRODUCT_OUT)/emmc_firmware_upgrade.bin
+endif
+#[BSP] add end

3.ota升级进程update-binary解析ota包 获取emmc固件,如果能成功获取则调用升级EMMC固件函数DoEmmc50FFU
AOSP/bootable/recovery/upadter/updater.cpp:
updater.cpp main函数内添加升级流程:
main {

//…

{
std::string emmc_firmware = “/tmp/emmc_firmware”;
std::string boot_device = “/dev/block/mmcblk0”;
if (!EmmcFirmwareLoadFile(za, EMMC_FIRMWARE_NAME, emmc_firmware, 0666)){//从ota包获取emmc固件,如果获取到才开始升级emmc 固件流程,获取不到不进行升级 继续执行正常升级IMAGE流程
int ret = DoEmmc50FFU(emmc_firmware, boot_device, FFUExecute);

    if (ret != 0 ) {
        fprintf(cmd_pipe, "ui_print %s\n", "emmc firmware upgrade fail.");
    } else {
        fprintf(cmd_pipe, "ui_print %s\n", "emmc firmware upgrade success.");
    }
}

}

//…
}
(完 —— 完整方案见附件ota update emmc firmware.rar

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值