现在我遇到一个问题,是这样的,我听过下载器下载到我的板子里面,从BootLoader跳到APP程序是正常的,我通过在线升级去更新就跳转不正常了,我查看了传到FLASH的数据是正确的;但是我更新的bin文件比较小的话又是可以正常跳到APP程序的,下面是我BootLoader程序的代码
uint32_t WaitingTime = JUMP_WAITING_TIME_LONG; //5min
uint8_t g_ui8IsWrqReceived = 0;
uint8_t g_ui8IsDownloadDone = 0;
uint32_t jump_config;
uint32_t g_ui32TransferAddress = FLASH_APP_ADDR;
uint32_t g_ui32DownloadBuffAddr = FLASH_BACKUP_ADDR;
uint32_t g_ui32WritingPosition = 0;
uint8_t g_ui8DownloadError = 0;
uint32_t g_ui32DownloadedSize = 0x78000;
uint8_t g_ui8FlashError = 0;
TFTP_ERROR_LIST g_error;
FW_UPGRADER_T g_upgrader;
int main(void)
{ uint32_t updateconfig = 0;
//uint32_t updateconfig1 = 0;
init_readConfig();
//ROM_SysCtlReset();
//判断是否有更新标志,如果有更新标志,将备份区程序拷贝到APP区;
//拷贝完成后清除更新标志,擦除备份区程序,重启;
//无更新标志,直接跳转到APP区执行应用程序;
EEPROMRead((uint32_t*)&updateconfig, EEPROM_ADDR_BL_UPDATE_CONFIG, 4);
if (!updateconfig)
{
iap_load_app(FLASH_APP_ADDR);//执行FLASH APP代码
} else
{
upgrader_init(&g_upgrader);
while (1)
{
upgrader_process();
}
}
}
//跳转到应用程序段
//appxaddr:用户代码起始地址.
void iap_load_app(uint32_t appxaddr)
{
//用户代码区第二个字为程序开始地址(复位地址)
g_jump2appfun = (iapfun_t)HWREG(appxaddr + 4);
// 初始化APP堆栈指针(用户代码区的第一个字用于存放栈顶地址)
// 将向量表设置为应用程序开头的Flash。
HWREG(0xE000ED08) = appxaddr;
// Load the stack pointer from the application's vector table.
// 从应用程序的向量表中加载堆栈指针。
__asm(" ldr r1, [r0]\n"
" mov sp, r1\n");
// Load the initial PC from the application's vector table and branch to
// the application's entry point.
// 从应用程序的向量表中加载初始PC并跳转至
// 应用程序的入口点。
__asm(" ldr r0, [r0, #4]\n"
" bx r0\n");
//跳转到APP执行
g_jump2appfun();
}
void upgrader_init(FW_UPGRADER_T *upgrader)
{
WaitingTime == JUMP_WAITING_TIME_LONG;
upgrader->status = UPGRADER_IDLE;
}
void upgrader_process()
{
uint32_t i = 0;
switch (g_upgrader.status) {
case UPGRADER_IDLE:
g_upgrader.status = REQUESTED;
break;
case UPGRADER_TIMEOUT:
// timeout so we go directly to jump.
g_upgrader.status = READY_TO_JUMP;
puts("Upgrader_timeout");
break;
case REQUESTED:
g_upgrader.status = DOWNLOADED;
break;
case DOWNLOADED:
// download completed.
// todo: integrity verification required here.
// start copying from download buf to main_app_buf
// init g_ui32WritingPosition to main_app_buf firstly and then go to next state.
g_ui32TransferAddress = FLASH_APP_ADDR;
g_ui32WritingPosition = g_ui32TransferAddress;
uint32_t g_ui32DownloadBuffAddr = FLASH_BACKUP_ADDR;
g_upgrader.status = FLASH_COPPYING;
break;
case FLASH_COPPYING:
// store the status into eeprom
// erase the main_app_buf
//TODO: calculate the size!
//while (g_ui32TransferAddress < (uint32_t)APP_FLASH_LAST_PAGE_ADDRESS)
//{
// if (FlashErase(g_ui32TransferAddress) == 0)
// {
// g_ui32TransferAddress += FLASH_PAGE_SIZE;
// }
// else
// {
// // report the error.
// g_ui8FlashError = 1;
// g_upgrader.status = UPGRADER_ERROR;
// g_error = FLASHERASE_FAILED;
// }
//}
for (i = 0; i < 480; i++) {
if (FlashErase(g_ui32TransferAddress + i * 1024) != 0) {
// report the error.
g_ui8FlashError = 1;
g_upgrader.status = UPGRADER_ERROR;
g_error = FLASHERASE_FAILED;
}
}
SysCtlDelay(10000);
for (i = 0; (i < g_ui32DownloadedSize);)
{
if (FlashProgram((uint32_t*)g_ui32DownloadBuffAddr, g_ui32WritingPosition, 4) == 0)
{
/* Check the written value */
if (*(uint32_t*)g_ui32WritingPosition != *(uint32_t*)g_ui32DownloadBuffAddr)
{
/* Flash content doesn't match SRAM content */
g_ui8FlashError = 1;
g_upgrader.status = UPGRADER_ERROR;
g_error = FLASHCOPY_FAILED;
break;
}
/* Increment FLASH destination address */
//FlashAddress++;
uint32_t aaaa = *(uint32_t*)g_ui32WritingPosition;
g_ui32WritingPosition += 4;
g_ui32DownloadBuffAddr += 4;
i += 4;
}
}
for (i = 0; i < 512; i++) {
if (FlashErase(FLASH_BACKUP_ADDR + i * 1024) != 0) {
// report the error.
g_ui8FlashError = 1;
g_upgrader.status = UPGRADER_ERROR;
g_error = FLASHERASE_FAILED;
}
}
g_upgrader.status = FLASH_COPPIED;
break;
case FLASH_COPPIED:
//todo check the integrity of coppied image.
// now it's ready to jump.
g_upgrader.status = READY_TO_JUMP;
//config the waiting to be "no_wait"
jump_config = 0;
EEPROMProgram((uint32_t*)&jump_config, EEPROM_ADDR_BL_UPDATE_CONFIG, 4);
//puts("Jumping");
break;
case READY_TO_JUMP:
//reset and disable the peripherals used by the boot loader.
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOG);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOH);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOJ);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOK);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOL);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOM);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPION);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOP);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOQ);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOR);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOS);
SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOT);
SysCtlPeripheralDisable(SYSCTL_PERIPH_EEPROM0);
SysCtlPeripheralDisable(SYSCTL_PERIPH_EMAC0);
SysCtlPeripheralDisable(SYSCTL_PERIPH_EPHY0);
SysCtlPeripheralDisable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralDisable(SYSCTL_PERIPH_UART1);
SysCtlPeripheralDisable(SYSCTL_PERIPH_ADC1);
SysCtlPeripheralDisable(SYSCTL_PERIPH_PWM0);
SysCtlPeripheralDisable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralDisable(SYSCTL_PERIPH_TIMER1);
SysCtlPeripheralDisable(SYSCTL_PERIPH_TIMER2);
SysTickIntDisable();
IntMasterDisable();
resetInit();
resetLaunch();
SysCtlReset();
break;
case UPGRADER_ERROR:
default:
// we handle here both UPGRADER_ERROR and not-defined state as error.
// stop the upgrade and take actions accordingly.
// simply reset the MCU here to retry.
//puts(g_error);
break;
}
}
Susan Yang:
user6310669我通过在线升级去更新就跳转不正常了
我对这一句有些疑惑。能否请您详细解释下?
另外若是可以的话,请私信一下工程,我用开发板测试一下,谢谢
user6310669:
回复 Susan Yang:
不好意思,字错了,现在我遇到一个问题,是这样的,我听过下载器下载到我的板子里面,从BootLoader跳到APP程序是正常的,我通过在线升级去更新就不正常了,在线升级是这样的,先把bin文件的数据传送到flash起始地址为0x00080000中,大小为480K,然后断电重启,BootLoader将flash中0x00080000~0x000f7fff中的数据传送到flash中0x00008000~0x0007ffff中,复制完成后,就跳转不到APP程序中了,我查看了传到FLASH的数据是正确的;但是我更新的bin文件比较小的话又是可以正常跳到APP程序的,下面是我BootLoader程序的代码
Susan Yang:
回复 user6310669:
应该和下面的问题有关系,您可以看一下
www.ti.com/…/spmu301e.pdf