proxmark3/armsrc/start.c
Philippe Teuwen e750481d12 Fix multiple issues with reported flash memory usage:
- Remove unused next_free_memory=BigBuf_get_addr()
- Fix size retrieval of compressed data section
  by chance the corrupted value was > than correct value so
  decompression was taking place, but was returning an error
  instead of the decompressed size
- Fix reporting of compressed size into common_area
  returned value of LZ4_decompress_safe is the decompressed size
  while we needed to report the compressed size
- Fix common_area late initialization
  common_area was initialized (and zeroed) after
  uncompress_data_section() had reported the compressed size
  in common_area, so compressed size was erased

Compressed size is used in the computation of the used and available
flash memory, which is now correct
(it was wrongly telling about 6kb were free while they weren't).
2020-11-05 00:59:32 +01:00

60 lines
1.9 KiB
C

//-----------------------------------------------------------------------------
// 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"
#include "lz4.h"
#include "BigBuf.h"
#include "string.h"
extern struct common_area common_area;
extern char __data_src_start__, __data_start__, __data_end__, __bss_start__, __bss_end__;
static void uncompress_data_section(void) {
int avail_in;
memcpy(&avail_in, &__data_src_start__, sizeof(int));
int avail_out = &__data_end__ - &__data_start__; // uncompressed size. Correct.
// uncompress data segment to RAM
uintptr_t p = (uintptr_t)&__data_src_start__;
int res = LZ4_decompress_safe((char *)p + 4, &__data_start__, avail_in, avail_out);
if (res < 0)
return;
// save the size of the compressed data section
common_area.arg1 = avail_in;
}
void __attribute__((section(".startos"))) Vector(void);
void Vector(void) {
/* 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;
uncompress_data_section();
/* Set up (that is: clear) BSS. */
char *dst = &__bss_start__;
char *end = &__bss_end__;
while (dst < end) *dst++ = 0;
AppMain();
}
#endif