Callisto4Bootloader: src/bootloader.c File Reference

Callisto4Bootloader

Data Structures | Macros | Typedefs | Functions | Variables
bootloader.c File Reference
`#include "bootloader_types.h"`
`#include "c4_error_codes.h"`
`#include "c4_qspi.h"`
`#include "c4_parser.h"`
`#include "c4_tftp.h"`
`#include "FreeRTOS.h"`
`#include "task.h"`
`#include "queue.h"`
`#include "timers.h"`
`#include "lwip/tcpip.h"`
`#include "enet_ethernetif.h"`
`#include "httpserver-netconn.h"`
`#include "board.h"`
`#include "pin_mux.h"`
`#include "clock_config.h"`
`#include "fsl_device_registers.h"`
`#include "fsl_iomuxc.h"`
`#include "fsl_lpi2c.h"`
`#include "sja1105.h"`
`#include "remsdaq_uart.h"`
`#include "platform-eeprom-header.h"`
`#include "platform-basetypes.h"`
`#include "platform-memory-map.h"`

Go to the source code of this file.

## Data Structures

union | CPUID_t
| structure for CPU ID base register in System Control Block (SCB). More...

## Macros

#define | FORCE_WRITE_TO_EEPROM 0
#define | PTP_APP_MASTER_TEST 0
#define | STACK_INIT_USE_TASK 0
#define | configSUPPLIER_CODE 'D'
| Manufacturer ID (1 character) More...
#define | configDEVICE 12369
| Device code (5-digit number) More...
#define | configOPTION 1
| Option code (2-digit number) More...
#define | configREVISION 'A'
| Revision code (1 character) More...
#define | configYEAR 20
| Year (2-digit number) More...
#define | configWEEK 9
| week (2-digit number) More...
#define | configSERIAL 1
| Serial number (3-digit number) More...
#define | configSERIAL_NUM(str)
#define | configHOSTNAME "Module-57920"
#define | configMAC_ADDR(X) X(0x00,0x0e,0xbf,0x33,0x00,0x00)
#define | configIP_ADDR(X) X(169,254,154,150)
#define | configNET_MASK(X) X(255,255,255,0)
#define | configGW_ADDR(X) X(0,0,0,0)
#define | configCOAP_ADDR(X) X(224,0,1,187)
#define | configUSE_DHCP 0
#define | COAP_TASK_STACK_SIZE (30000 / 4)
#define | COAP_TASK_PRIO 4
#define | C4_PRINT(...) printf(__VA_ARGS__)
#define | EXAMPLE_CLOCK_NAME kCLOCK_CoreSysClk
#define | MAIN_THREAD_NAME "Main Thread"
#define | MAIN_THREAD_STACKSIZE_BYTES 8192
#define | MAIN_THREAD_PRIO DEFAULT_THREAD_PRIO

## Typedefs

typedef char | tHostName[PLATFORM_HOSTNAME_MAXLEN]
typedef char | tSerialNo[PLATFORM_SERIAL_LEN]
typedef stEEPROM_Header_t | tFactoryConfig

## Functions

void | stack_init (stEEPROM_Header_t *stEEPROM_Header)
| Initialise the IP stack. More...
void | ipaddress_show (stEEPROM_Header_t *stEEPROM_Header)
void | coap_join_group (stEEPROM_Header_t *stEEPROM_Header)
void | main_task (void *pvParam)
void | BOARD_InitLPSPI3 (void)
void | BOARD_InitModuleClock (void)
void | RegisterFactoryConfig (void)
void | eeprom_header_setdefaults (stEEPROM_Header_t *pstHeader)
| Set the local defaults to use if the EEPROM header couldn't be read in. More...
static void | C4_jumpToUserApplication (uint32_t app_start, const char *args)
| Set up jump and arguments. More...
static void | C4_jump (uint32_t user_sp, uint32_t user_startup, const char *argv)
| Jump to application. More...
static exit_code_t | C4_checkExecutable (const serialNOR_t *image)
| Check whether an executable exists at the location and is valid. More...
static void | C4_displayVectorTable (const char *identifier, const serialNOR_t *table)
| Print out vector table. More...
static void | C4_BootFunc (void *pParam)
| MAKE_STRING (tHostName)
| MAKE_STRING (tSerialNo)
void | BL_SysTick_DelayTicks (uint32_t n)
| Sets a delay. More...
int | main (void)
| Application entry point. More...

## Variables

char | qspiflash_config
char | image_vector_table
char | boot_data
static const uint32_t | VER_MAJ = 0
| Major version number. More...
static const uint32_t | VER_MIN = 1
| Minor version number. More...
static const char *const | VER_DATE = __DATE__
| Compilation date. More...
static const char *const | VER_TIME = "time"
| Compilation time. More...
static const ptrdiff_t | IVT_offset = 0x1000L
| fixed offset of IVT in program image region. More...
static const uint32_t | BUF_LEN = 1024
volatile char | qspifake
uint32_t | __Vectors []
uint32_t | __boot_hdr_start__ []
uint32_t | __boot_hdr_end__ []
uint32_t * | __vectors_start__
uint32_t * | __section_table_start
unsigned int | __data_section_table
unsigned int | __data_section_table_end
unsigned int | __bss_section_table
unsigned int | __bss_section_table_end
uint32_t * | __section_table_end
stPlatformCalls_t | stPlatformCalls
static struct netif | fsl_netif1
static ip4_addr_t | fsl_netif1_ipaddr
static ip4_addr_t | fsl_netif1_netmask
static ip4_addr_t | fsl_netif1_gw
static const uint32_t | CURRENT = 0
| Index in jump location array for currant image. More...
static const uint32_t | RECOVERY = 1

## Macro Definition Documentation

## ◆ C4_PRINT

#define C4_PRINT | ( |  | ... | ) | printf(__VA_ARGS__)

Definition at line 153 of file bootloader.c.

## ◆ COAP_TASK_PRIO

#define COAP_TASK_PRIO 4

Definition at line 147 of file bootloader.c.

## ◆ COAP_TASK_STACK_SIZE

#define COAP_TASK_STACK_SIZE (30000 / 4)

Definition at line 146 of file bootloader.c.

## ◆ configCOAP_ADDR

#define configCOAP_ADDR | ( |  | X | ) | X(224,0,1,187)

Definition at line 143 of file bootloader.c.

## ◆ configDEVICE

#define configDEVICE 12369

Device code (5-digit number)

Definition at line 110 of file bootloader.c.

## ◆ configGW_ADDR

#define configGW_ADDR | ( |  | X | ) | X(0,0,0,0)

Definition at line 142 of file bootloader.c.

## ◆ configHOSTNAME

#define configHOSTNAME "Module-57920"

Definition at line 138 of file bootloader.c.

## ◆ configIP_ADDR

#define configIP_ADDR | ( |  | X | ) | X(169,254,154,150)

Definition at line 140 of file bootloader.c.

## ◆ configMAC_ADDR

#define configMAC_ADDR | ( |  | X | ) | X(0x00,0x0e,0xbf,0x33,0x00,0x00)

Definition at line 139 of file bootloader.c.

## ◆ configNET_MASK

#define configNET_MASK | ( |  | X | ) | X(255,255,255,0)

Definition at line 141 of file bootloader.c.

## ◆ configOPTION

#define configOPTION 1

Option code (2-digit number)

Definition at line 112 of file bootloader.c.

## ◆ configREVISION

#define configREVISION 'A'

Revision code (1 character)

Definition at line 114 of file bootloader.c.

## ◆ configSERIAL

#define configSERIAL 1

Serial number (3-digit number)

Definition at line 120 of file bootloader.c.

## ◆ configSERIAL_NUM

#define configSERIAL_NUM | ( |  | str | ) |

Value:
snprintf(str, PLATFORM_SERIAL_LEN+1, "%c%05d%02d%c%02d%02d%03d", \
configSUPPLIER_CODE, \
configDEVICE, \
configOPTION, \
configREVISION, \
configYEAR, \
configWEEK, \
configSERIAL)

Device serial number (16-character string)

Construct the serial string from the above information.

Parameters

  [out] | str | Array to hold serial string.

Returns
  number of characters written to string

Definition at line 128 of file bootloader.c.

## ◆ configSUPPLIER_CODE

#define configSUPPLIER_CODE 'D'

Manufacturer ID (1 character)

- D - Danton
- S - SRX
- F - DFM
- N - Nyquist

Definition at line 108 of file bootloader.c.

## ◆ configUSE_DHCP

#define configUSE_DHCP 0

Definition at line 144 of file bootloader.c.

## ◆ configWEEK

#define configWEEK 9

week (2-digit number)

Definition at line 118 of file bootloader.c.

## ◆ configYEAR

#define configYEAR 20

Year (2-digit number)

Definition at line 116 of file bootloader.c.

## ◆ EXAMPLE_CLOCK_NAME

#define EXAMPLE_CLOCK_NAME kCLOCK_CoreSysClk

Definition at line 176 of file bootloader.c.

## ◆ FORCE_WRITE_TO_EEPROM

#define FORCE_WRITE_TO_EEPROM 0

Definition at line 94 of file bootloader.c.

## ◆ MAIN_THREAD_NAME

#define MAIN_THREAD_NAME "Main Thread"

Definition at line 178 of file bootloader.c.

## ◆ MAIN_THREAD_PRIO

