parent
353095ae95
commit
c4c571d837
@ -1,19 +0,0 @@
|
||||
#ifndef BOOT_INTERNAL_H
|
||||
#define BOOT_INTERNAL_H
|
||||
|
||||
#include <boot_args.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// The 'g_boot_command' variable stores the 'command' passed to the
|
||||
// function 'svc_reboot_to_bootloader()'. It may be one of the
|
||||
// 'BOOT_COMMAND_xxx' values defined in the enumeration, or it could
|
||||
// be any other value that should be treated as a non-special action,
|
||||
// in which case the bootloader should behave as if the device was
|
||||
// just powered up. The variable is set before the main() is called.
|
||||
extern boot_command_t g_boot_command;
|
||||
|
||||
// The 'g_boot_args' array stores extra arguments passed
|
||||
// function 'svc_reboot_to_bootloader()'
|
||||
extern uint8_t g_boot_args[BOOT_ARGS_SIZE];
|
||||
|
||||
#endif // BOOT_INTERNAL_H
|
@ -0,0 +1,44 @@
|
||||
|
||||
#include "../boot_args.h"
|
||||
#include <common.h>
|
||||
#include <string.h>
|
||||
|
||||
// The 'g_boot_command_shadow' shadows a real boot command passed
|
||||
// to the bootloader.
|
||||
// 1. In the bootloader, its value is set in the startup code.
|
||||
// 2. In the firmware it holds command for the next boot and it is used
|
||||
// when svc_reboot_to_bootloader() is called
|
||||
boot_command_t g_boot_command_shadow;
|
||||
|
||||
#ifdef STM32U5
|
||||
// The 'g_boot_command' is persistent variable that holds the 'command'
|
||||
// for the next reboot/jump to the bootloader. Its value is set to
|
||||
// g_boot_command_shadow when 'svc_reboot_to_bootloader()' is called.
|
||||
boot_command_t __attribute__((section(".boot_command"))) g_boot_command;
|
||||
#endif
|
||||
|
||||
// The 'g_boot_args' is persistent array that stores extra arguments passed
|
||||
// to the function bootargs_set.
|
||||
static boot_args_t __attribute__((section(".boot_args"))) g_boot_args;
|
||||
|
||||
void bootargs_set(boot_command_t command, const void* args, size_t args_size) {
|
||||
// save boot command
|
||||
g_boot_command_shadow = command;
|
||||
|
||||
size_t copy_size = 0;
|
||||
// copy arguments up to BOOT_ARGS_MAX_SIZE
|
||||
if (args != NULL && args_size > 0) {
|
||||
copy_size = MIN(args_size, BOOT_ARGS_MAX_SIZE);
|
||||
memcpy(&g_boot_args.raw[0], args, copy_size);
|
||||
}
|
||||
|
||||
// clear rest of boot_args array
|
||||
size_t clear_size = BOOT_ARGS_MAX_SIZE - copy_size;
|
||||
if (clear_size > 0) {
|
||||
memset(&g_boot_args.raw[copy_size], 0, clear_size);
|
||||
}
|
||||
}
|
||||
|
||||
boot_command_t bootargs_get_command() { return g_boot_command_shadow; }
|
||||
|
||||
const boot_args_t* bootargs_get_args() { return &g_boot_args; }
|
@ -0,0 +1 @@
|
||||
../stm32f4/boot_args.c
|
@ -0,0 +1,44 @@
|
||||
|
||||
#include "../boot_args.h"
|
||||
#include <common.h>
|
||||
#include <string.h>
|
||||
|
||||
// The 'g_boot_command_shadow' variable stores the 'command' for the next
|
||||
// reboot/jumping to the bootloadeer. It may be one of the
|
||||
// 'BOOT_COMMAND_xxx' values defined in the enumeration, or it could
|
||||
// be any other value that should be treated as a non-special action,
|
||||
// in which case the bootloader should behave as if the device was
|
||||
// just powered up.
|
||||
|
||||
static boot_command_t g_boot_command_shadow;
|
||||
|
||||
// The 'g_boot_args' array stores extra arguments passed
|
||||
// function boot_args. It sits at section that persists jump to the bootloader.
|
||||
static boot_args_t g_boot_args;
|
||||
|
||||
void bootargs_set(boot_command_t command, const void* args, size_t args_size) {
|
||||
// save boot command
|
||||
g_boot_command_shadow = command;
|
||||
|
||||
size_t copy_size = 0;
|
||||
// copy arguments up to BOOT_ARGS_MAX_SIZE
|
||||
if (args != NULL && args_size > 0) {
|
||||
copy_size = MIN(args_size, BOOT_ARGS_MAX_SIZE);
|
||||
memcpy(&g_boot_args.raw[0], args, copy_size);
|
||||
}
|
||||
|
||||
// clear rest of boot_args array
|
||||
size_t clear_size = BOOT_ARGS_MAX_SIZE - copy_size;
|
||||
if (clear_size > 0) {
|
||||
memset(&g_boot_args.raw[copy_size], 0, clear_size);
|
||||
}
|
||||
}
|
||||
|
||||
void bootargs_clear() {
|
||||
g_boot_command_shadow = BOOT_COMMAND_NONE;
|
||||
memset(&g_boot_args, 0, sizeof(g_boot_args));
|
||||
}
|
||||
|
||||
boot_command_t bootargs_get_command() { return g_boot_command_shadow; }
|
||||
|
||||
const boot_args_t* bootargs_get_args() { return &g_boot_args; }
|
Loading…
Reference in new issue