Skip to content

Commit e7728d4

Browse files
dgarskedanielinux
authored andcommitted
Vorago VA416xx port improvements
1 parent 8c3533a commit e7728d4

3 files changed

Lines changed: 38 additions & 11 deletions

File tree

docs/Targets.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4705,7 +4705,7 @@ The default build uses DEBUG_UART=1 to generate logging on the UART.
47054705

47064706
```sh
47074707
cp config/examples/vorago_va416x0.config .config
4708-
make VORAGO_SDK_DIR=$PWD../VA416xx_SDK/
4708+
make VORAGO_SDK_DIR=$PWD/../VA416xx_SDK/
47094709
[CC ARM] src/string.o
47104710
[CC ARM] src/image.o
47114711
[CC ARM] src/libwolfboot.o
@@ -4850,6 +4850,7 @@ echo -n "pBOOT" > trigger_magic.bin
48504850
0x3F7FB trigger_magic.bin
48514851

48524852
# Use JLink to load
4853+
#JLinkExe -CommanderScript tools/scripts/va416x0/flash_va416xx_update.jlink
48534854
device VA416XX
48544855
si 1
48554856
speed 2000

hal/va416x0.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ hal_status_t FRAM_Write(uint8_t spiBank, uint32_t addr, uint8_t *buf,
237237
hal_status_t status = hal_status_ok;
238238
uint8_t spiData[4];
239239

240+
/* Validate input parameters */
241+
if (buf == NULL || len == 0) {
242+
return hal_status_badParam;
243+
}
244+
/* Bounds check: ensure write doesn't exceed FRAM size */
245+
if (addr >= FRAM_SIZE || (addr + len) > FRAM_SIZE) {
246+
return hal_status_badParam;
247+
}
248+
240249
#ifdef DEBUG_EXT_FLASH
241250
wolfBoot_printf("fram write: addr 0x%x, dst 0x%x, len %d\n",
242251
addr, buf, len);
@@ -259,6 +268,15 @@ hal_status_t FRAM_Read(uint8_t spiBank, uint32_t addr, uint8_t *buf,
259268
{
260269
uint8_t spiData[4];
261270

271+
/* Validate input parameters */
272+
if (buf == NULL || len == 0) {
273+
return hal_status_badParam;
274+
}
275+
/* Bounds check: ensure read doesn't exceed FRAM size */
276+
if (addr >= FRAM_SIZE || (addr + len) > FRAM_SIZE) {
277+
return hal_status_badParam;
278+
}
279+
262280
#ifdef DEBUG_EXT_FLASH
263281
wolfBoot_printf("fram read: addr 0x%x, dst 0x%x, len %d\n",
264282
addr, buf, len);
@@ -290,7 +308,7 @@ hal_status_t FRAM_Erase(uint8_t spiBank, uint32_t addr, uint32_t len)
290308
memset(data, FRAM_ERASE_VALUE, sizeof(data));
291309

292310
while (len > 0) {
293-
int erase_len = (len > (int)sizeof(data)) ? (int)sizeof(data) : len;
311+
uint32_t erase_len = (len > sizeof(data)) ? sizeof(data) : len;
294312
status = FRAM_Write(ROM_SPI_BANK, addr, data, erase_len);
295313
if (status != hal_status_ok) {
296314
return -(int)status; /* convert to negative error code */
@@ -333,14 +351,14 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
333351
#ifdef EXT_FLASH
334352
void ext_flash_lock(void)
335353
{
336-
/* Enable writes to code memory space */
337-
VOR_SYSCONFIG->ROM_PROT |= SYSCONFIG_ROM_PROT_WREN_Msk;
354+
/* Disable writes to code memory space */
355+
VOR_SYSCONFIG->ROM_PROT &= ~SYSCONFIG_ROM_PROT_WREN_Msk;
338356
}
339357

340358
void ext_flash_unlock(void)
341359
{
342-
/* Disable writes to code memory space */
343-
VOR_SYSCONFIG->ROM_PROT &= ~SYSCONFIG_ROM_PROT_WREN_Msk;
360+
/* Enable writes to code memory space */
361+
VOR_SYSCONFIG->ROM_PROT |= SYSCONFIG_ROM_PROT_WREN_Msk;
344362
}
345363

346364
int ext_flash_write(uintptr_t address, const uint8_t *data, int len)
@@ -480,12 +498,12 @@ void hal_init(void)
480498
}
481499

482500
/* Disable Watchdog - should be already disabled out of reset */
483-
VOR_WATCH_DOG->WDOGLOCK = 0x1ACCE551;
501+
VOR_WATCH_DOG->WDOGLOCK = WATCHDOG_UNLOCK_KEY;
484502
VOR_WATCH_DOG->WDOGCONTROL = 0x0;
485503
NVIC_ClearPendingIRQ(WATCHDOG_IRQn);
486504

487505
/* set FPU CP10 and CP11 Full Access */
488-
SCB->CPACR |= ((0x3 << 20)|(0x3 << 22));
506+
SCB->CPACR |= (CPACR_CP10_FULL_ACCESS | CPACR_CP11_FULL_ACCESS);
489507

490508
/* Init EDAC */
491509
ConfigEdac(WOLFBOOT_EDAC_RAM_SCRUB, WOLFBOOT_EDAC_ROM_SCRUB);

hal/va416x0.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
*/
2121

2222

23-
#ifndef VA416X0_DEF_INCLUDED
24-
#define VA416X0_DEF_INCLUDED
23+
#ifndef WOLFBOOT_HAL_VA416X0_H
24+
#define WOLFBOOT_HAL_VA416X0_H
2525

2626
#include <stdint.h>
2727
#include <stdbool.h>
@@ -108,4 +108,12 @@
108108
#endif
109109

110110

111-
#endif /* VA416X0_DEF_INCLUDED */
111+
/* Watchdog unlock key - required to modify watchdog registers */
112+
#define WATCHDOG_UNLOCK_KEY 0x1ACCE551
113+
114+
/* FPU Coprocessor Access Control - enable CP10 and CP11 full access */
115+
#define CPACR_CP10_FULL_ACCESS (0x3 << 20)
116+
#define CPACR_CP11_FULL_ACCESS (0x3 << 22)
117+
118+
119+
#endif /* WOLFBOOT_HAL_VA416X0_H */

0 commit comments

Comments
 (0)