cc3200系列教程之制作bootloader简介
什么是bootloader?有什么用处?当我们在flash下载两个app时,如何从一个app转到另一个app?这个要怎么去做到?这时候就需要bootloader
。bootloader就是在cc3200启动的时候有选择性地启动我们的app,因为app是会更新的,譬如我们可以通过服务器下载一个新的app到cc3200上,这时候就起到了一个无线更新app的效果,无线更新app的功能叫做OTA,其底层就需要bootloader的支持。这里我们不讲OTA,仅仅就讲bootloader。
软件思路:通过bootloader我们启动另一个app,因此本例程需要两个bin文件,但是ccs需要三个工程,出于方便,我就先介绍思路,这里app我就采用uart_demo,
sram的空间分部是从0x2000 0000开始的,结束,我就不太清楚了,以前有看过,但是想不起来了。
cc3200是有内置bootloader,当上电的时候,会把内置bootloader拷贝到0x2000 0000 – 0x2000 4000内,所以一般我们的app的地址是在0x2000 4000,这个地址怎么知道了?ccs是需要看cc3200v1p32.cmd这个文件,这个文件里有
#define RAM_BASE 0x20004000
/* System memory map */
MEMORY
{
/* Application uses internal RAM for program and data */
SRAM_CODE (RWX) : origin = 0x20004000, length = 0x13000
SRAM_DATA (RWX) : origin = 0x20017000, length = 0x19000
}
很明显啊,这个工程的内存地址是从0x2000 4000的开始的,如果你修改了这个值,就会导致你的app跑不起来。
bootloader需要3个bin文件构成,
第一个bin文件叫relocator,这个bin文件是sdk就提供的,这里我不想改这个文件,理由么?太简单了
第二个bin文件叫BootLoaderManage,这个是我在blink的基础上修改的
第三个bin文件叫bootloader。这三者有什么关系?
relocator的空间位置是位于0x2000 4000
BootLoaderManage的空间位置是位于0x2000 0000
bootloader是上面两者的结合体,等于relocator + BootLoaderManage,relocator 是在前面的。BootLoaderManage在后面。
relocator 占据了0x100大小,
这里我截图,其中relocator 不足0x100大小,但是如果你把它看成了0x100大小,然后再跟BootLoaderManage的大小相加,最后就会发现大小是等于bootloader的大小,
怎么生成这个文件,需要把这句话
"${CC3200_SDK_ROOT}/example/application_bootloader/ccs/bootgen.exe" "${CC3200_SDK_ROOT}/example/application_bootloader/relocator/ewarm/Release/Exe/relocator.bin" "${BuildArtifactFileBaseName}.bin" "bootloader.bin"加在下面的位置。
这句话其实就是调用bootgen.exe这个工具把两个bin文件合成一个bin文件,具体是怎么合成的,我也不太清楚。
cc3200上电流程:跑内置的bootloader,内置的bootloader把我们的bootloader拷贝到0x2000 4000处,这时候会运行relocator这个bin文件,这个bin文件的功能就是把BootLoaderManage拷贝到0x2000 0000 处(单纯的拷贝功能,所以文件很小),接着跳到0x2000 0000处执行BootLoaderManage这个bin文件,接着我们在BootLoaderManage这个bin文件读取flash的文件,并把flash的文件拷贝到0x2000 4000 处,接着执行0x2000 4000 的app文件。
截图:
特别点:::::::::还需要特别一点的地方:修改下面这个静态库,如果没修改的话,会导致你的bootloader的文件大小大于0x4000,
大于这个数,会产生很大的麻烦
BootLoaderManage代码:
- int main() {
- //
- // Initialize Board configurations
- //
- BoardInit();
- MAP_PRCMPeripheralClkEnable(PRCM_UARTA0, PRCM_RUN_MODE_CLK);
- //
- // Configure PIN_55 for UART0 UART0_TX
- //
- MAP_PinTypeUART(PIN_55, PIN_MODE_3);
- //
- // Configure PIN_57 for UART0 UART0_RX
- //
- MAP_PinTypeUART(PIN_57, PIN_MODE_3);
- MAP_PRCMPeripheralReset(PRCM_UARTA0);
- MAP_UARTConfigSetExpClk(CONSOLE, MAP_PRCMPeripheralClockGet(CONSOLE_PERIPH),
- UART_BAUD_RATE, (UART_CONFIG_WLEN_8 |
- UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
- MAP_UARTCharPut(CONSOLE,'b');
- MAP_UARTCharPut(CONSOLE,'o');
- MAP_UARTCharPut(CONSOLE,'o');
- MAP_UARTCharPut(CONSOLE,'t');
- MAP_UARTCharPut(CONSOLE,'l');
- MAP_UARTCharPut(CONSOLE,'o');
- MAP_UARTCharPut(CONSOLE,'a');
- MAP_UARTCharPut(CONSOLE,'d');
- MAP_UARTCharPut(CONSOLE,'e');
- delay();
- MAP_UARTCharPut(CONSOLE,'r');
- delay();
- delay();
- delay();
- delay();
- RunMagic("/sys/mcuimg2.bin");
- while(1){
- delay();
- MAP_UARTCharPut(CONSOLE,'r');
- delay();
- }
- return 0;
- }
- /*
- * MyBootLoader.c
- *
- * Created on: 2015年8月20日
- * Author: Administrator
- */
- #include "MyBootLoader.h"
- #ifndef ccs
- void Run(unsigned long ulBaseLoc)
- {
- //
- // Set the SP
- //
- __asm(" ldr sp,[r0]\n"
- " add r0,r0,#4");
- //
- // Jump to entry code
- //
- __asm(" ldr r1,[r0]\n"
- " bx r1");
- }
- #else
- __asm(" .sect \".text:Run\"\n"
- " .clink\n"
- " .thumbfunc Run\n"
- " .thumb\n"
- "Run:\n"
- " ldr sp,[r0]\n"
- " add r0,r0,#4\n"
- " ldr r1,[r0]\n"
- " bx r1");
- #endif
- extern void delay();
- void RunMagic(char *fileName) {
- int retVal;
- unsigned long token, fileHandle;
- SlFsFileInfo_t fsFileInfo;
- token = 0;
- sl_Start(NULL, NULL, NULL);
- delay();
- retVal = sl_FsOpen(fileName, FS_MODE_OPEN_READ, &token, &fileHandle);
- delay();
- if (0 == retVal) {
- //
- // Get the file size using File Info structure
- //
- delay();
- retVal = sl_FsGetInfo(fileName, token, &fsFileInfo);
- //
- // Check for failure
- //
- if (0 == retVal) {
- //
- // Read the application into SRAM
- //
- delay();
- retVal = sl_FsRead(fileHandle, 0,
- (unsigned char *) APP_IMG_SRAM_OFFSET, fsFileInfo.FileLen);
- //
- // Stop the network services
- //
- delay();
- sl_Stop(30);
- delay();
- //
- // Execute the application.
- //
- Run(APP_IMG_SRAM_OFFSET);
- }
- }
- }
- /*
- * MyBootLoader.h
- *
- * Created on: 2015年8月20日
- * Author: Administrator
- */
- #ifndef MYBOOTLOADER_H_
- #define MYBOOTLOADER_H_
- #include "simplelink.h"
- #include "fs.h"
- #define APP_IMG_SRAM_OFFSET 0x20004000
- void RunMagic(char *fileName);
- #endif /* MYBOOTLOADER_H_ */