improve sys interface for flash_erase_all_and_exec
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
2012-05-29 Niibe Yutaka <gniibe@fsij.org>
|
||||
|
||||
* 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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
31
src/sys.c
31
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 <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 "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,
|
||||
|
||||
@@ -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 (;;);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user