Reindentation of loadboot.cpp
This commit is contained in:
+94
-92
@@ -1,34 +1,34 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Copyright (c) 2014 by Michael Blandford. All rights reserved.
|
* Copyright (c) 2014 by Michael Blandford. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. Neither the name of the author nor the names of its contributors may
|
* 3. Neither the name of the author nor the names of its contributors may
|
||||||
* be used to endorse or promote products derived from this software
|
* be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
****************************************************************************
|
****************************************************************************
|
||||||
* Other Authors:
|
* Other Authors:
|
||||||
* - Andre Bernet
|
* - Andre Bernet
|
||||||
* - Bertrand Songis
|
* - Bertrand Songis
|
||||||
* - Bryan J. Rentoul (Gruvin)
|
* - Bryan J. Rentoul (Gruvin)
|
||||||
@@ -42,37 +42,35 @@
|
|||||||
* - Rob Thomson
|
* - Rob Thomson
|
||||||
* - Romolo Manfredini
|
* - Romolo Manfredini
|
||||||
* - Thomas Husterer
|
* - Thomas Husterer
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef PCBSKY
|
#ifdef PCBSKY
|
||||||
#include "AT91SAM3S4.h"
|
#include "AT91SAM3S4.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PCBTARANIS
|
#ifdef PCBTARANIS
|
||||||
#include "stm32f2xx.h"
|
#include "stm32f2xx.h"
|
||||||
#include "stm32f2xx_gpio.h"
|
#include "stm32f2xx_gpio.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PCBTARANIS)
|
#if defined(PCBTARANIS)
|
||||||
void bwdt_reset()
|
void bwdt_reset()
|
||||||
{
|
{
|
||||||
IWDG->KR = 0xAAAA ; // reload
|
IWDG->KR = 0xAAAA; // reload
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PCBTARANIS)
|
#if defined(PCBTARANIS)
|
||||||
|
|
||||||
__attribute__ ((section(".bootrodata"), used))
|
__attribute__ ((section(".bootrodata"), used))
|
||||||
void _bootStart( void ) ;
|
void _bootStart(void);
|
||||||
|
|
||||||
__attribute__ ((section(".isr_boot_vector"), used))
|
__attribute__ ((section(".isr_boot_vector"), used))
|
||||||
const uint32_t BootVectors[] = {
|
const uint32_t BootVectors[] = { (uint32_t) &_estack,
|
||||||
(uint32_t)&_estack,
|
(uint32_t) (void (*)(void)) ((unsigned long) &_bootStart) };
|
||||||
(uint32_t)(void (*)(void))((unsigned long)&_bootStart)
|
|
||||||
} ;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PCBTARANIS)
|
#if defined(PCBTARANIS)
|
||||||
@@ -85,8 +83,7 @@ __attribute__ ((section(".bootrodata"), used))
|
|||||||
|
|
||||||
const uint8_t BootCode[] = {
|
const uint8_t BootCode[] = {
|
||||||
#include "bootloader.lbm"
|
#include "bootloader.lbm"
|
||||||
} ;
|
};
|
||||||
|
|
||||||
|
|
||||||
#if defined(PCBTARANIS)
|
#if defined(PCBTARANIS)
|
||||||
|
|
||||||
@@ -94,61 +91,66 @@ __attribute__ ((section(".bootrodata"), used))
|
|||||||
|
|
||||||
void _bootStart()
|
void _bootStart()
|
||||||
{
|
{
|
||||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN ; // Enable portC clock
|
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN; // Enable portC clock
|
||||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN ; // Enable portE clock
|
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN; // Enable portE clock
|
||||||
|
|
||||||
GPIOC->PUPDR = 0x00000004 ;
|
|
||||||
GPIOE->PUPDR = 0x00000040 ;
|
|
||||||
|
|
||||||
uint32_t i ;
|
GPIOC->PUPDR = 0x00000004;
|
||||||
for ( i = 0 ; i < 50000 ; i += 1 )
|
GPIOE->PUPDR = 0x00000040;
|
||||||
{
|
|
||||||
bwdt_reset() ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( (GPIOE->IDR & 0x00000008 ) == 0 )
|
uint32_t i;
|
||||||
{
|
for (i = 0; i < 50000; i += 1) {
|
||||||
if ( (GPIOC->IDR & 0x00000002 ) == 0 )
|
bwdt_reset();
|
||||||
{
|
}
|
||||||
// Bootloader needed
|
|
||||||
const uint8_t *src ;
|
|
||||||
uint8_t *dest ;
|
|
||||||
uint32_t size ;
|
|
||||||
|
|
||||||
bwdt_reset() ;
|
if ((GPIOE->IDR & 0x00000008) == 0) {
|
||||||
size = sizeof(BootCode) ;
|
if ((GPIOC->IDR & 0x00000002) == 0) {
|
||||||
src = BootCode ;
|
// Bootloader needed
|
||||||
dest = (uint8_t *)0x20000000 ;
|
const uint8_t *src;
|
||||||
|
uint8_t *dest;
|
||||||
|
uint32_t size;
|
||||||
|
|
||||||
for ( ; size ; size -= 1 )
|
bwdt_reset();
|
||||||
{
|
size = sizeof(BootCode);
|
||||||
*dest++ = *src++ ;
|
src = BootCode;
|
||||||
}
|
dest = (uint8_t *) 0x20000000;
|
||||||
// Could check for a valid copy to RAM here
|
|
||||||
// Go execute bootloader
|
for (; size; size -= 1) {
|
||||||
bwdt_reset() ;
|
*dest++ = *src++;
|
||||||
|
}
|
||||||
uint32_t address = *(uint32_t *)0x20000004 ;
|
// Could check for a valid copy to RAM here
|
||||||
|
// Go execute bootloader
|
||||||
((void (*)(void)) (address))() ; // Go execute the loaded application
|
bwdt_reset();
|
||||||
|
|
||||||
}
|
uint32_t address = *(uint32_t *) 0x20000004;
|
||||||
}
|
|
||||||
|
((void (*)(void)) (address))(); // Go execute the loaded application
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
// run_application() ;
|
// run_application() ;
|
||||||
asm(" mov.w r1, #134217728"); // 0x8000000
|
asm(" mov.w r1, #134217728");
|
||||||
asm(" add.w r1, #32768"); // 0x8000
|
// 0x8000000
|
||||||
|
asm(" add.w r1, #32768");
|
||||||
asm(" movw r0, #60680"); // 0xED08
|
// 0x8000
|
||||||
asm(" movt r0, #57344"); // 0xE000
|
|
||||||
asm(" str r1, [r0, #0]"); // Set the VTOR
|
asm(" movw r0, #60680");
|
||||||
|
// 0xED08
|
||||||
asm("ldr r0, [r1, #0]"); // Stack pointer value
|
asm(" movt r0, #57344");
|
||||||
asm("msr msp, r0"); // Set it
|
// 0xE000
|
||||||
asm("ldr r0, [r1, #4]"); // Reset address
|
asm(" str r1, [r0, #0]");
|
||||||
|
// Set the VTOR
|
||||||
|
|
||||||
|
asm("ldr r0, [r1, #0]");
|
||||||
|
// Stack pointer value
|
||||||
|
asm("msr msp, r0");
|
||||||
|
// Set it
|
||||||
|
asm("ldr r0, [r1, #4]");
|
||||||
|
// Reset address
|
||||||
asm("mov.w r1, #1");
|
asm("mov.w r1, #1");
|
||||||
asm("orr r0, r1"); // Set lsbit
|
asm("orr r0, r1");
|
||||||
asm("bx r0"); // Execute application
|
// Set lsbit
|
||||||
|
asm("bx r0");
|
||||||
|
// Execute application
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user