mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
rename common_area typedef and global
This commit is contained in:
parent
bc76c7263e
commit
d56d8f0f65
5 changed files with 38 additions and 38 deletions
|
@ -71,7 +71,7 @@ int g_dbglevel = DBG_ERROR;
|
||||||
uint8_t g_trigger = 0;
|
uint8_t g_trigger = 0;
|
||||||
bool g_hf_field_active = false;
|
bool g_hf_field_active = false;
|
||||||
extern uint32_t _stack_start[], _stack_end[];
|
extern uint32_t _stack_start[], _stack_end[];
|
||||||
struct common_area common_area __attribute__((section(".commonarea")));
|
common_area_t g_common_area __attribute__((section(".commonarea")));
|
||||||
static int button_status = BUTTON_NO_CLICK;
|
static int button_status = BUTTON_NO_CLICK;
|
||||||
static bool allow_send_wtx = false;
|
static bool allow_send_wtx = false;
|
||||||
uint16_t g_tearoff_delay_us = 0;
|
uint16_t g_tearoff_delay_us = 0;
|
||||||
|
@ -303,7 +303,7 @@ static void SendVersion(void) {
|
||||||
#ifndef WITH_NO_COMPRESSION
|
#ifndef WITH_NO_COMPRESSION
|
||||||
// Send Chip ID and used flash memory
|
// 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 = (uint32_t)__data_src_start__ - (uint32_t)_flash_start;
|
||||||
uint32_t compressed_data_section_size = common_area.arg1;
|
uint32_t compressed_data_section_size = g_common_area.arg1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct p {
|
struct p {
|
||||||
|
@ -2413,8 +2413,8 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_START_FLASH: {
|
case CMD_START_FLASH: {
|
||||||
if (common_area.flags.bootrom_present) {
|
if (g_common_area.flags.bootrom_present) {
|
||||||
common_area.command = COMMON_AREA_COMMAND_ENTER_FLASH_MODE;
|
g_common_area.command = COMMON_AREA_COMMAND_ENTER_FLASH_MODE;
|
||||||
}
|
}
|
||||||
usb_disable();
|
usb_disable();
|
||||||
AT91C_BASE_RSTC->RSTC_RCR = RST_CONTROL_KEY | AT91C_RSTC_PROCRST;
|
AT91C_BASE_RSTC->RSTC_RCR = RST_CONTROL_KEY | AT91C_RSTC_PROCRST;
|
||||||
|
@ -2424,7 +2424,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
}
|
}
|
||||||
case CMD_DEVICE_INFO: {
|
case CMD_DEVICE_INFO: {
|
||||||
uint32_t dev_info = DEVICE_INFO_FLAG_OSIMAGE_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_OS;
|
uint32_t dev_info = DEVICE_INFO_FLAG_OSIMAGE_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_OS;
|
||||||
if (common_area.flags.bootrom_present) {
|
if (g_common_area.flags.bootrom_present) {
|
||||||
dev_info |= DEVICE_INFO_FLAG_BOOTROM_PRESENT;
|
dev_info |= DEVICE_INFO_FLAG_BOOTROM_PRESENT;
|
||||||
}
|
}
|
||||||
reply_old(CMD_DEVICE_INFO, dev_info, 0, 0, 0, 0);
|
reply_old(CMD_DEVICE_INFO, dev_info, 0, 0, 0, 0);
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "BigBuf.h"
|
#include "BigBuf.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
extern struct common_area common_area;
|
extern common_area_t g_common_area;
|
||||||
extern uint32_t __data_src_start__[], __data_start__[], __data_end__[], __bss_start__[], __bss_end__[];
|
extern uint32_t __data_src_start__[], __data_start__[], __data_end__[], __bss_start__[], __bss_end__[];
|
||||||
|
|
||||||
#ifndef WITH_NO_COMPRESSION
|
#ifndef WITH_NO_COMPRESSION
|
||||||
|
@ -35,7 +35,7 @@ static void uncompress_data_section(void) {
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return;
|
return;
|
||||||
// save the size of the compressed data section
|
// save the size of the compressed data section
|
||||||
common_area.arg1 = avail_in;
|
g_common_area.arg1 = avail_in;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -43,13 +43,13 @@ void __attribute__((section(".startos"))) Vector(void);
|
||||||
void Vector(void) {
|
void Vector(void) {
|
||||||
/* Stack should have been set up by the bootloader */
|
/* Stack should have been set up by the bootloader */
|
||||||
|
|
||||||
if (common_area.magic != COMMON_AREA_MAGIC || common_area.version != 1) {
|
if (g_common_area.magic != COMMON_AREA_MAGIC || g_common_area.version != 1) {
|
||||||
/* Initialize common area */
|
/* Initialize common area */
|
||||||
memset(&common_area, 0, sizeof(common_area));
|
memset(&g_common_area, 0, sizeof(g_common_area));
|
||||||
common_area.magic = COMMON_AREA_MAGIC;
|
g_common_area.magic = COMMON_AREA_MAGIC;
|
||||||
common_area.version = 1;
|
g_common_area.version = 1;
|
||||||
}
|
}
|
||||||
common_area.flags.osimage_present = 1;
|
g_common_area.flags.osimage_present = 1;
|
||||||
|
|
||||||
/* Set up data segment: Copy from flash to ram */
|
/* Set up data segment: Copy from flash to ram */
|
||||||
#ifdef WITH_NO_COMPRESSION
|
#ifdef WITH_NO_COMPRESSION
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "proxmark3_arm.h"
|
#include "proxmark3_arm.h"
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
struct common_area common_area __attribute__((section(".commonarea")));
|
common_area_t g_common_area __attribute__((section(".commonarea")));
|
||||||
uint32_t start_addr, end_addr;
|
uint32_t start_addr, end_addr;
|
||||||
bool bootrom_unlocked;
|
bool bootrom_unlocked;
|
||||||
extern uint32_t _bootrom_start[], _bootrom_end[], _flash_start[], _flash_end[], _osimage_entry[];
|
extern uint32_t _bootrom_start[], _bootrom_end[], _flash_start[], _flash_end[], _osimage_entry[];
|
||||||
|
@ -90,7 +90,7 @@ static void UsbPacketReceived(uint8_t *packet) {
|
||||||
DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH |
|
DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH |
|
||||||
DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO |
|
DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO |
|
||||||
DEVICE_INFO_FLAG_UNDERSTANDS_VERSION;
|
DEVICE_INFO_FLAG_UNDERSTANDS_VERSION;
|
||||||
if (common_area.flags.osimage_present)
|
if (g_common_area.flags.osimage_present)
|
||||||
arg0 |= DEVICE_INFO_FLAG_OSIMAGE_PRESENT;
|
arg0 |= DEVICE_INFO_FLAG_OSIMAGE_PRESENT;
|
||||||
|
|
||||||
reply_old(CMD_DEVICE_INFO, arg0, 1, 2, 0, 0);
|
reply_old(CMD_DEVICE_INFO, arg0, 1, 2, 0, 0);
|
||||||
|
@ -196,9 +196,9 @@ static void flash_mode(void) {
|
||||||
end_addr = 0;
|
end_addr = 0;
|
||||||
bootrom_unlocked = false;
|
bootrom_unlocked = false;
|
||||||
uint8_t rx[sizeof(PacketCommandOLD)];
|
uint8_t rx[sizeof(PacketCommandOLD)];
|
||||||
common_area.command = COMMON_AREA_COMMAND_NONE;
|
g_common_area.command = COMMON_AREA_COMMAND_NONE;
|
||||||
if (!common_area.flags.button_pressed && BUTTON_PRESS())
|
if (!g_common_area.flags.button_pressed && BUTTON_PRESS())
|
||||||
common_area.flags.button_pressed = 1;
|
g_common_area.flags.button_pressed = 1;
|
||||||
|
|
||||||
usb_enable();
|
usb_enable();
|
||||||
|
|
||||||
|
@ -215,12 +215,12 @@ static void flash_mode(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (common_area.flags.button_pressed && !BUTTON_PRESS()) {
|
if (g_common_area.flags.button_pressed && !BUTTON_PRESS()) {
|
||||||
common_area.flags.button_pressed = 0;
|
g_common_area.flags.button_pressed = 0;
|
||||||
}
|
}
|
||||||
if (!common_area.flags.button_pressed && BUTTON_PRESS()) {
|
if (!g_common_area.flags.button_pressed && BUTTON_PRESS()) {
|
||||||
/* Perform a reset to leave flash mode */
|
/* Perform a reset to leave flash mode */
|
||||||
common_area.flags.button_pressed = 1;
|
g_common_area.flags.button_pressed = 1;
|
||||||
usb_disable();
|
usb_disable();
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
AT91C_BASE_RSTC->RSTC_RCR = RST_CONTROL_KEY | AT91C_RSTC_PROCRST;
|
AT91C_BASE_RSTC->RSTC_RCR = RST_CONTROL_KEY | AT91C_RSTC_PROCRST;
|
||||||
|
@ -292,38 +292,38 @@ void BootROM(void) {
|
||||||
|
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
|
|
||||||
int common_area_present = 0;
|
int g_common_area_present = 0;
|
||||||
switch (AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_RSTTYP) {
|
switch (AT91C_BASE_RSTC->RSTC_RSR & AT91C_RSTC_RSTTYP) {
|
||||||
case AT91C_RSTC_RSTTYP_WATCHDOG:
|
case AT91C_RSTC_RSTTYP_WATCHDOG:
|
||||||
case AT91C_RSTC_RSTTYP_SOFTWARE:
|
case AT91C_RSTC_RSTTYP_SOFTWARE:
|
||||||
case AT91C_RSTC_RSTTYP_USER:
|
case AT91C_RSTC_RSTTYP_USER:
|
||||||
/* In these cases the common_area in RAM should be ok, retain it if it's there */
|
/* In these cases the g_common_area in RAM should be ok, retain it if it's there */
|
||||||
if (common_area.magic == COMMON_AREA_MAGIC && common_area.version == 1)
|
if (g_common_area.magic == COMMON_AREA_MAGIC && g_common_area.version == 1)
|
||||||
common_area_present = 1;
|
g_common_area_present = 1;
|
||||||
break;
|
break;
|
||||||
default: /* Otherwise, initialize it from scratch */
|
default: /* Otherwise, initialize it from scratch */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!common_area_present) {
|
if (!g_common_area_present) {
|
||||||
/* Common area not ok, initialize it */
|
/* Common area not ok, initialize it */
|
||||||
size_t i;
|
size_t i;
|
||||||
/* Makeshift memset, no need to drag util.c into this */
|
/* Makeshift memset, no need to drag util.c into this */
|
||||||
for (i = 0; i < sizeof(common_area); i++)
|
for (i = 0; i < sizeof(g_common_area); i++)
|
||||||
((char *)&common_area)[i] = 0;
|
((char *)&g_common_area)[i] = 0;
|
||||||
|
|
||||||
common_area.magic = COMMON_AREA_MAGIC;
|
g_common_area.magic = COMMON_AREA_MAGIC;
|
||||||
common_area.version = 1;
|
g_common_area.version = 1;
|
||||||
}
|
}
|
||||||
common_area.flags.bootrom_present = 1;
|
g_common_area.flags.bootrom_present = 1;
|
||||||
|
|
||||||
if ((common_area.command == COMMON_AREA_COMMAND_ENTER_FLASH_MODE) ||
|
if ((g_common_area.command == COMMON_AREA_COMMAND_ENTER_FLASH_MODE) ||
|
||||||
(!common_area.flags.button_pressed && BUTTON_PRESS()) ||
|
(!g_common_area.flags.button_pressed && BUTTON_PRESS()) ||
|
||||||
(*_osimage_entry == 0xffffffffU)) {
|
(*_osimage_entry == 0xffffffffU)) {
|
||||||
flash_mode();
|
flash_mode();
|
||||||
} else {
|
} else {
|
||||||
// clear button status, even if button still pressed
|
// clear button status, even if button still pressed
|
||||||
common_area.flags.button_pressed = 0;
|
g_common_area.flags.button_pressed = 0;
|
||||||
// jump to Flash address of the osimage entry point (LSBit set for thumb mode)
|
// jump to Flash address of the osimage entry point (LSBit set for thumb mode)
|
||||||
__asm("bx %0\n" : : "r"(((uint32_t)_osimage_entry) | 0x1));
|
__asm("bx %0\n" : : "r"(((uint32_t)_osimage_entry) | 0x1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -886,10 +886,10 @@ typedef struct {
|
||||||
|
|
||||||
|
|
||||||
// CMD_DEVICE_INFO response packet has flags in arg[0], flag definitions:
|
// CMD_DEVICE_INFO response packet has flags in arg[0], flag definitions:
|
||||||
/* Whether a bootloader that understands the common_area is present */
|
/* Whether a bootloader that understands the g_common_area is present */
|
||||||
#define DEVICE_INFO_FLAG_BOOTROM_PRESENT (1<<0)
|
#define DEVICE_INFO_FLAG_BOOTROM_PRESENT (1<<0)
|
||||||
|
|
||||||
/* Whether a osimage that understands the common_area is present */
|
/* Whether a osimage that understands the g_common_area is present */
|
||||||
#define DEVICE_INFO_FLAG_OSIMAGE_PRESENT (1<<1)
|
#define DEVICE_INFO_FLAG_OSIMAGE_PRESENT (1<<1)
|
||||||
|
|
||||||
/* Set if the bootloader is currently executing */
|
/* Set if the bootloader is currently executing */
|
||||||
|
|
|
@ -120,7 +120,7 @@
|
||||||
#define COMMON_AREA_MAGIC 0x43334d50 // "PM3C"
|
#define COMMON_AREA_MAGIC 0x43334d50 // "PM3C"
|
||||||
#define COMMON_AREA_COMMAND_NONE 0
|
#define COMMON_AREA_COMMAND_NONE 0
|
||||||
#define COMMON_AREA_COMMAND_ENTER_FLASH_MODE 1
|
#define COMMON_AREA_COMMAND_ENTER_FLASH_MODE 1
|
||||||
struct common_area {
|
typedef struct {
|
||||||
int magic; /* Magic sequence, to distinguish against random uninitialized memory */
|
int magic; /* Magic sequence, to distinguish against random uninitialized memory */
|
||||||
char version; /* Must be 1 */
|
char version; /* Must be 1 */
|
||||||
char command;
|
char command;
|
||||||
|
@ -130,6 +130,6 @@ struct common_area {
|
||||||
unsigned int button_pressed: 1;
|
unsigned int button_pressed: 1;
|
||||||
} PACKED flags;
|
} PACKED flags;
|
||||||
int arg1, arg2;
|
int arg1, arg2;
|
||||||
} PACKED;
|
} PACKED common_area_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue