2019-07-25 22:41:08 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved.
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup cpu_arm7_common
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Common ARM7 boot up code
|
|
|
|
*
|
|
|
|
* @author Heiko Will <hwill@inf.fu-berlin.de>
|
|
|
|
* @author Michael Baar <michael.baar@fu-berlin.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "thread.h"
|
2019-11-25 01:34:38 +01:00
|
|
|
#ifdef MODULE_PUF_SRAM
|
|
|
|
#include "puf_sram.h"
|
|
|
|
#endif
|
2019-07-25 22:41:08 +02:00
|
|
|
|
2019-11-09 23:56:29 +01:00
|
|
|
#include "cpu.h"
|
2019-07-25 22:41:08 +02:00
|
|
|
#include "log.h"
|
|
|
|
|
2019-11-16 01:40:01 +01:00
|
|
|
static inline void _init_data(void)
|
2019-07-25 22:41:08 +02:00
|
|
|
{
|
2019-11-16 01:40:01 +01:00
|
|
|
/* (linker script ensures that data is 32-bit aligned) */
|
2019-07-25 22:41:08 +02:00
|
|
|
extern unsigned int _etext;
|
|
|
|
extern unsigned int _data;
|
|
|
|
extern unsigned int _edata;
|
|
|
|
extern unsigned int __bss_start;
|
|
|
|
extern unsigned int __bss_end;
|
|
|
|
|
2019-11-16 01:40:01 +01:00
|
|
|
/* Support for Battery Backup RAM */
|
2019-11-09 23:56:29 +01:00
|
|
|
#ifdef CPU_HAS_BACKUP_RAM
|
|
|
|
extern unsigned int _sbackup_data_load[];
|
|
|
|
extern unsigned int _sbackup_data[];
|
|
|
|
extern unsigned int _ebackup_data[];
|
|
|
|
extern unsigned int _sbackup_bss[];
|
|
|
|
extern unsigned int _ebackup_bss[];
|
2019-11-16 01:40:01 +01:00
|
|
|
#endif
|
2019-11-09 23:56:29 +01:00
|
|
|
|
2019-11-16 01:40:01 +01:00
|
|
|
register unsigned int *src;
|
|
|
|
register unsigned int *dst;
|
|
|
|
register unsigned int *end;
|
2019-07-25 22:41:08 +02:00
|
|
|
|
2019-11-16 01:40:01 +01:00
|
|
|
/* initialize data from flash */
|
|
|
|
src = &_etext;
|
|
|
|
dst = &_data;
|
|
|
|
end = &_edata;
|
2019-07-25 22:41:08 +02:00
|
|
|
|
2019-11-16 01:40:01 +01:00
|
|
|
while (dst < end) {
|
|
|
|
*dst++ = *src++;
|
2019-07-25 22:41:08 +02:00
|
|
|
}
|
|
|
|
|
2019-11-16 01:40:01 +01:00
|
|
|
/* clear bss */
|
|
|
|
dst = &__bss_start;
|
|
|
|
end = &__bss_end;
|
2019-07-25 22:41:08 +02:00
|
|
|
|
2019-11-16 01:40:01 +01:00
|
|
|
while (dst < end) {
|
|
|
|
*dst++ = 0;
|
2019-07-25 22:41:08 +02:00
|
|
|
}
|
2019-11-09 23:56:29 +01:00
|
|
|
|
|
|
|
#ifdef CPU_HAS_BACKUP_RAM
|
2019-11-16 01:40:01 +01:00
|
|
|
/* only initialize battery backup on cold boot */
|
2019-11-09 23:56:29 +01:00
|
|
|
if (cpu_woke_from_backup()) {
|
2019-11-16 01:40:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load low-power data section. */
|
|
|
|
src = _sbackup_data_load;
|
|
|
|
dst = _sbackup_data;
|
|
|
|
end = _ebackup_data;
|
|
|
|
|
|
|
|
while (dst < end) {
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* zero-out low-power bss. */
|
|
|
|
dst = _sbackup_bss;
|
|
|
|
end = _ebackup_bss;
|
2019-11-09 23:56:29 +01:00
|
|
|
|
2019-11-16 01:40:01 +01:00
|
|
|
while (dst < end) {
|
|
|
|
*dst++ = 0;
|
2019-11-09 23:56:29 +01:00
|
|
|
}
|
|
|
|
#endif /* CPU_HAS_BACKUP_RAM */
|
2019-07-25 22:41:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void bootloader(void)
|
|
|
|
{
|
2019-09-14 14:49:48 +02:00
|
|
|
extern void cpu_init(void);
|
2019-07-25 22:41:08 +02:00
|
|
|
|
|
|
|
/* initialize bss and data */
|
|
|
|
_init_data();
|
|
|
|
|
2019-11-25 01:34:38 +01:00
|
|
|
#ifdef MODULE_PUF_SRAM
|
|
|
|
/* uninitialized heap starts after bss section */
|
|
|
|
extern unsigned int __bss_end;
|
|
|
|
puf_sram_init((uint8_t *) __bss_end, SEED_RAM_LEN);
|
|
|
|
#endif
|
|
|
|
|
2019-09-14 14:49:48 +02:00
|
|
|
/* cpu specific setup of clocks, peripherals */
|
|
|
|
cpu_init();
|
2019-07-25 22:41:08 +02:00
|
|
|
|
|
|
|
#ifdef MODULE_NEWLIB
|
|
|
|
extern void __libc_init_array(void);
|
|
|
|
__libc_init_array();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @} */
|