MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mccibootloaderplatform_startapp.c
Go to the documentation of this file.
1/*
2
3Module: mccibootloaderplatform_startapp.c
4
5Function:
6 McciBootloaderPlatform_startApp()
7
8Copyright and License:
9 This file copyright (C) 2021 by
10
11 MCCI Corporation
12 3520 Krums Corners Road
13 Ithaca, NY 14850
14
15 See accompanying LICENSE file for copyright and license information.
16
17Author:
18 Terry Moore, MCCI Corporation March 2021
19
20*/
21
23
25#include "mcci_arm_cm0plus.h"
26#include <stdint.h>
27
28/****************************************************************************\
29|
30| Manifest constants & typedefs.
31|
32\****************************************************************************/
33
34
35/****************************************************************************\
36|
37| Read-only data.
38|
39\****************************************************************************/
40
41
42
43/****************************************************************************\
44|
45| Variables.
46|
47\****************************************************************************/
48
49
50/*
51
52Name: McciBootloaderPlatform_startApp()
53
54Function:
55 Launch application from bootloader.
56
57Definition:
58 void McciBootloaderPlatform_startApp(
59 const void *pAppBase
60 );
61
62Description:
63 pAppBase points to the base of the application image in memory, which
64 is assumed to conform to any platform-specific requirements. The
65 application is launched. If the launch fails,
66 McciBootloaderPlatform_fail() is invoked. This function does not
67 return to the caller.
68
69Returns:
70 No explicit result.
71
72Notes:
73 On a Cortex M0+ or similar processor, pAppBase points to the vectors
74 of the app being invoked. The first dword is the stack pointer, and
75 the second dword is the start address.
76
77 In a full implementation, the bootloader should shutdown all
78 peripherals it has setup, and establish a default condition for
79 launching the app. In principal, the app should be entered as if
80 it had received control from a reset. This is to some degree a
81 matter of taste and design rather than a logical requirement.
82
83*/
84
85#define FUNCTION "McciBootloaderPlatform_startApp"
86
87void
89 const void *pAppBase
90 )
91 {
92 const Mcci_CortexAppEntryContents_t * const pAppVectors = pAppBase;
93 const uint32_t stack = pAppVectors->stack;
94 const uint32_t pc = pAppVectors->entry;
95
96 // Oddly, interrupts are enabled on launch, so we have to
97 // deal with that below.
98 McciArm_disableInterrupts();
99
100 // Do the SOC-specific things to get us ready;
102
103 // set the stack pointer
104 McciArm_setMSP(stack);
105
106 // set the vector address
109 (uint32_t) pAppVectors & MCCI_CM0PLUS_SCB_VTOR_TBLOFF
110 );
111
112 // go to the app: enable interrupts and jump.
113 __asm volatile ("cpsie i" ::: "memory");
114 __asm volatile ("bx %0" :: "r"(pc));
115 __builtin_unreachable();
116 }
117
118#undef FUNCTION
119
120
121/**** end of mccibootloaderplatform_startapp.c ****/
#define MCCI_CM0PLUS_SCB_VTOR
static uint32_t McciArm_putReg(uint32_t reg, uint32_t val)
write a 32-bit value to a cm0plus register
#define MCCI_CM0PLUS_SCB_VTOR_TBLOFF
static void McciBootloaderPlatform_prepareForLaunch(void)
void McciBootloaderPlatform_startApp(const void *pAppBase)
application entry contents
uint32_t entry
uint32_t stack