improve sys interface for flash_erase_all_and_exec

This commit is contained in:
NIIBE Yutaka
2012-05-29 09:41:25 +09:00
parent e2ab8c9183
commit 08563d5a65
5 changed files with 37 additions and 10 deletions

View File

@@ -1,6 +1,11 @@
2012-05-29 Niibe Yutaka <gniibe@fsij.org> 2012-05-29 Niibe Yutaka <gniibe@fsij.org>
* src/sys.c (reset): Don't depend if DFU_SUPPORT or not. * src/sys.c (reset): Don't depend if DFU_SUPPORT or not.
(flash_erase_all_and_exec): Rename and change the argument.
* src/gnuk.ld.in (__flash_start__): Real flash ROM address,
regardless of DFU_SUPPORT.
* src/main.c (main): Call flash_erase_all_and_exec with SRAM
address.
* polarssl-0.14.0/library/aes.c (FT0, FT1, FT2): Specify sections * polarssl-0.14.0/library/aes.c (FT0, FT1, FT2): Specify sections
in detail, so that addresses won't be affected by compiler. in detail, so that addresses won't be affected by compiler.

View File

@@ -38,7 +38,8 @@ MEMORY
ram : org = 0x20000000, len = 20k ram : org = 0x20000000, len = 20k
} }
__flash_start__ = ORIGIN(flash); /* __flash_start__: flash ROM start address regardless of DFU_SUPPORT */
__flash_start__ = 0x08001000;
__flash_end__ = ORIGIN(flash) + LENGTH(flash); __flash_end__ = ORIGIN(flash) + LENGTH(flash);
__ram_start__ = ORIGIN(ram); __ram_start__ = ORIGIN(ram);

View File

@@ -484,7 +484,7 @@ main (int argc, char *argv[])
/* Set vector */ /* Set vector */
SCB->VTOR = (uint32_t)&_regnual_start; SCB->VTOR = (uint32_t)&_regnual_start;
/* Leave Gnuk */ /* Leave Gnuk */
flash_mass_erase_and_exec (); flash_erase_all_and_exec (*((void (**)(void))(&_regnual_start+4)));
/* Never reached */ /* Never reached */
return 0; return 0;

View File

@@ -1,10 +1,32 @@
/*
* sys.c - system services at the first flash ROM blocks
*
* Copyright (C) 2012 Free Software Initiative of Japan
* Author: NIIBE Yutaka <gniibe@fsij.org>
*
* This file is a part of Gnuk, a GnuPG USB Token implementation.
*
* Gnuk is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Gnuk is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ch.h" #include "ch.h"
#include "hal.h" #include "hal.h"
#include "board.h" #include "board.h"
#include "usb_lld.h" #include "usb_lld.h"
extern uint8_t __flash_start__, __flash_end__; extern uint8_t __flash_start__, __flash_end__;
extern uint8_t _regnual_start;
static const uint8_t * static const uint8_t *
@@ -184,9 +206,8 @@ flash_protect (void)
static void __attribute__((naked)) static void __attribute__((naked))
flash_mass_erase_and_exec (void) flash_erase_all_and_exec (void (*entry)(void))
{ {
void (**func )(void) = (void (**)(void))(&_regnual_start + 4);
uint32_t addr = (uint32_t)&__flash_start__; uint32_t addr = (uint32_t)&__flash_start__;
uint32_t end = (uint32_t)&__flash_end__; uint32_t end = (uint32_t)&__flash_end__;
int r; int r;
@@ -201,7 +222,7 @@ flash_mass_erase_and_exec (void)
} }
if (addr >= end) if (addr >= end)
(**func) (); (*entry) ();
for (;;); for (;;);
} }
@@ -281,7 +302,7 @@ handler vector[] __attribute__ ((section(".vectors"))) = {
(handler)flash_check_blank, (handler)flash_check_blank,
(handler)flash_write, (handler)flash_write,
(handler)flash_protect, (handler)flash_protect,
(handler)flash_mass_erase_and_exec, (handler)flash_erase_all_and_exec,
usb_lld_sys_init, usb_lld_sys_init,
usb_lld_sys_shutdown, usb_lld_sys_shutdown,
nvic_system_reset, nvic_system_reset,

View File

@@ -65,11 +65,11 @@ flash_protect (void)
} }
static inline void __attribute__((noreturn)) static inline void __attribute__((noreturn))
flash_mass_erase_and_exec (void) flash_erase_all_and_exec (void (*entry)(void))
{ {
void (*func) (void) = (void (*)(void))vector[10]; void (*func) (void (*)(void)) = (void (*)(void (*)(void)))vector[10];
(*func) (); (*func) (entry);
for (;;); for (;;);
} }