bootloaderApp.c
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright 2014-2019 Inertial Sense, Inc. - http://inertialsense.com
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
7 
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT, IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #include <asf.h>
14 #include <string.h>
15 #include "../../src/data_sets.h"
16 #include "../../hw-libs/misc/rtos.h"
17 #include "bootloaderApp.h"
18 
19 
20 void unlockUserFlash(void)
21 {
22  // unlock 64K of config data at end in event that downgrade of firmware is happening, old firmware did not attempt to unlock before flash writes
23  for (uint32_t flashUnlockStart = BOOTLOADER_FLASH_USER_DATA_START_ADDRESS; flashUnlockStart < BOOTLOADER_FLASH_USER_DATA_END_ADDRESS; flashUnlockStart += BOOTLOADER_FLASH_BLOCK_SIZE)
24  {
25  flash_unlock(flashUnlockStart, flashUnlockStart + BOOTLOADER_FLASH_BLOCK_SIZE - 1, 0, 0); // unlock is inclusive
26  }
27 }
28 
29 
30 static void soft_reset_internal(void)
31 {
33 #if defined(PLATFORM_IS_EVB_2)
34 #else
35  usart_reset((Usart*)SERIAL0);
36  usart_reset((Usart*)SERIAL1);
37 #endif
40 
41  while(1);
42 }
43 
45 {
47 }
48 
49 void soft_reset_backup_register(uint32_t sysFaultStatus)
50 {
51  GPBR->SYS_GPBR[GPBR_IDX_STATUS] |= sysFaultStatus; // Report cause of reset
53 }
54 
55 void set_reset_pin_enabled(int enabled)
56 {
57  // *** WARNING *** Disabling the reset pin will require a chip erase via jtag to deploy new firmware
58  // *** WARNING *** Provide a way to re-enable the reset pin via message or other mechanism to avoid this
59 
60 #if 0
61 
62  if (enabled)
63  {
64  uint32_t mode = RSTC->RSTC_MR;
65  mode &= ~RSTC_MR_KEY_Msk;
67  RSTC->RSTC_MR = mode;
68  }
69  else
70  {
71  uint32_t mode = RSTC->RSTC_MR;
72  mode &= ~(RSTC_MR_URSTEN | RSTC_MR_KEY_Msk);
73  mode |= RSTC_MR_KEY_PASSWD;
74  RSTC->RSTC_MR = mode;
75  }
76 
77 #endif
78 
79 }
80 
81 
82 void enable_bootloader(int pHandle)
83 {
84  // update the bootloader header jump signature to indicate we want to go to bootloader
88 
89  // unlock bootloader header
90  flash_unlock(BOOTLOADER_FLASH_BOOTLOADER_HEADER_ADDRESS, BOOTLOADER_FLASH_BOOTLOADER_HEADER_ADDRESS + BOOTLOADER_FLASH_BOOTLOADER_HEADER_SIZE - 1, 0, 0);
91 
92  // this flash write is allowed to erase and write a 512 byte page because it is in the small sector, last param of 1 does this
93  flash_write(BOOTLOADER_FLASH_BOOTLOADER_HEADER_ADDRESS, &header, BOOTLOADER_FLASH_BOOTLOADER_HEADER_SIZE, 1);
94 
95  // unlock flash in case of firmware downgrade
97 
98  // Let the bootloader know which port to use for the firmware update. Set key and port number.
99  GPBR->SYS_GPBR[3] = PORT_SEL_KEY_SYS_GPBR_3;
100  GPBR->SYS_GPBR[4] = PORT_SEL_KEY_SYS_GPBR_4;
101  GPBR->SYS_GPBR[5] = PORT_SEL_KEY_SYS_GPBR_5;
102  GPBR->SYS_GPBR[6] = PORT_SEL_KEY_SYS_GPBR_6;
103  GPBR->SYS_GPBR[7] = pHandle;
104 
105  // reset processor
107 }
108 
109 
111 {
112  unlockUserFlash();
113 
114  //this enables SAM-BA
117 }
118 
119 
void soft_reset_backup_register(uint32_t sysFaultStatus)
Definition: bootloaderApp.c:49
#define GPBR_IDX_STATUS
Definition: rtos.h:40
void enable_bootloader(int pHandle)
Definition: bootloaderApp.c:82
#define GPBR
(GPBR ) Base Address
Definition: same70j19.h:537
#define RSTC_CR_KEY_PASSWD
(RSTC_CR) Writing any other value in this field aborts the write operation.
#define RSTC_MR_KEY_Msk
(RSTC_MR) Write Access Password
#define RSTC_MR_URSTEN
(RSTC_MR) User Reset Enable
CDCHeaderDescriptor header
#define PORT_SEL_KEY_SYS_GPBR_6
Usart hardware registers.
#define RSTC
(RSTC ) Base Address
Definition: same70j19.h:532
void set_reset_pin_enabled(int enabled)
Definition: bootloaderApp.c:55
uint32_t flash_clear_gpnvm(uint32_t ul_gpnvm)
Clear the given GPNVM bit.
Definition: flash_efc.c:897
void soft_reset_no_backup_register(void)
Definition: bootloaderApp.c:44
#define BOOTLOADER_FLASH_BOOTLOADER_HEADER_ADDRESS
void usart_reset(Usart *p_usart)
Reset the USART and disable TX and RX.
Definition: usart.c:240
#define BOOTLOADER_FLASH_USER_DATA_END_ADDRESS
#define BOOTLOADER_FLASH_BLOCK_SIZE
#define RSTC_CR_PROCRST
(RSTC_CR) Processor Reset
#define Disable_global_interrupt()
struct bootloader_header_t::@34 data
void unlockUserFlash(void)
Definition: bootloaderApp.c:20
uint32_t flash_write(uint32_t ul_address, const void *p_buffer, uint32_t ul_size, uint32_t ul_erase_flag)
Write a data buffer on flash.
Definition: flash_efc.c:607
#define BOOTLOADER_JUMP_SIGNATURE_STAY_IN_BOOTLOADER
#define PORT_SEL_KEY_SYS_GPBR_5
#define BOOTLOADER_FLASH_BOOTLOADER_HEADER_SIZE
#define PORT_SEL_KEY_SYS_GPBR_3
void enable_bootloader_assistant(void)
#define SYS_FAULT_STATUS_ENABLE_BOOTLOADER
Definition: data_sets.h:3285
static void soft_reset_internal(void)
Definition: bootloaderApp.c:30
Autogenerated API include file for the Atmel Software Framework (ASF)
#define RSTC_MR_KEY_PASSWD
(RSTC_MR) Writing any other value in this field aborts the write operation.Always reads as 0...
#define PORT_SEL_KEY_SYS_GPBR_4
char jumpSignature[BOOTLOADER_JUMP_SIGNATURE_SIZE]
#define BOOTLOADER_FLASH_USER_DATA_START_ADDRESS
uint32_t flash_unlock(uint32_t ul_start, uint32_t ul_end, uint32_t *pul_actual_start, uint32_t *pul_actual_end)
Unlock all the regions in the given address range. The actual unlock range is reported through two ou...
Definition: flash_efc.c:752


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:08