author | Sam Wu <yihui.wu@amlogic.com> | 2017-11-13 02:44:39 (GMT) |
---|---|---|
committer | Sam Wu <yihui.wu@amlogic.com> | 2017-11-14 06:15:26 (GMT) |
commit | 764e116d0962b236841b501dd0287b4dbcaf2dc9 (patch) | |
tree | 80c6e9c72ccaf36e298ae245cb131c8c4152fb62 | |
parent | 98a2485d4cc864b6f156f04939d6652b519a2c71 (diff) | |
download | uboot-ref-o-20171115.zip uboot-ref-o-20171115.tar.gz uboot-ref-o-20171115.tar.bz2 |
FactoryBurn: mtd flashing bugs fix
PD# 154368
1, fix err return value when verify TPL;
2, fix mtd bootloader write/read size not the same.
3, mtd: fix 'imgread pic' offset not aligh nand page 2k.
4, mtd: fix erasing data before dump data.
Change-Id: I47737416a314d566c3a13cedb703f103d12085a3
-rw-r--r-- | common/cmd_burnup.c | 2 | ||||
-rw-r--r-- | common/cmd_imgread.c | 7 | ||||
-rw-r--r-- | common/store_interface.c | 38 | ||||
-rw-r--r-- | drivers/usb/gadget/v2_burning/v2_common/optimus_download.c | 18 |
4 files changed, 37 insertions, 28 deletions
diff --git a/common/cmd_burnup.c b/common/cmd_burnup.c index 49596ff..4c1308a 100644 --- a/common/cmd_burnup.c +++ b/common/cmd_burnup.c @@ -13,7 +13,7 @@ #define ErrP(fmt...) printf("[burnup]Err:%s,L%d:", __func__, __LINE__),printf(fmt) static unsigned char *cmd_name = (unsigned char *)("store"); -extern const char* _usbDownPartImgType; +const char* _usbDownPartImgType = ""; #define MtdAlignBits (12) //32k #define MtdAlignSz (1U << MtdAlignBits) diff --git a/common/cmd_imgread.c b/common/cmd_imgread.c index d31545f..e7fd88a 100644 --- a/common/cmd_imgread.c +++ b/common/cmd_imgread.c @@ -487,9 +487,10 @@ static int do_image_read_pic(cmd_tbl_t *cmdtp, int flag, int argc, char * const if (pItem->start + itemSz > flashReadOff) { - //emmc read can't support offset not align 512 - rc = store_read_ops((unsigned char*)partName, (unsigned char *)((picLoadAddr>>9)<<9), - ((pItem->start>>9)<<9), itemSz + (picLoadAddr & 0x1ff)); + unsigned long rdOff = pItem->start; + unsigned long rdOffAlign = (rdOff >> 11) << 11;//align 2k page for mtd nand, 512 for emmc + rc = store_read_ops((unsigned char*)partName, (unsigned char *)((picLoadAddr>>11)<<11), + rdOffAlign, itemSz + (rdOff & 0x7ff) ); if (rc) { errorP("Fail to read pic at offset 0x%x\n", pItem->start); return __LINE__; diff --git a/common/store_interface.c b/common/store_interface.c index a01023b..11b0d7c 100644 --- a/common/store_interface.c +++ b/common/store_interface.c @@ -89,7 +89,7 @@ static int mtd_find_phy_off_by_lgc_off(const char* partName, const loff_t logicA mtdPartInf = get_mtd_device_nm(partName); if (IS_ERR(mtdPartInf)) { ErrP("device(%s) is err\n", partName); - return -__LINE__; + return CMD_RET_FAILURE; } const unsigned eraseSz = mtdPartInf->erasesize; const unsigned offsetInBlk = logicAddr & (eraseSz - 1); @@ -730,7 +730,7 @@ static int do_store_size(cmd_tbl_t * cmdtp, int flag, int argc, char * const arg mtdPartInf = get_mtd_device_nm(partName); if (IS_ERR(mtdPartInf)) { ErrP("device(%s) is err\n", partName); - return -__LINE__; + return CMD_RET_FAILURE; } const unsigned eraseSz = mtdPartInf->erasesize; const uint64_t partSzPhy = mtdPartInf->size; @@ -1215,14 +1215,14 @@ static int do_store_rom_write(cmd_tbl_t * cmdtp, int flag, int argc, char * cons if ( bootloaderMaxSz < size ) { ErrP("bootloader sz 0x%llx too large,max sz 0x%x\n", size, bootloaderMaxSz ); - return -__LINE__; + return CMD_RET_FAILURE; } if ( !updateTpl ) { MsgP("Warnning:tplWriteSz 0x%x too small, update bl2 only but not update tpl\n", tplWriteSz); } if (iCopy2Update >= tplCpyNum || iCopy2Update >= Bl2CpyNum) { ErrP("iCopy2Update[%s] invalid, must < min(%d, %d)\n", argv[5], tplCpyNum, Bl2CpyNum); - return -__LINE__; + return CMD_RET_FAILURE; } for (i = 0; i < Bl2CpyNum; ++i) { @@ -1232,7 +1232,7 @@ static int do_store_rom_write(cmd_tbl_t * cmdtp, int flag, int argc, char * cons ret = run_command(str, 0); if (ret) { ErrP("Failed at erase bl2[%d],ret=%d\n", i, ret); - return -__LINE__; + return CMD_RET_FAILURE; } //copyOff = i * Bl2Size; @@ -1241,7 +1241,7 @@ static int do_store_rom_write(cmd_tbl_t * cmdtp, int flag, int argc, char * cons ret = run_command(str, 0); if (ret) { ErrP("Failed at pgram bl2[%d],ret=%d\n", i, ret); - return -__LINE__; + return CMD_RET_FAILURE; } } addr += Bl2Size; @@ -1253,7 +1253,7 @@ static int do_store_rom_write(cmd_tbl_t * cmdtp, int flag, int argc, char * cons ret = run_command(str, 0); if (ret) { ErrP("Failed at erase tpl[%d],ret=%d\n", i, ret); - return -__LINE__; + return CMD_RET_FAILURE; } copyOff = i * tplCapSize; @@ -1262,7 +1262,7 @@ static int do_store_rom_write(cmd_tbl_t * cmdtp, int flag, int argc, char * cons ret = run_command(str, 0); if (ret) { ErrP("Failed at pgram bl2[%d],ret=%d\n", i, ret); - return -__LINE__; + return CMD_RET_FAILURE; } } #if CONFIG_TPL_VAL_NUM_MIN @@ -1413,17 +1413,17 @@ static int do_store_rom_read(cmd_tbl_t * cmdtp, int flag, int argc, char * const if ( bootloaderMaxSz < size || tplRealSz < 0 ) { ErrP("bootloader sz 0x%llx invalid, max sz %d\n", size, bootloaderMaxSz ); - return -__LINE__; + return CMD_RET_FAILURE; } if (iCopy2Update >= tplCpyNum || iCopy2Update >= Bl2CpyNum) { ErrP("iCopy2Update[%s] invalid, must < min(%d, %d)\n", argv[5], tplCpyNum, Bl2CpyNum); - return -__LINE__; + return CMD_RET_FAILURE; } tmpBuf = (char*)malloc(size); if ( !tmpBuf ) { ErrP("Failed maloc 0x%llx bytes\n", size); - return -__LINE__; + return CMD_RET_FAILURE; } memset(tmpBuf, 0, size); @@ -1438,7 +1438,7 @@ static int do_store_rom_read(cmd_tbl_t * cmdtp, int flag, int argc, char * const ret = run_command(str, 0); if (ret) { ErrP("Failed at pgram bl2[%d],ret=%d\n", i, ret); - return -__LINE__; + return CMD_RET_FAILURE; } #if CONFIG_BL2_VAL_NUM_MIN if (verifyMode) //copy index not specified, need read all copies @@ -1456,7 +1456,7 @@ static int do_store_rom_read(cmd_tbl_t * cmdtp, int flag, int argc, char * const #if CONFIG_BL2_VAL_NUM_MIN if (okCrcNum < CONFIG_BL2_VAL_NUM_MIN && verifyMode) { ErrP("okCrcNum(%d) < CONFIG_BL2_VAL_NUM_MIN(%d)\n", okCrcNum, CONFIG_BL2_VAL_NUM_MIN); - return -__LINE__; + return CMD_RET_FAILURE; } okCrcNum = 0; #endif//#if CONFIG_BL2_VAL_NUM_MIN @@ -1475,7 +1475,7 @@ static int do_store_rom_read(cmd_tbl_t * cmdtp, int flag, int argc, char * const ret = run_command(str, 0); if (ret) { ErrP("Failed at pgram bl2[%d],ret=%d\n", i, ret); - return -__LINE__; + return CMD_RET_FAILURE; } #if CONFIG_TPL_VAL_NUM_MIN if (verifyMode) //copy index not specified, need read all copies @@ -1493,7 +1493,7 @@ static int do_store_rom_read(cmd_tbl_t * cmdtp, int flag, int argc, char * const #if CONFIG_TPL_VAL_NUM_MIN if (okCrcNum < CONFIG_TPL_VAL_NUM_MIN && verifyMode) { ErrP("okCrcNum(%d) < CONFIG_TPL_VAL_NUM_MIN(%d)\n", okCrcNum, CONFIG_TPL_VAL_NUM_MIN); - return -__LINE__; + return CMD_RET_FAILURE; } #endif//#if CONFIG_TPL_VAL_NUM_MIN memcpy((char*)addr + Bl2Size, (unsigned char*)readBuf, tplRealSz); @@ -1617,7 +1617,7 @@ static int do_store_read(cmd_tbl_t * cmdtp, int flag, int argc, char * const arg if (iCopy2Update >= tplCpyNum) { ErrP("iCopy2Update[%s] invalid, must < max(%d)\n", argv[6], tplCpyNum); - return -__LINE__; + return CMD_RET_FAILURE; } loff_t copyOff = iCopy2Update * tplCapSize; @@ -1715,7 +1715,7 @@ static int do_store_write(cmd_tbl_t * cmdtp, int flag, int argc, char * const ar debugP("iCopy2Update=%d, tplCpyNum=%d\n", iCopy2Update, tplCpyNum); if (iCopy2Update >= tplCpyNum) { ErrP("iCopy2Update[%s] invalid, must < max(%d)\n", argv[6], tplCpyNum); - return -__LINE__; + return CMD_RET_FAILURE; } for ( i = 0; i < tplCpyNum; ++i ) @@ -1726,7 +1726,7 @@ static int do_store_write(cmd_tbl_t * cmdtp, int flag, int argc, char * const ar ret = run_command(str, 0); if (ret) { ErrP("Failed at erase tpl[%d],ret=%d\n", i, ret); - return -__LINE__; + return CMD_RET_FAILURE; } loff_t copyOff = i * tplCapSize; @@ -1735,7 +1735,7 @@ static int do_store_write(cmd_tbl_t * cmdtp, int flag, int argc, char * const ar ret = run_command(str, 0); if (ret) { ErrP("Failed at pgram bl2[%d],ret=%d\n", i, ret); - return -__LINE__; + return CMD_RET_FAILURE; } } } else diff --git a/drivers/usb/gadget/v2_burning/v2_common/optimus_download.c b/drivers/usb/gadget/v2_burning/v2_common/optimus_download.c index b384772..46300d2 100644 --- a/drivers/usb/gadget/v2_burning/v2_common/optimus_download.c +++ b/drivers/usb/gadget/v2_burning/v2_common/optimus_download.c @@ -80,7 +80,8 @@ struct ImgBurnInfo{ u8 verifyAlgorithm;//0--sha1sum, 1--crc32, 2--addsum u8 imgBurnSta;// u8 storageMediaType;//NAND default, - u8 resrv4Align[4]; + u8 isDumpMode; //if dump mode + u8 resrv4Align[3]; u64 nextMediaOffset;//image size already received u64 imgPktSz;//total size of the file image @@ -94,7 +95,7 @@ struct ImgBurnInfo{ }; static struct ImgBurnInfo OptimusImgBurnInfo = {0}; -const char* _usbDownPartImgType = ""; +extern const char* _usbDownPartImgType ; struct imgBurnInfo_sparse{ @@ -177,7 +178,7 @@ static int optimus_verify_dtb(struct ImgBurnInfo* pDownInfo, u8* genSum) } //32k, Now nand not need align any more, but I remember spi nor flash need 32k aligh -#define BOOTLOADER_ALIGN_BITS 15 +#define BOOTLOADER_ALIGN_BITS 0//15 //return value is the actual size it write static int optimus_download_bootloader_image(struct ImgBurnInfo* pDownInfo, u32 dataSzReceived, const u8* data) @@ -195,9 +196,11 @@ static int optimus_download_bootloader_image(struct ImgBurnInfo* pDownInfo, u32 return 0; } +#if BOOTLOADER_ALIGN_BITS size += (1U<<BOOTLOADER_ALIGN_BITS) -1; size >>= BOOTLOADER_ALIGN_BITS; size <<= BOOTLOADER_ALIGN_BITS; +#endif// #if BOOTLOADER_ALIGN_BITS ret = store_boot_write((unsigned char*)data, 0, size); if (dataSzReceived != size)DWN_MSG("align bootloader sz from 0x%x to 0x%llx\n", dataSzReceived, size) ; @@ -216,8 +219,12 @@ static int optimus_verify_bootloader(struct ImgBurnInfo* pDownInfo, u8* genSum) off = (1ULL << 62) - 1; //verify mode for verify discrete bootloader #endif//#if defined(CONFIG_AML_MTD) - /*size = 0x60000;////////////TODO:hardcode len!!*/ size=pDownInfo->imgPktSz; +#if BOOTLOADER_ALIGN_BITS + size += (1U<<BOOTLOADER_ALIGN_BITS) -1; + size >>= BOOTLOADER_ALIGN_BITS; + size <<= BOOTLOADER_ALIGN_BITS; +#endif// #if BOOTLOADER_ALIGN_BITS ret = store_boot_read(pBuf, off, size); if (ret) { DWN_ERR("Fail to read bootloader\n"); @@ -308,7 +315,7 @@ static int optimus_storage_open(struct ImgBurnInfo* pDownInfo, const u8* data, c #if defined(CONFIG_DISCRETE_BOOTLOADER) if ( strcmp(CONFIG_TPL_PART_NAME, partName) ) #endif//#if defined(CONFIG_DISCRETE_BOOTLOADER) - if (!(is_optimus_storage_inited()>>16) && strcmp("bootloader", partName)) { + if (!pDownInfo->isDumpMode && !(is_optimus_storage_inited()>>16) && strcmp("bootloader", partName)) { char cmd[96]; sprintf(cmd, "store erase partition %s", partName); DWN_MSG("cmd[%s]\n", cmd); @@ -1148,6 +1155,7 @@ u32 optimus_dump_storage_data(u8* pBuf, const u32 wantSz, char* errInfo) DWN_DBG("pBuf=0x%p, wantSz=0x%x, nextMediaOffset=%x\n", pBuf, wantSz, (u32)nextMediaOffset); + pDownInfo->isDumpMode = 1; //do not do any erase in dump mode ret = optimus_storage_open(pDownInfo, pBuf, wantSz); if (OPT_DOWN_OK != ret) { sprintf(errInfo, "Fail to open stoarge\n"); |