From 08563d5a65f695a6b7b9a67bcf720a843f82817e Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Tue, 29 May 2012 09:41:25 +0900 Subject: [PATCH] improve sys interface for flash_erase_all_and_exec --- ChangeLog | 5 +++++ src/gnuk.ld.in | 3 ++- src/main.c | 2 +- src/sys.c | 31 ++++++++++++++++++++++++++----- src/sys.h | 6 +++--- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4afe3f3..730b58e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ 2012-05-29 Niibe Yutaka * 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 in detail, so that addresses won't be affected by compiler. diff --git a/src/gnuk.ld.in b/src/gnuk.ld.in index b9ff5f9..3d4f675 100644 --- a/src/gnuk.ld.in +++ b/src/gnuk.ld.in @@ -38,7 +38,8 @@ MEMORY 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); __ram_start__ = ORIGIN(ram); diff --git a/src/main.c b/src/main.c index 6e56d87..aa1344b 100644 --- a/src/main.c +++ b/src/main.c @@ -484,7 +484,7 @@ main (int argc, char *argv[]) /* Set vector */ SCB->VTOR = (uint32_t)&_regnual_start; /* Leave Gnuk */ - flash_mass_erase_and_exec (); + flash_erase_all_and_exec (*((void (**)(void))(&_regnual_start+4))); /* Never reached */ return 0; diff --git a/src/sys.c b/src/sys.c index 2e6e98e..f69d0c2 100644 --- a/src/sys.c +++ b/src/sys.c @@ -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 + * + * 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 . + * + */ + #include "ch.h" #include "hal.h" #include "board.h" #include "usb_lld.h" extern uint8_t __flash_start__, __flash_end__; -extern uint8_t _regnual_start; static const uint8_t * @@ -184,9 +206,8 @@ flash_protect (void) 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 end = (uint32_t)&__flash_end__; int r; @@ -201,7 +222,7 @@ flash_mass_erase_and_exec (void) } if (addr >= end) - (**func) (); + (*entry) (); for (;;); } @@ -281,7 +302,7 @@ handler vector[] __attribute__ ((section(".vectors"))) = { (handler)flash_check_blank, (handler)flash_write, (handler)flash_protect, - (handler)flash_mass_erase_and_exec, + (handler)flash_erase_all_and_exec, usb_lld_sys_init, usb_lld_sys_shutdown, nvic_system_reset, diff --git a/src/sys.h b/src/sys.h index 609aec0..4a3d89b 100644 --- a/src/sys.h +++ b/src/sys.h @@ -65,11 +65,11 @@ flash_protect (void) } 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 (;;); }