Functions
SBL Internal Functions

The section has a list of all internal functions which are used internally by the SBL module. More...

Functions

void SBL_bufferMgmt (uint32_t inputBuffer[], uint32_t bufferLen, uint8_t isLastBufferLcl)
 
static void SBL_applyConfigFile (uint32_t *bufferPtr, uint32_t bufferLen)
 
static void SBL_updateVarHeaderStateEnd (void)
 
static void SBL_readRPRCHeaderStateUpdate (uint32_t bytesRead)
 
static uint32_t SBL_extractRPRCHeader (uint32_t readPtrLcl[], uint32_t bufferLen)
 
static uint32_t SBL_readRPRCHeader (uint32_t *bufferPtr, uint32_t bufferLenIp)
 
static uint32_t SBL_handleSectionDwldComplete (void)
 
static uint32_t SBL_readRPRCSecContent (uint32_t *bufferPtr, uint32_t bufferLenIp)
 
static uint32_t SBL_readAlignmentBytes (uint32_t *bufferPtr, uint32_t bufferLenIp)
 
static uint32_t SBL_extractRPRCSecHeader (uint32_t readPtrLcl[])
 
static uint32_t SBL_updateVarSectionHeaderStateEnd (void)
 
static uint32_t SBL_readRPRCSecHeader (uint32_t *bufferPtr, uint32_t bufferLenIp)
 
void SBL_parserInitialization (void)
 
uint32_t SBL_imageParser (uint32_t *bufferPtr, uint32_t bufferLen)
 
void SBL_imageAuthParamsInit (void)
 
int32_t SBL_imageValidationCheck (uint32_t *readPtr, uint32_t bufferLen)
 
static void copyCode (uint32_t *dest, uint32_t *src, uint32_t length)
 
void _system_pre_init (void)
 
int main (void)
 
static uint32_t SBL_imageDetailParse (uint32_t bufferPtrLcl[])
 
uint32_t SBL_metaHeaderParser (uint32_t bufferPtr[])
 
static uint32_t SBL_stateMetaHeaderParser (uint32_t readPtrLcl[])
 
static uint32_t SBL_stateRPRCDownloadParse (uint32_t readPtrLcl[], uint32_t bufferLen)
 
void SBL_multicoreImageParser (void)
 
static void SBL_switchBuffer ()
 
void SBL_bufferMgmtTask (UArg arg0, UArg arg1)
 
int32_t SBL_imageLoader (QSPIFlash_Handle qspiFlashHandle, uint32_t flashAddr)
 
int32_t SBL_imageFlasher (QSPIFlash_Handle qspiFlashHandle, uint32_t flashAddr)
 
void SBL_initTask (UArg arg0, UArg arg1)
 
void SBL_init (void)
 
static int32_t SBL_verifyCRC (uint8_t *dataBuffer, uint32_t dataLength, uint32_t verifyCRC)
 
static void SBL_discardInput (void)
 
void SBL_transportInit (void)
 
void SBL_transportDeinit (void)
 
int32_t SBL_transportConfig (void)
 
int32_t SBL_transportRead (uint8_t *buffer, uint32_t size)
 
void SBL_printf (const uint8_t *pcFormat,...)
 
int32_t SBL_transportDownloadFile (QSPIFlash_Handle qspiFlashHandle, uint32_t flashAddr, uint32_t maxSize)
 
void SBL_platformInit (void)
 
void SBL_mpuConfigDefault (void)
 
void SBL_mpuConfigBSS (bool enable)
 
uint32_t SBL_calculateImageOffset (uint32_t sectionPtr, uint32_t sectionLen)
 

Detailed Description

The section has a list of all internal functions which are used internally by the SBL module.

Function Documentation

void _system_pre_init ( void  )

Description
This function is called on reset. It copies the code deom TCMA to TCMB memory. All the SBL routines run in TCMB memory. The variables used are defined in the linker command file.

Return values
NotApplicable
static void copyCode ( uint32_t *  dest,
uint32_t *  src,
uint32_t  length 
)
static

Description
Code copy routine

Return values
NotApplicable
int main ( void  )

