proxmark3/armsrc/start.c

70 lines
2.2 KiB
C
Raw Normal View History

//-----------------------------------------------------------------------------
// Jonathan Westhues, Mar 2006
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Just vector to AppMain(). This is in its own file so that I can place it
// with the linker script.
//-----------------------------------------------------------------------------
#ifndef __START_H
#define __START_H
#include "proxmark3_arm.h"
#include "appmain.h"
#ifndef WITH_NO_COMPRESSION
2020-06-05 22:24:05 +08:00
#include "lz4.h"
#endif
2015-06-25 18:22:34 +08:00
#include "BigBuf.h"
2020-06-07 18:46:05 +08:00
#include "string.h"
2015-06-25 18:22:34 +08:00
extern struct common_area common_area;
extern uint32_t __data_src_start__[], __data_start__[], __data_end__[], __bss_start__[], __bss_end__[];
2015-06-25 18:22:34 +08:00
#ifndef WITH_NO_COMPRESSION
static void uncompress_data_section(void) {
2020-06-07 18:46:05 +08:00
int avail_in;
memcpy(&avail_in, __data_src_start__, sizeof(int));
int avail_out = (uint32_t)__data_end__ - (uint32_t)__data_start__; // uncompressed size. Correct.
2020-06-05 22:24:05 +08:00
// uncompress data segment to RAM
char *p = (char *)__data_src_start__;
int res = LZ4_decompress_safe(p + 4, (char *)__data_start__, avail_in, avail_out);
2015-06-25 18:22:34 +08:00
2019-04-10 15:32:40 +08:00
if (res < 0)
return;
2019-03-10 03:34:41 +08:00
// save the size of the compressed data section
common_area.arg1 = avail_in;
2015-06-25 18:22:34 +08:00
}
#endif
2015-06-25 18:22:34 +08:00
2020-05-10 22:59:38 +08:00
void __attribute__((section(".startos"))) Vector(void);
void Vector(void) {
2019-03-10 03:34:41 +08:00
/* Stack should have been set up by the bootloader */
if (common_area.magic != COMMON_AREA_MAGIC || common_area.version != 1) {
/* Initialize common area */
memset(&common_area, 0, sizeof(common_area));
common_area.magic = COMMON_AREA_MAGIC;
common_area.version = 1;
}
common_area.flags.osimage_present = 1;
2020-12-30 08:31:40 +08:00
/* Set up data segment: Copy from flash to ram */
2020-12-30 08:36:44 +08:00
#ifdef WITH_NO_COMPRESSION
uint32_t *data_src = __data_src_start__;
uint32_t *data_dst = __data_start__;
while (data_dst < __data_end__) *data_dst++ = *data_src++;
#else
2020-12-30 08:31:40 +08:00
uncompress_data_section();
#endif
2020-12-30 08:31:40 +08:00
2020-12-30 08:36:44 +08:00
/* Set up (that is: clear) BSS. */
uint32_t *bss_dst = __bss_start__;
while (bss_dst < __bss_end__) *bss_dst++ = 0;
2019-03-10 03:34:41 +08:00
AppMain();
}
2019-03-12 07:12:26 +08:00
#endif