cc3200系列教程之制作bootloader简介

来源:互联网 发布:淘宝不允许好评返现 编辑:程序博客网 时间:2024/05/22 06:53

什么是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的大小,

image

怎么生成这个文件,需要把这句话

"${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"加在下面的位置。

image

这句话其实就是调用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文件。

截图:

image

 

特别点:::::::::还需要特别一点的地方:修改下面这个静态库,如果没修改的话,会导致你的bootloader的文件大小大于0x4000,

大于这个数,会产生很大的麻烦


 

BootLoaderManage代码:

[java] view plain copy
 print?
  1. int main() {  
  2.     //  
  3.     // Initialize Board configurations  
  4.     //  
  5.     BoardInit();  
  6.        MAP_PRCMPeripheralClkEnable(PRCM_UARTA0, PRCM_RUN_MODE_CLK);  
  7.   
  8.         //  
  9.         // Configure PIN_55 for UART0 UART0_TX  
  10.         //  
  11.         MAP_PinTypeUART(PIN_55, PIN_MODE_3);  
  12.   
  13.         //  
  14.         // Configure PIN_57 for UART0 UART0_RX  
  15.         //  
  16.         MAP_PinTypeUART(PIN_57, PIN_MODE_3);  
  17.   
  18.     MAP_PRCMPeripheralReset(PRCM_UARTA0);  
  19.   
  20.     MAP_UARTConfigSetExpClk(CONSOLE, MAP_PRCMPeripheralClockGet(CONSOLE_PERIPH),  
  21.     UART_BAUD_RATE, (UART_CONFIG_WLEN_8 |  
  22.     UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));  
  23.     MAP_UARTCharPut(CONSOLE,'b');  
  24.     MAP_UARTCharPut(CONSOLE,'o');  
  25.     MAP_UARTCharPut(CONSOLE,'o');  
  26.     MAP_UARTCharPut(CONSOLE,'t');  
  27.     MAP_UARTCharPut(CONSOLE,'l');  
  28.     MAP_UARTCharPut(CONSOLE,'o');  
  29.     MAP_UARTCharPut(CONSOLE,'a');  
  30.     MAP_UARTCharPut(CONSOLE,'d');  
  31.     MAP_UARTCharPut(CONSOLE,'e');  
  32.     delay();  
  33.     MAP_UARTCharPut(CONSOLE,'r');  
  34.     delay();  
  35.     delay();  
  36.     delay();  
  37.     delay();  
  38.     RunMagic("/sys/mcuimg2.bin");  
  39.     while(1){  
  40.   
  41.         delay();  
  42.         MAP_UARTCharPut(CONSOLE,'r');  
  43.         delay();  
  44.     }  
  45.     return 0;  
  46. }  
[java] view plain copy
 print?
  1. /* 
  2.  * MyBootLoader.c 
  3.  * 
  4.  *  Created on: 2015年8月20日 
  5.  *      Author: Administrator 
  6.  */  
  7. #include "MyBootLoader.h"  
  8. #ifndef ccs  
  9. void Run(unsigned long ulBaseLoc)  
  10. {  
  11.   
  12.     //  
  13.     // Set the SP  
  14.     //  
  15.     __asm(" ldr    sp,[r0]\n"  
  16.             "   add    r0,r0,#4");  
  17.   
  18.     //  
  19.     // Jump to entry code  
  20.     //  
  21.     __asm(" ldr    r1,[r0]\n"  
  22.             "   bx     r1");  
  23. }  
  24. #else  
  25. __asm("    .sect \".text:Run\"\n"  
  26.         "    .clink\n"  
  27.         "    .thumbfunc Run\n"  
  28.         "    .thumb\n"  
  29.         "Run:\n"  
  30.         "    ldr    sp,[r0]\n"  
  31.         "    add    r0,r0,#4\n"  
  32.         "    ldr    r1,[r0]\n"  
  33.         "    bx     r1");  
  34. #endif  
  35. extern void delay();  
  36. void RunMagic(char *fileName) {  
  37.   
  38.     int retVal;  
  39.     unsigned long token, fileHandle;  
  40.     SlFsFileInfo_t fsFileInfo;  
  41.   
  42.     token = 0;  
  43.     sl_Start(NULL, NULL, NULL);  
  44.     delay();  
  45.     retVal = sl_FsOpen(fileName, FS_MODE_OPEN_READ, &token, &fileHandle);  
  46.     delay();  
  47.     if (0 == retVal) {  
  48.         //  
  49.         // Get the file size using File Info structure  
  50.         //  
  51.         delay();  
  52.         retVal = sl_FsGetInfo(fileName, token, &fsFileInfo);  
  53.   
  54.         //  
  55.         // Check for failure  
  56.         //  
  57.         if (0 == retVal) {  
  58.   
  59.             //  
  60.             // Read the application into SRAM  
  61.             //  
  62.             delay();  
  63.             retVal = sl_FsRead(fileHandle, 0,  
  64.                     (unsigned char *) APP_IMG_SRAM_OFFSET, fsFileInfo.FileLen);  
  65.   
  66.             //  
  67.             // Stop the network services  
  68.             //  
  69.             delay();  
  70.             sl_Stop(30);  
  71.   
  72.             delay();  
  73.             //  
  74.             // Execute the application.  
  75.             //  
  76.             Run(APP_IMG_SRAM_OFFSET);  
  77.         }  
  78.     }  
  79. }  


[java] view plain copy
 print?
  1. /* 
  2.  * MyBootLoader.h 
  3.  * 
  4.  *  Created on: 2015年8月20日 
  5.  *      Author: Administrator 
  6.  */  
  7.   
  8. #ifndef MYBOOTLOADER_H_  
  9. #define MYBOOTLOADER_H_  
  10. #include "simplelink.h"  
  11. #include "fs.h"  
  12. #define APP_IMG_SRAM_OFFSET     0x20004000  
  13. void RunMagic(char *fileName);  
  14.   
  15. #endif /* MYBOOTLOADER_H_ */  
原创粉丝点击