#define MAIN_THREAD_PRIO DEFAULT_THREAD_PRIO

Definition at line 180 of file bootloader.c.

## ◆ MAIN_THREAD_STACKSIZE_BYTES

#define MAIN_THREAD_STACKSIZE_BYTES 8192

Definition at line 179 of file bootloader.c.

## ◆ PTP_APP_MASTER_TEST

#define PTP_APP_MASTER_TEST 0

Definition at line 96 of file bootloader.c.

## ◆ STACK_INIT_USE_TASK

#define STACK_INIT_USE_TASK 0

Definition at line 98 of file bootloader.c.

## Typedef Documentation

## ◆ tFactoryConfig

typedef stEEPROM_Header_t tFactoryConfig

Definition at line 308 of file bootloader.c.

## ◆ tHostName

typedef char tHostName[PLATFORM_HOSTNAME_MAXLEN]

Definition at line 303 of file bootloader.c.

## ◆ tSerialNo

typedef char tSerialNo[PLATFORM_SERIAL_LEN]

Definition at line 305 of file bootloader.c.

## Function Documentation

## ◆ BL_SysTick_DelayTicks()

void BL_SysTick_DelayTicks | ( | uint32_t | n | ) |

Sets a delay.

Expose function from bootloader.c.

Parameters

  [in] | n | Delay time in ms

Definition at line 317 of file bootloader.c.

Referenced by C4_displayError(), C4_flashError(), and FlashLed().

## ◆ BOARD_InitLPSPI3()

void BOARD_InitLPSPI3 | ( | void |  | ) |

Initialise LPSPI3's pin muxes

This can't go in the NXP config because many modules don't use LPSPI3

Definition at line 875 of file bootloader.c.

## ◆ BOARD_InitModuleClock()

void BOARD_InitModuleClock | ( | void |  | ) |

Set up the Ethernet PLL

FIXME: shouldn't this live in the NXP clock config setup instead?

Definition at line 599 of file bootloader.c.

## ◆ C4_BootFunc()

static void C4_BootFunc | ( | void * | pParam | ) |

static

Definition at line 605 of file bootloader.c.

## ◆ C4_checkExecutable()

static exit_code_t C4_checkExecutable | ( | const serialNOR_t * | image | ) |

static

Check whether an executable exists at the location and is valid.

This performs a simple check that the first word is not un set (0xFFFF_FFFF in NOR Flash) and performs other tests such as checking CRC.

Parameters

  [in] | image | Start of image region.

Returns
  Exit code

Return values

  C4_ERR_OK | image passes tests.
  C4_ERR_INCOMPATIBLE_IMAGE | image is not compatible.
  C4_ERR_CORRUPT_IMAGE | image is corrupt or not present

Definition at line 838 of file bootloader.c.

## ◆ C4_displayVectorTable()

static void C4_displayVectorTable | ( | const char * | identifier,
|  | const serialNOR_t * | table
| ) |  |

static

Print out vector table.

Parameters

  [in] | identifier | Descriptive text to help reader identify which image vector table applies to.
  [in] | table | Vector table to diplay.

Definition at line 853 of file bootloader.c.

## ◆ C4_jump()

static void C4_jump | ( | uint32_t | user_sp,
|  | uint32_t | user_startup,
|  | const char * | argv
| ) |  |

static

Jump to application.

Sets the stack pointer and program counter.

This function does not return in normal situations.

Parameters

  [in] | user_sp | Location to set stack pointer.
  [in] | user_startup | Location to set program counter.
  [in] | argv | Arguments to be passed to program.

Definition at line 788 of file bootloader.c.

## ◆ C4_jumpToUserApplication()

static void C4_jumpToUserApplication | ( | uint32_t | app_start,
|  | const char * | args
| ) |  |

static

Set up jump and arguments.

This determines the stack and program counter from the values contained in the application flash.

Parameters

  [in] | app_start | Beginning of application flash location.
  [in] | args | Aguments to be passed to the application.

Definition at line 767 of file bootloader.c.

## ◆ coap_join_group()

void coap_join_group | ( | stEEPROM_Header_t * | stEEPROM_Header | ) |

## ◆ eeprom_header_setdefaults()

void eeprom_header_setdefaults | ( | stEEPROM_Header_t * | pstHeader | ) |

Set the local defaults to use if the EEPROM header couldn't be read in.

Parameters

  [out] | pstHeader | Header to fill with defaults

## ◆ ipaddress_show()

void ipaddress_show | ( | stEEPROM_Header_t * | stEEPROM_Header | ) |

Display the current IP address, subnet mask, and gateway address

Definition at line 530 of file bootloader.c.

Referenced by stack_init().

## ◆ main()

int main | ( | void |  | ) |

Application entry point.

Returns
  Doesn't actually return

