MIFARE Plus 4b UID: fix signature check
[RRG-proxmark3.git] / armsrc / start.c
bloba5e385ae72f369f34a1c75b81a3019a9cc60bd99
1 //-----------------------------------------------------------------------------
2 // Copyright (C) Jonathan Westhues, Mar 2006
3 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // See LICENSE.txt for the text of the license.
16 //-----------------------------------------------------------------------------
17 // Just vector to AppMain(). This is in its own file so that I can place it
18 // with the linker script.
19 //-----------------------------------------------------------------------------
21 #ifndef __START_H
22 #define __START_H
24 #include "proxmark3_arm.h"
25 #include "appmain.h"
26 #ifdef WITH_COMPRESSION
27 #include "lz4.h"
28 #endif
29 #include "BigBuf.h"
30 #include "string.h"
31 #include "ticks.h"
33 extern common_area_t g_common_area;
34 extern uint32_t __data_src_start__[], __data_start__[], __data_end__[], __bss_start__[], __bss_end__[];
36 #ifdef WITH_COMPRESSION
37 static void uncompress_data_section(void) {
38 int avail_in;
39 memcpy(&avail_in, __data_src_start__, sizeof(int));
40 int avail_out = (uint32_t)__data_end__ - (uint32_t)__data_start__; // uncompressed size. Correct.
41 // uncompress data segment to RAM
42 char *p = (char *)__data_src_start__;
43 int res = LZ4_decompress_safe(p + 4, (char *)__data_start__, avail_in, avail_out);
44 if (res < 0) {
45 while (true) {
46 LED_A_INV();
47 LED_B_INV();
48 LED_C_INV();
49 LED_D_INV();
50 SpinDelay(200);
53 // save the size of the compressed data section
54 g_common_area.arg1 = avail_in;
56 #endif
58 void __attribute__((section(".startos"))) Vector(void);
59 void Vector(void) {
60 /* Stack should have been set up by the bootloader */
62 if (g_common_area.magic != COMMON_AREA_MAGIC || g_common_area.version != 1) {
63 /* Initialize common area */
64 memset(&g_common_area, 0, sizeof(g_common_area));
65 g_common_area.magic = COMMON_AREA_MAGIC;
66 g_common_area.version = 1;
68 g_common_area.flags.osimage_present = 1;
70 /* Set up data segment: Copy from flash to ram */
71 #ifndef WITH_COMPRESSION
72 uint32_t *data_src = __data_src_start__;
73 uint32_t *data_dst = __data_start__;
74 while (data_dst < __data_end__) *data_dst++ = *data_src++;
75 #else
76 uncompress_data_section();
77 #endif
79 /* Set up (that is: clear) BSS. */
80 uint32_t *bss_dst = __bss_start__;
81 while (bss_dst < __bss_end__) *bss_dst++ = 0;
83 AppMain();
85 #endif