Description
Entry point into the application code. This is the only code that runs in TCMA memory. Calls the SBL initialization routine that will run in TCMB memory.

Return values
NotApplicable.
static void SBL_applyConfigFile ( uint32_t *  bufferPtr,
uint32_t  bufferLen 
)
static

Description
Apply config file. This function implements the state m/c for the RPRC image parser.

Parameters
[in]bufferPtrConfig file buffer pointer.
[in]bufferLenData length.
Return values
Numberof bytes read.
void SBL_bufferMgmt ( uint32_t  inputBuffer[],
uint32_t  bufferLen,
uint8_t  isLastBufferLcl 
)

Description
This is the buffer management function that manages the input buffers. It invokes the parsing routine when the buffer is full.

Parameters
[in]inputBufferInput data to sent from the interface
[in]bufferLenLength of the input buffer
[in]isLastBufferLclFlag to indicate the the last buffer
Return values
Notapplicable
void SBL_bufferMgmtTask ( UArg  arg0,
UArg  arg1 
)

Description
Manages the parsing of buffers

Parameters
[in]arg0Task Arg0
[in]arg1Task Arg1
Return values
NotApplicable.
uint32_t SBL_calculateImageOffset ( uint32_t  sectionPtr,
uint32_t  sectionLen 
)

Description
This function calculates the RAM file offset.

Parameters
[in]sectionPtrSection start address.
[in]sectionLenSection Length.
Return values
RAMOffset
static void SBL_discardInput ( void  )
static

Description
This function is used to discard the incoming UART stream incase an error is detected.

Return values
NotApplicable.
static uint32_t SBL_extractRPRCHeader ( uint32_t  readPtrLcl[],
uint32_t  bufferLen 
)
static

Description
Used to extract the RPRC header.

Parameters
[in]readPtrLclBuffer pointer.
[in]bufferLenBuffer length.
Return values
Numberof bytes read.
static uint32_t SBL_extractRPRCSecHeader ( uint32_t  readPtrLcl[])
static

Description
This function is used to extract the section header.

Parameters
[in]readPtrLclBuffer pointer
Return values
Numberof bytes read.
static uint32_t SBL_handleSectionDwldComplete ( void  )
static

Description
Used to update globals on sectionDwld complete.

Return values
Numberof bytes read.
void SBL_imageAuthParamsInit ( void  )

Description
Initializes the decryption parameters to reset state.

Return values
Notapplicable
static uint32_t SBL_imageDetailParse ( uint32_t  bufferPtrLcl[])
static

Description
This function extracts the image details from Meta Header.

Parameters
[in]bufferPtrLclBuffer pointer.
Return values
Numberof bytes read.
int32_t SBL_imageFlasher ( QSPIFlash_Handle  qspiFlashHandle,
uint32_t  flashAddr 
)

Description
This function download the application meta imageover over a device peripheral. It does the following:

  1. Erases the portion of SFLASH where the Metaimage has to be stored.
  2. Receives the Metaimage over transport interface.
  3. Stores the image into the SFLASH.
Parameters
[in]qspiFlashHandleHandle of QSPI Flash module.
[in]flashAddrAddress of SFLASH location where the application meta image is written to.
Return values
Success- 0
Error- SBL Error code
int32_t SBL_imageLoader ( QSPIFlash_Handle  qspiFlashHandle,
uint32_t  flashAddr 
)

Description
Downloads the Application Metaimage from FLASH to respective RAMs

Parameters
[in]qspiFlashHandleHandle of QSPI Flash module.
[in]flashAddrAddress of SFLASH location where the application meta image is written to.
Return values
Success- 0
Error- SBL Error code
uint32_t SBL_imageParser ( uint32_t *  bufferPtr,
uint32_t  bufferLen 
)

Description
This function implements the state m/c for the RPRC image parser.

Parameters
[in]bufferPtrInput buffer for parsing
[in]bufferLenInput buffer data length
Return values
Numberof bytes used.
int32_t SBL_imageValidationCheck ( uint32_t *  readPtr,
uint32_t  bufferLen 
)

Description
Authenticates and validates the image.

