2014-08-27 18:47:31 +02:00
|
|
|
/*
|
2013-08-16 10:20:23 +02:00
|
|
|
* Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved.
|
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* 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.
|
2014-08-27 18:47:31 +02:00
|
|
|
*/
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
/**
|
2015-07-06 01:11:48 +02:00
|
|
|
* @ingroup cpu_arm7_common
|
2010-09-22 15:10:42 +02:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @internal
|
|
|
|
* @brief ARM bootloader
|
|
|
|
*
|
|
|
|
* @author Heiko Will <hwill@inf.fu-berlin.de>
|
|
|
|
* @author Michael Baar <michael.baar@fu-berlin.de>
|
|
|
|
* @version $Revision$
|
|
|
|
* @since 19.08.2008
|
|
|
|
*
|
|
|
|
* @note $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "thread.h"
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
void FIQ_Routine(void) __attribute__((interrupt("FIQ")));
|
2013-06-24 22:37:35 +02:00
|
|
|
//void SWI_Routine (void) __attribute__((interrupt("SWI")));
|
2013-06-21 03:52:57 +02:00
|
|
|
void UNDEF_Routine(void) __attribute__((interrupt("UNDEF")));
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
void IRQ_Routine(void)
|
|
|
|
{
|
2010-09-22 15:10:42 +02:00
|
|
|
printf("Kernel Panic,\nEarly IRQ call\n");
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
while (1) {};
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2013-06-21 03:52:57 +02:00
|
|
|
void FIQ_Routine(void)
|
|
|
|
{
|
2010-09-22 15:10:42 +02:00
|
|
|
printf("Kernel Panic,\nEarly FIQ call\n");
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
while (1) {};
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2013-06-21 03:52:57 +02:00
|
|
|
void SWI_Routine(void)
|
|
|
|
{
|
2010-09-22 15:10:42 +02:00
|
|
|
printf("Kernel Panic,\nEarly SWI call\n");
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
while (1) {};
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2013-06-21 03:52:57 +02:00
|
|
|
void DEBUG_Routine(void)
|
|
|
|
{
|
2010-09-22 15:10:42 +02:00
|
|
|
printf("DEBUG hit.");
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
while (1) {};
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
volatile int arm_abortflag = 0;
|
|
|
|
|
2016-12-13 13:26:37 +01:00
|
|
|
void abtorigin(const char *vector, unsigned long *lnk_ptr1)
|
2010-09-22 15:10:42 +02:00
|
|
|
{
|
2016-12-13 13:26:37 +01:00
|
|
|
register unsigned long *lnk_ptr2;
|
2013-06-21 03:52:57 +02:00
|
|
|
register unsigned long *sp;
|
2010-09-22 15:10:42 +02:00
|
|
|
register unsigned int cpsr, spsr;
|
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
__asm__ __volatile__("mrs %0, cpsr" : "=r"(cpsr)); // copy current mode
|
|
|
|
__asm__ __volatile__("mrs %0, spsr" : "=r"(spsr)); // copy dabt generating mode
|
|
|
|
__asm__ __volatile__("msr cpsr_c, %0" :: "r"(spsr)); // switch to dabt generating mode
|
|
|
|
__asm__ __volatile__("mov %0, lr" : "=r"(lnk_ptr2)); // copy lr
|
|
|
|
__asm__ __volatile__("mov %0, sp" : "=r"(sp)); // copy sp
|
|
|
|
__asm__ __volatile__("msr cpsr_c, %0" :: "r"(cpsr)); // switch back to abt mode
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
printf("#!%s abort at %p (0x%08lX) originating from %p (0x%08lX) in mode 0x%X\n",
|
2013-06-21 03:52:57 +02:00
|
|
|
vector, (void *)lnk_ptr1, *(lnk_ptr1), (void *)lnk_ptr2, *(lnk_ptr2), spsr
|
|
|
|
);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2013-06-21 03:52:57 +02:00
|
|
|
void UNDEF_Routine(void)
|
|
|
|
{
|
2014-09-12 15:46:17 +02:00
|
|
|
/* cppcheck-suppress variableScope */
|
2016-12-13 13:26:37 +01:00
|
|
|
register unsigned long *lnk_ptr;
|
2013-06-21 03:52:57 +02:00
|
|
|
__asm__ __volatile__("sub %0, lr, #8" : "=r"(lnk_ptr)); // get aborting instruction
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
if (arm_abortflag == 0) {
|
2010-09-22 15:10:42 +02:00
|
|
|
arm_abortflag = 1; // remember state (if printing should fail again)
|
|
|
|
abtorigin("undef", lnk_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2013-06-21 03:52:57 +02:00
|
|
|
void PABT_Routine(void)
|
|
|
|
{
|
2014-09-12 15:46:17 +02:00
|
|
|
/* cppcheck-suppress variableScope */
|
2016-12-13 13:26:37 +01:00
|
|
|
register unsigned long *lnk_ptr;
|
2013-06-21 03:52:57 +02:00
|
|
|
__asm__ __volatile__("sub %0, lr, #8" : "=r"(lnk_ptr)); // get aborting instruction
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
if (arm_abortflag == 0) {
|
2010-09-22 15:10:42 +02:00
|
|
|
arm_abortflag = 1; // remember state (if printing should fail again)
|
|
|
|
abtorigin("pabt", lnk_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2013-06-21 03:52:57 +02:00
|
|
|
void DABT_Routine(void)
|
|
|
|
{
|
2014-09-12 15:46:17 +02:00
|
|
|
/* cppcheck-suppress variableScope */
|
2016-12-13 13:26:37 +01:00
|
|
|
register unsigned long *lnk_ptr;
|
2013-06-21 03:52:57 +02:00
|
|
|
__asm__ __volatile__("sub %0, lr, #8" : "=r"(lnk_ptr)); // get aborting instruction
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
if (arm_abortflag == 0) {
|
2010-09-22 15:10:42 +02:00
|
|
|
arm_abortflag = 1; // remember state (if printing should fail again)
|
|
|
|
abtorigin("data", lnk_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
static inline void
|
|
|
|
bl_init_data(void)
|
|
|
|
{
|
|
|
|
extern unsigned int _etext;
|
|
|
|
extern unsigned int _data;
|
|
|
|
extern unsigned int _edata;
|
|
|
|
extern unsigned int __bss_start;
|
|
|
|
extern unsigned int __bss_end;
|
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
register unsigned int *p1;
|
|
|
|
register unsigned int *p2;
|
|
|
|
register unsigned int *p3;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
// initialize data from flash
|
|
|
|
// (linker script ensures that data is 32-bit aligned)
|
|
|
|
p1 = &_etext;
|
|
|
|
p2 = &_data;
|
|
|
|
p3 = &_edata;
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
while (p2 < p3) {
|
2010-09-22 15:10:42 +02:00
|
|
|
*p2++ = *p1++;
|
2013-06-21 03:52:57 +02:00
|
|
|
}
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
// clear bss
|
|
|
|
// (linker script ensures that bss is 32-bit aligned)
|
|
|
|
p1 = &__bss_start;
|
|
|
|
p2 = &__bss_end;
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
while (p1 < p2) {
|
2010-09-22 15:10:42 +02:00
|
|
|
*p1++ = 0;
|
2013-06-21 03:52:57 +02:00
|
|
|
}
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2013-06-21 03:52:57 +02:00
|
|
|
void bootloader(void)
|
|
|
|
{
|
2010-09-22 15:10:42 +02:00
|
|
|
extern void bl_uart_init(void);
|
|
|
|
extern void bl_init_ports(void);
|
|
|
|
extern void bl_init_clks(void);
|
|
|
|
extern void bl_blink(void);
|
2010-12-01 16:26:48 +01:00
|
|
|
extern void bl_config_init(void);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
/* board specific setup of clocks */
|
|
|
|
bl_init_clks();
|
2010-12-06 16:12:58 +01:00
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
/* initialize bss and data */
|
2013-12-19 15:25:12 +01:00
|
|
|
#ifndef CPU_MC1322X
|
2010-09-22 15:10:42 +02:00
|
|
|
bl_init_data();
|
2013-10-17 13:28:52 +02:00
|
|
|
#endif
|
2010-12-06 16:12:58 +01:00
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
/* board specific setup of i/o pins */
|
|
|
|
bl_init_ports();
|
2010-12-06 16:12:58 +01:00
|
|
|
|
2015-06-04 13:47:46 +02:00
|
|
|
#ifdef MODULE_NEWLIB
|
|
|
|
extern void __libc_init_array(void);
|
|
|
|
__libc_init_array();
|
|
|
|
#endif
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @} */
|