Initialises board hardware, reads EEPROM, starts the platform code etc.

Definition at line 334 of file bootloader.c.

Referenced by __attribute__().

## ◆ main_task()

void main_task | ( | void * | pvParam | ) |

Parameters

  [in] | pvParam | Task parameter pointer (not used)

Low priority (i.e. unimportant) background task.

Definition at line 554 of file bootloader.c.

## ◆ MAKE_STRING() [1/2]

MAKE_STRING | ( | tHostName |  | ) |

## ◆ MAKE_STRING() [2/2]

MAKE_STRING | ( | tSerialNo |  | ) |

## ◆ RegisterFactoryConfig()

void RegisterFactoryConfig | ( | void |  | ) |

## ◆ stack_init()

void stack_init | ( | stEEPROM_Header_t * | stEEPROM_Header | ) |

Initialise the IP stack.

Starts LWIP, TCPIP, IGMP, etc

Definition at line 429 of file bootloader.c.

References EXAMPLE_CLOCK_NAME, fsl_netif1, fsl_netif1_gw, fsl_netif1_ipaddr, fsl_netif1_netmask, ipaddress_show(), and NULL.

## Variable Documentation

## ◆ __boot_hdr_end__

uint32_t __boot_hdr_end__[]

## ◆ __boot_hdr_start__

uint32_t __boot_hdr_start__[]

## ◆ __bss_section_table

unsigned int __bss_section_table

## ◆ __bss_section_table_end

unsigned int __bss_section_table_end

## ◆ __data_section_table

unsigned int __data_section_table

## ◆ __data_section_table_end

unsigned int __data_section_table_end

## ◆ __section_table_end

uint32_t* __section_table_end

## ◆ __section_table_start

uint32_t* __section_table_start

## ◆ __Vectors

uint32_t __Vectors[]

## ◆ __vectors_start__

uint32_t* __vectors_start__

## ◆ boot_data

char boot_data

## ◆ BUF_LEN

const uint32_t BUF_LEN = 1024

static

Definition at line 173 of file bootloader.c.

## ◆ CURRENT

const uint32_t CURRENT = 0

static

Index in jump location array for currant image.

Definition at line 169 of file bootloader.c.

## ◆ fsl_netif1

struct netif fsl_netif1

static

Definition at line 298 of file bootloader.c.

Referenced by stack_init().

## ◆ fsl_netif1_gw

ip4_addr_t fsl_netif1_gw

static

Definition at line 301 of file bootloader.c.

Referenced by stack_init().

## ◆ fsl_netif1_ipaddr

ip4_addr_t fsl_netif1_ipaddr

static

Definition at line 299 of file bootloader.c.

Referenced by stack_init().

## ◆ fsl_netif1_netmask

ip4_addr_t fsl_netif1_netmask

static

Definition at line 300 of file bootloader.c.

Referenced by stack_init().

## ◆ image_vector_table

char image_vector_table

## ◆ IVT_offset

const ptrdiff_t IVT_offset = 0x1000L

static

fixed offset of IVT in program image region.

Definition at line 165 of file bootloader.c.

## ◆ qspifake

volatile char qspifake

Definition at line 277 of file bootloader.c.

## ◆ qspiflash_config

char qspiflash_config

## ◆ RECOVERY

const uint32_t RECOVERY = 1

static

Definition at line 170 of file bootloader.c.

## ◆ stPlatformCalls

stPlatformCalls_t stPlatformCalls

Definition at line 296 of file bootloader.c.

## ◆ VER_DATE

const char* const VER_DATE = __DATE__

static

Compilation date.

Definition at line 160 of file bootloader.c.

## ◆ VER_MAJ

const uint32_t VER_MAJ = 0

static

Major version number.

Definition at line 156 of file bootloader.c.

## ◆ VER_MIN

const uint32_t VER_MIN = 1

static

Minor version number.

Definition at line 158 of file bootloader.c.

## ◆ VER_TIME

const char* const VER_TIME = "time"

static

Compilation time.

Definition at line 162 of file bootloader.c.

configDEVICE
#define configDEVICE
Device code (5-digit number)
Definition: bootloader.c:110
configSERIAL
#define configSERIAL
Serial number (3-digit number)
Definition: bootloader.c:120
configOPTION
#define configOPTION
Option code (2-digit number)
Definition: bootloader.c:112
configYEAR
#define configYEAR
Year (2-digit number)
Definition: bootloader.c:116
configWEEK
#define configWEEK
week (2-digit number)
Definition: bootloader.c:118
configREVISION
#define configREVISION
Revision code (1 character)
Definition: bootloader.c:114
configSUPPLIER_CODE
#define configSUPPLIER_CODE
Manufacturer ID (1 character)
Definition: bootloader.c:108