Parameters
[in]readPtrInput data that has to be validated.
[in]bufferLenData length in bytes.
Return values
Success- 0
Error- SBL Error code
void SBL_init ( void  )

Description
Called from main.c that runs in TCMA memory. It initializes the SOC, Configures MPU, halts DSS, performs platform related intializations and launches the init task.

Return values
NotApplicable.
void SBL_initTask ( UArg  arg0,
UArg  arg1 
)

Description
Decides whether the application acts as meta Image Flasher or Image Loader based upon user input.

Parameters
[in]arg0Task Arg0
[in]arg1Task Arg1
Return values
NotApplicable.
uint32_t SBL_metaHeaderParser ( uint32_t  bufferPtr[])

Description
This function implements the parser for the meta header.

Parameters
[in]bufferPtrPointer to the buffer containing the meta header.
Return values
Numberof bytes read.
void SBL_mpuConfigBSS ( bool  enable)

Description
This function configures the MPU for BSS regions.

Parameters
[in]enableFlag to enable or disable the MPU settings for BSS regions.
Return values
Notapplicable.
void SBL_mpuConfigDefault ( void  )

Description
The function is used to initialize MPU (Memory Protection Unit) settings. This is valid only for the R4. Information about MPU programming is available at:-

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0363g/Chdcahcf.html.

  1. This code comes up after the C initialization (from _c_int00 to main). Presently, the application comes up in privilege mode, not user mode. So the access permissions are set accordingly.
  2. There is no cache on the R4F on the AR parts, so regions that would otherwise make sense to be cacheable are made non-cache.
  3. Peripheral space is strongly ordered instead of device because writes need to go through when they are issued and not at a later (uncertain time when next read forces the writes sitting in write buffer to be flushed out, reference: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0363g/Chdcahcf.html). An alternative way is to use the Device type instead of strongly orderered but this requires all driver code to be scrutinized for APIs that do a write at the end and for such APIs a "dsb" instruction needs to be issued. This is prone to errors during maintenance work so it is safer to choose strongly-ordered. Presently, the architecture is more memory size constrained than cycles (MIPS) constrained so safety benefits at potentially increased cycles are a good trade-off.
  4. L3 Memory has been set as normal. This means for any transfer of ownership from R4F to non-R4F (peripherals, HW acc), a "dsb" instruction should be issued after the last write and before notifying/triggering the non-R4F entity.
  5. Mailbox Memory has been set as normal. This means for any transfer of ownership from R4F to non-R4F (BSS for example), a "dsb" instruction (MEM_BARRIER()) should be issued after the last write to the mailbox message memory before notifying/triggering the non-R4F entity.
  6. BSS Memory will be configured when the BSS sections are updated. In the default MPU configuration, these sections are marked as reserved.

    Return values
    Notapplicable
void SBL_multicoreImageParser ( void  )

Description
This function implements the state machine for the Meta Image parsing.

Return values
Notapplicable.
void SBL_parserInitialization ( void  )

Description
This function is the initialization function for all the parser variables.

Return values
Notapplicable.
void SBL_platformInit ( void  )

Description
Platform specific intializations.

Return values
Notapplicable
void SBL_printf ( const uint8_t *  pcFormat,
  ... 
)

Description
Takes the Formatted input string and dumps it on the UART console

Return values
NotApplicable
static uint32_t SBL_readAlignmentBytes ( uint32_t *  bufferPtr,
uint32_t  bufferLenIp 
)
static

Description
This function returns number of alignment bytes used.

Parameters
[in]bufferPtrPointer to the buffer that contains data for parsing.
[in]bufferLenIpBuffer length in bytes.
Return values
Numberof bytes read.
static uint32_t SBL_readRPRCHeader ( uint32_t *  bufferPtr,
uint32_t  bufferLenIp 
)
static

Description
RPRC Image header parser. This function implements the state m/c for the RPRC image header parser.

Parameters
[in]bufferPtrPointer to the buffer used for parsing.
[in]bufferLenIpBuffer length in bytes.
Return values
Numberof bytes read.
static void SBL_readRPRCHeaderStateUpdate ( uint32_t  bytesRead)
static

