diff --git a/armsrc/BigBuf.c b/armsrc/BigBuf.c index e84433a98..31ecb4329 100644 --- a/armsrc/BigBuf.c +++ b/armsrc/BigBuf.c @@ -14,12 +14,12 @@ #include "dbprint.h" #include "pm3_cmd.h" -extern uint8_t _stack_start, __bss_end__; +extern char _stack_start[], __bss_end__[]; // BigBuf is the large multi-purpose buffer, typically used to hold A/D samples or traces. // Also used to hold various smaller buffers and the Mifare Emulator Memory. // We know that bss is aligned to 4 bytes. -static uint8_t *BigBuf = &__bss_end__; +static uint8_t *BigBuf = (uint8_t *)__bss_end__; /* BigBuf memory layout: Pointer to highest available memory: s_bigbuf_hi @@ -69,7 +69,7 @@ static bool tracing = true; // compute the available size for BigBuf void BigBuf_initialize(void) { - s_bigbuf_size = (uint32_t)&_stack_start - (uint32_t)&__bss_end__; + s_bigbuf_size = (uint32_t)_stack_start - (uint32_t)__bss_end__; s_bigbuf_hi = s_bigbuf_size; trace_len = 0; } diff --git a/armsrc/appmain.c b/armsrc/appmain.c index f0402de1f..36b7b1768 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -70,7 +70,7 @@ int DBGLEVEL = DBG_ERROR; uint8_t g_trigger = 0; bool g_hf_field_active = false; -extern uint32_t _stack_start, _stack_end; +extern char _stack_start[], _stack_end[]; struct common_area common_area __attribute__((section(".commonarea"))); static int button_status = BUTTON_NO_CLICK; static bool allow_send_wtx = false; @@ -240,10 +240,9 @@ static uint32_t MeasureAntennaTuningLfData(void) { } void print_stack_usage(void) { - // pointer arithmetic is times 4. (two shifts to the left) - for (uint32_t *p = &_stack_start; ; ++p) { + for (uint32_t *p = (uint32_t *)_stack_start; ; ++p) { if (*p != 0xdeadbeef) { - Dbprintf(" Max stack usage......... %d / %d bytes", (&_stack_end - p) << 2, (&_stack_end - &_stack_start) << 2); + Dbprintf(" Max stack usage......... %d / %d bytes", _stack_end - (char *)p, _stack_end - _stack_start); break; } } @@ -257,9 +256,9 @@ void ReadMem(int addr) { /* osimage version information is linked in, cf commonutil.h */ /* bootrom version information is pointed to from _bootphase1_version_pointer */ -extern char *_bootphase1_version_pointer, _flash_start, _flash_end, __data_src_start__; +extern char _bootphase1_version_pointer[], _flash_start[], _flash_end[], __data_src_start__[]; #ifdef WITH_NO_COMPRESSION -extern char *_bootrom_end, _bootrom_start, __os_size__; +extern char _bootrom_end[], _bootrom_start[], __os_size__[]; #endif static void SendVersion(void) { char temp[PM3_CMD_DATA_SIZE - 12]; /* Limited data payload in USB packets */ @@ -269,11 +268,11 @@ static void SendVersion(void) { * symbol _bootphase1_version_pointer, perform slight sanity checks on the * pointer, then use it. */ - char *bootrom_version = *(char **)&_bootphase1_version_pointer; + char *bootrom_version = *(char **)_bootphase1_version_pointer; strncat(VersionString, " [ "_YELLOW_("ARM")" ]\n", sizeof(VersionString) - strlen(VersionString) - 1); - if (bootrom_version < &_flash_start || bootrom_version >= &_flash_end) { + if (bootrom_version < _flash_start || bootrom_version >= _flash_end) { strcat(VersionString, "bootrom version information appears invalid\n"); } else { FormatVersionInformation(temp, sizeof(temp), " bootrom: ", bootrom_version); @@ -301,7 +300,7 @@ static void SendVersion(void) { } #ifndef WITH_NO_COMPRESSION // Send Chip ID and used flash memory - uint32_t text_and_rodata_section_size = (uint32_t)&__data_src_start__ - (uint32_t)&_flash_start; + uint32_t text_and_rodata_section_size = __data_src_start__ - _flash_start; uint32_t compressed_data_section_size = common_area.arg1; #endif @@ -315,7 +314,7 @@ static void SendVersion(void) { struct p payload; payload.id = *(AT91C_DBGU_CIDR); #ifdef WITH_NO_COMPRESSION - payload.section_size = (uint32_t)&_bootrom_end - (uint32_t)&_bootrom_start + (uint32_t)&__os_size__; + payload.section_size = _bootrom_end - _bootrom_start + (uint32_t)__os_size__; #else payload.section_size = text_and_rodata_section_size + compressed_data_section_size; #endif @@ -2440,7 +2439,7 @@ void __attribute__((noreturn)) AppMain(void) { SpinDelay(100); BigBuf_initialize(); - for (uint32_t *p = &_stack_start; p < (uint32_t *)((uintptr_t)&_stack_end - 0x200); ++p) { + for (uint32_t *p = (uint32_t *)_stack_start; p < (uint32_t *)_stack_end - 0x200; ++p) { *p = 0xdeadbeef; } @@ -2501,8 +2500,8 @@ void __attribute__((noreturn)) AppMain(void) { for (;;) { WDT_HIT(); - if (_stack_start != 0xdeadbeef) { - Dbprintf("Stack overflow detected! Please increase stack size, currently %d bytes", (&_stack_end - &_stack_start) << 2); + if (*((uint32_t *)_stack_start) != 0xdeadbeef) { + Dbprintf("Stack overflow detected! Please increase stack size, currently %d bytes", _stack_end - _stack_start); Dbprintf("Unplug your device now."); while (1); } diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index 2df952214..67974c4c7 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -34,7 +34,7 @@ typedef lz4_stream *lz4_streamp; static int downloaded_bitstream = 0; // this is where the bitstreams are located in memory: -extern uint8_t _binary_obj_fpga_all_bit_z_start, _binary_obj_fpga_all_bit_z_end; +extern char _binary_obj_fpga_all_bit_z_start[], _binary_obj_fpga_all_bit_z_end[]; static uint8_t *fpga_image_ptr = NULL; static uint32_t uncompressed_bytes_cnt; @@ -235,8 +235,8 @@ static bool reset_fpga_stream(int bitstream_version, lz4_streamp compressed_fpga uncompressed_bytes_cnt = 0; // initialize z_stream structure for inflate: - compressed_fpga_stream->next_in = (char *)&_binary_obj_fpga_all_bit_z_start; - compressed_fpga_stream->avail_in = &_binary_obj_fpga_all_bit_z_end - &_binary_obj_fpga_all_bit_z_start; + compressed_fpga_stream->next_in = _binary_obj_fpga_all_bit_z_start; + compressed_fpga_stream->avail_in = _binary_obj_fpga_all_bit_z_end - _binary_obj_fpga_all_bit_z_start; int res = LZ4_setStreamDecode(compressed_fpga_stream->lz4StreamDecode, NULL, 0); if (res == 0) diff --git a/armsrc/start.c b/armsrc/start.c index 062a83eb9..f6a3fd1de 100644 --- a/armsrc/start.c +++ b/armsrc/start.c @@ -21,16 +21,16 @@ #include "string.h" extern struct common_area common_area; -extern char __data_src_start__, __data_start__, __data_end__, __bss_start__, __bss_end__; +extern char __data_src_start__[], __data_start__[], __data_end__[], __bss_start__[], __bss_end__[]; #ifndef WITH_NO_COMPRESSION 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. + 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); + char *p = __data_src_start__; + int res = LZ4_decompress_safe(p + 4, __data_start__, avail_in, avail_out); if (res < 0) return; @@ -53,18 +53,16 @@ void Vector(void) { /* Set up data segment: Copy from flash to ram */ #ifdef WITH_NO_COMPRESSION - char *data_src = &__data_src_start__; - char *data_dst = &__data_start__; - char *data_end = &__data_end__; - while (data_dst < data_end) *data_dst++ = *data_src++; + char *data_src = __data_src_start__; + char *data_dst = __data_start__; + while (data_dst < __data_end__) *data_dst++ = *data_src++; #else uncompress_data_section(); #endif /* Set up (that is: clear) BSS. */ - char *bss_dst = &__bss_start__; - char *bss_end = &__bss_end__; - while (bss_dst < bss_end) *bss_dst++ = 0; + char *bss_dst = __bss_start__; + while (bss_dst < __bss_end__) *bss_dst++ = 0; AppMain(); } diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index eed42dff5..94f49de2b 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -268,7 +268,7 @@ static void lookupChipID(uint32_t iChipID, uint32_t mem_used) { break; } - PrintAndLogEx(NORMAL, " --= %s " _YELLOW_("%uK") " bytes ( " _YELLOW_("%2.0f%%") " used )" + PrintAndLogEx(NORMAL, " --= %s " _YELLOW_("%uK") " bytes ( " _YELLOW_("%2.1f%%") " used )" , asBuff , mem_avail , mem_avail == 0 ? 0.0f : (float)mem_used / (mem_avail * 1024) * 100