This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Secondary bootloader using ROM file-system functions

Guru 80505 points


Hi All,

I am working on small and fast secondary bootloader. From this reason I decided to use file system functions located in ROM (fs_Open(), fs_GetFileInfo(), fs_Read()) instead standard file systems functions from SimpleLink NWP. This approach allows save some boot time because it it not required started NWP. Also bootloader is smaller because is not necessary link SimpleLink driver library. My idea is based on fast boot mode from "application_bootloader" in SDK 1.2.0 and file filesystem.h in this example.

Unfortunately calling file system functions from ROM not work properly. I am not able find reason of the issue. Calling of fs_Open() function always return -11 (=file not found). My file "/sys/mcuimg1.bin" is properly saved in flash filesystem and with sl_FsOpen() works properly. From my point of view it looks like that filename was not properly pass into ROM function call. Unfortunately I don't know how this fix. Any advice will be highly appreciated.

Actually same issue was discussed at this thread (https://e2e.ti.com/support/wireless_connectivity/simplelink_wifi_cc31xx_cc32xx/f/968/p/498670/1807110). There is verified answer, unfortunately it not answers what is root case of problem.

My minimal code of bootloader for CCS is here:

#include "hw_ints.h"
#include "hw_types.h"
#include "fs.h"
#include "hw_memmap.h"
#include "rom.h"
#include "rom_map.h"
#include "prcm.h"
#include "interrupt.h"

#include "filesystem.h"


// vector table
#if defined(ccs) || defined(gcc)
extern void (* const g_pfnVectors[])(void);
#endif

// application entry point
#define APP_OFFSET     0x20020000
// application image file name
static unsigned char   file[] = "/sys/mcuimg1.bin";

//
// Run firmware image from RAM address
//
void runFirmwareImage(unsigned long);

__asm("    .sect \".text:runFirmwareImage\"\n"
      "    .clink\n"
      "    .thumbfunc runFirmwareImage\n"
      "    .thumb\n"
      "runFirmwareImage:\n"
      "    ldr    sp,[r0]\n"
      "    add    r0,r0,#4\n"
      "    ldr    r1,[r0]\n"
      "    bx     r1");

//
// Load fimrware image from file into RAM
//
int loadFirmwareImage(void) {

  long            handle;
  SlFsFileInfo2_t pFsFileInfo2;
  Token_t         token = 0;

  // open file for read - used ROM function fs_Open()
  if ((handle = fs_Open(1, file, _FS_MODE_OPEN_READ, &token)) <= 0) return handle;

  // get file length - used ROM function fs_GetFileInfo()
  if (fs_GetFileInfo(1, file, &token, &pFsFileInfo2) < 0) return 2;

  // load application image into RAM - used ROM function fs_Read()
  if (fs_Read(handle, 0, (char *)APP_OFFSET, pFsFileInfo2.Size) < 0) return 3;

  return 0;
}

//
// Main
//
int main() {

  int retVal;

  // init hardware
  MAP_IntVTableBaseSet((unsigned long)&g_pfnVectors[0]);
  IntMasterEnable();
  IntEnable(FAULT_SYSTICK);
  PRCMCC3200MCUInit();

  // load image into RAM (always return -11)
  retVal = loadFirmwareImage();

  // execute image from RAM
  if (retVal == 0) runFirmwareImage(APP_OFFSET);

  while(1) {}
}

Bootloader linker file:

#define RAM_BASE 0x20004000

/* System memory map */
MEMORY
{
    /* Application uses internal RAM for program and data */
    SRAM_CODE (RWX) : origin = 0x20004000, length = 0x8000
    SRAM_DATA (RWX) : origin = 0x20000000, length = 0x4000
}


/* Section allocation in memory */
SECTIONS
{
    .intvecs:   > RAM_BASE
    .init_array : > SRAM_CODE
    .vtable :   > SRAM_CODE
    .text   :   > SRAM_CODE
    .const  :   > SRAM_CODE
    .cinit  :   > SRAM_CODE
    .pinit  :   > SRAM_CODE
    .data   :   > SRAM_DATA
    .bss    :   > SRAM_DATA
    .sysmem :   > SRAM_DATA
    .stack  :   > SRAM_DATA(HIGH)
}

Whole CSS 6.1.3 project:

5127.bootmgr.zip


Regards,

Jan

  • Hi,

    I worked on this bootloader to find root cause why it not working, I fund few issues:

    1. Mistake in linker file. SRAM DATA memory area cannot be set to beginning of RAM, because beginning of RAM is internally used for ROM functions.

    original:
    SRAM_DATA (RWX) : origin = 0x20000000, length = 0x4000
    new:
    SRAM_DATA (RWX) : origin = 0x200023a0, length = 0x1c60

    2. Missing initialization of the DMA controller. ROM function probably use DMA and without initialized DMA are not functional.

    new init code:
    // init hardware
    MAP_IntVTableBaseSet((unsigned long)&g_pfnVectors[0]);
    IntMasterEnable();
    IntEnable(FAULT_SYSTICK);
    PRCMCC3200MCUInit();
    UDMAInit();

    3. It seems file ROM functions (in address: 0x000020c5, 0x000022f3m etc.) are not able work with all file names. The are able to work only with limited number file names. This file names are hard coded in ROM (address 0x42b1 and bellow in hw ES1.33).

    List of usable file names:
    /sys/mcuimg.bin
    /sys/mcuflpatch.bin
    /sys/mcureserved.bin
    /sys/mcutst.bin
    etc.
    ROM function from filesystem.h:
    #define fs_Open        ((SlFileHandle_t  (*)(UINT8 SecurityFlag,const unsigned char *pFileName , UINT32 Mode, Token_t* pToken ))(0x000020c5))
    #define fs_Read        ((NumberOfBytes_t (*)(SlFileHandle_t FileHandle, UINT32 Offset, char* pData, UINT32 Len))(0x000022f3))
    #define fs_GetFileInfo ((long            (*)(UINT8 SecurityFlag, const unsigned char *pFileName, const Token_t* pToken ,SlFsFileInfo2_t* pFsFileInfo))0x000023db)
    #define fs_Close       ((long            (*)(InternalSecurityFlag_t InternalSecurityFlag, SlFileHandle_t FileHandle, SignatureAttr_t* pCertification))0x000022c5)

    Can any TI employee confirm my observations? I mean that ROM file systems function cannot be used with all file names and this functions are able work only with limited list of file names.

    Thanks

    Jan

  • Any response from TI engineer? Is not here someone (from Israel R&D?) who has access to NWP code and is able answer my question?

    Thank for answer

    Jan
  • no response?
  • Hi,

    Sorry for the delay.

    Let me touch base with the R&D and I'll get back to you (I am from the APPS team).

    Shlomi

  • Hi,

    Your observation is right.

    The "raw" file system methods works only on mcuXXX files since the file system itself is not loaded/initialized at this phase.

    mcuXXX files are required since M4 processor needs to load these files and execute but all other files are not really required.

    Regards,

    Shlomi

  • Hi,

    Thank you.

    Jan