Description
Used to read RPRC header header state update.

Parameters
[in]bytesReadNumber of bytes used.
Return values
Notapplicable.
static uint32_t SBL_readRPRCSecContent ( uint32_t *  bufferPtr,
uint32_t  bufferLenIp 
)
static

Description
This function process the RPRC image section content.

Parameters
[in]bufferPtrPointer to the buffer that contains data for parsing.
[in]bufferLenIpBuffer length in bytes.
Return values
Numberof bytes read.
static uint32_t SBL_readRPRCSecHeader ( uint32_t *  bufferPtr,
uint32_t  bufferLenIp 
)
static

Description
This function implements the state m/c for the RPRC image section header parser.

Parameters
[in]bufferPtrPointer to the buffer that contains data for parsing.
[in]bufferLenIpBuffer length in bytes.
Return values
Numberof bytes read.
static uint32_t SBL_stateMetaHeaderParser ( uint32_t  readPtrLcl[])
static

Description
This function parses the Meta Header.

Parameters
[in]readPtrLclPointer to the input buffer.
Return values
Numberof bytes read.
static uint32_t SBL_stateRPRCDownloadParse ( uint32_t  readPtrLcl[],
uint32_t  bufferLen 
)
static

Description
This function parses the RPRC image.

Parameters
[in]readPtrLclPointer to the input buffer.
[in]bufferLenInput buffer length.
Return values
Numberof bytes read.
static void SBL_switchBuffer ( )
inlinestatic

Description
Switches between Ping and Pong Buffer

Return values
NotApplicable.
int32_t SBL_transportConfig ( void  )

Description
Opens the UART instance in the specified mode.

Return values
Success- 0
Error- SBL Error code
void SBL_transportDeinit ( void  )

Description
This function de-initializes the UART interface that is used as transport to download the file.

Return values
NotApplicable.
int32_t SBL_transportDownloadFile ( QSPIFlash_Handle  qspiFlashHandle,
uint32_t  flashAddr,
uint32_t  maxSize 
)

Description
This function downloads the application meta image file over UART using XMODEM. The downloaded file is written to SFLASH pointed to by the flash address. XMODEM receive routine is implemented based on the following sender<->receiver handshake. NAK and CAN handshake is not shown below.

RECEIVER ("s -k foo.bar") SENDER ("foo.bar open x.x minutes")

C
                                STX 01 FE Data[1024] CRC CRC
ACK
                                STX 02 FD Data[1024] CRC CRC
ACK
                                SOH 03 FC Data[128] CRC CRC
ACK
                                SOH 04 FB Data[100] CPMEOF[28] CRC CRC
ACK
                                EOT
ACK
Parameters
[in]qspiFlashHandleHandle of QSPI Flash module.
[in]flashAddrAddress of SFLASH location where the application meta image is written to.
[in]maxSizeMaximum size of meta image.
Return values
Success- Number of bytes read.
Error- SBL Error code.
void SBL_transportInit ( void  )

Description
This function initializes the UART interface that is used as transport to download the file.

Return values
NotApplicable.
int32_t SBL_transportRead ( uint8_t *  buffer,
uint32_t  size 
)

Description
This function is used to read a input character from the UART peripheral.

Return values
NotApplicable.
static void SBL_updateVarHeaderStateEnd ( void  )
static

Description
Used to update globals at the end of RPRC header.

Return values
Notapplicable.
static uint32_t SBL_updateVarSectionHeaderStateEnd ( void  )
static

Description
Used to update the globals in end sectionHeader.

Return values
Imageoffset.
static int32_t SBL_verifyCRC ( uint8_t *  dataBuffer,
uint32_t  dataLength,
uint32_t  verifyCRC 
)
static

Description
This function is used to verify the CRC or checksum of a block of data.

Parameters
[in]dataBufferPointer to the data buffer.
[in]dataLengthSize of the data buffer.
[in]verifyCRCFlag indicating whether CRC or checksum has to be verified.
Return values
Success- 0
Error- SBL Error code

Copyright 2019, Texas Instruments Incorporated