Skip to content

Commit 0f7c97b

Browse files
committed
SFU: Initial
1 parent 2e56526 commit 0f7c97b

File tree

7 files changed

+4002
-0
lines changed

7 files changed

+4002
-0
lines changed

libraries/SFU/.portenta_only

Whitespace-only changes.

libraries/SFU/extra/loader/loader.ino

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
/* Key code for writing PRCR register. */
3+
#define BSP_PRV_PRCR_KEY (0xA500U)
4+
#define BSP_PRV_PRCR_PRC1_UNLOCK ((BSP_PRV_PRCR_KEY) | 0x2U)
5+
#define BSP_PRV_PRCR_LOCK ((BSP_PRV_PRCR_KEY) | 0x0U)
6+
7+
#define BSP_PRV_BITS_PER_WORD (32)
8+
9+
10+
#define POST_APPLICATION_ADDR (0x10000)
11+
#define SKETCH_FLASH_OFFSET (64 * 1024)
12+
13+
void setup() {
14+
Serial.begin(9600);
15+
//while(!Serial){}
16+
Serial.println("2nd stage bootloader");
17+
18+
int app_valid = (((*(uint32_t *) SKETCH_FLASH_OFFSET + POST_APPLICATION_ADDR) & 0xFF000000) == 0x20000000);
19+
if (app_valid) {
20+
Serial.print("Booting application @");
21+
Serial.print(SKETCH_FLASH_OFFSET + POST_APPLICATION_ADDR, HEX);
22+
boot5(SKETCH_FLASH_OFFSET + POST_APPLICATION_ADDR);
23+
} else {
24+
Serial.print("Application not found");
25+
}
26+
}
27+
28+
void loop() {
29+
30+
}
31+
32+
void boot5(uint32_t address) {
33+
34+
R_SYSTEM->PRCR = (uint16_t) BSP_PRV_PRCR_PRC1_UNLOCK;
35+
R_BSP_MODULE_STOP(FSP_IP_USBFS, 0);
36+
R_BSP_MODULE_STOP(FSP_IP_USBHS, 0);
37+
R_SYSTEM->PRCR = (uint16_t) BSP_PRV_PRCR_LOCK;
38+
39+
/* Disable MSP monitoring. */
40+
#if BSP_FEATURE_TZ_HAS_TRUSTZONE
41+
__set_MSPLIM(0);
42+
#else
43+
R_MPU_SPMON->SP[0].CTL = 0;
44+
#endif
45+
46+
__disable_irq(); // Note: remember to enable IRQ in application
47+
__DSB();
48+
__ISB();
49+
50+
// Disable SysTick
51+
SysTick->CTRL = 0;
52+
53+
SCB->VTOR = address;
54+
55+
// Cleanup NVIC
56+
for (size_t i = 0U; i < BSP_ICU_VECTOR_MAX_ENTRIES / BSP_PRV_BITS_PER_WORD; i++)
57+
{
58+
NVIC->ICER[i] = 0xFF;
59+
}
60+
61+
uint32_t mainStackPointer = *(volatile uint32_t *)(address);
62+
__set_MSP(mainStackPointer);
63+
uint32_t programResetHandlerAddress = *(volatile uint32_t *) (address + 4);
64+
void (* programResetHandler)(void) = (void (*)(void)) programResetHandlerAddress;
65+
programResetHandler();
66+
}

libraries/SFU/library.properties

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=SFU
2+
version=1.0.0
3+
author=Arduino
4+
maintainer=Arduino <[email protected]>
5+
sentence=Second stage bootloader for Portenta C33
6+
paragraph=
7+
category=Other
8+
url=https://www.arduino.cc/en/Reference/SFU
9+
architectures=renesas_portenta,renesas

libraries/SFU/src/SFU.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
SFU.h
3+
Copyright (c) 2023 Arduino SA. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#include "SFU.h"
21+
22+
const unsigned char SFU[0x10000] __attribute__ ((section(".second_stage_ota"), used)) = {
23+
#include "c33.h"
24+
};

libraries/SFU/src/SFU.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
SFU.h
3+
Copyright (c) 2023 Arduino SA. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef _SFU_H_
21+
#define _SFU_H_
22+
23+
#include "Arduino.h"
24+
25+
class SFU {
26+
public:
27+
static int begin();
28+
static int download(const char* url);
29+
static int apply();
30+
};
31+
32+
#endif // _SFU_H_

0 commit comments

Comments
 (0)