mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-18 06:08:31 +03:00
Structure build system to build for multiple boards/apps/environments
This commit is contained in:
10
.gitignore
vendored
10
.gitignore
vendored
@@ -7,11 +7,15 @@ cscope.out
|
|||||||
*/__pycache__
|
*/__pycache__
|
||||||
*.E
|
*.E
|
||||||
*.pyc
|
*.pyc
|
||||||
sam3s_example/mains/zwizwa_ccid.c
|
|
||||||
Baselibc
|
|
||||||
venv
|
|
||||||
tags
|
tags
|
||||||
*.hobj
|
*.hobj
|
||||||
*.o
|
*.o
|
||||||
|
*.a
|
||||||
|
*.lst
|
||||||
|
*.map
|
||||||
|
*.elf
|
||||||
|
*.size
|
||||||
|
*.bin
|
||||||
|
*.p
|
||||||
host/simtrace2-remsim
|
host/simtrace2-remsim
|
||||||
host/simtrace2-remsim-usb2udp
|
host/simtrace2-remsim-usb2udp
|
||||||
|
|||||||
@@ -34,11 +34,11 @@
|
|||||||
|
|
||||||
# Chip & board used for compilation
|
# Chip & board used for compilation
|
||||||
# (can be overriden by adding CHIP=chip and BOARD=board to the command-line)
|
# (can be overriden by adding CHIP=chip and BOARD=board to the command-line)
|
||||||
CHIP = sam3s2
|
CHIP ?= sam3s4
|
||||||
BOARD = simtrace
|
BOARD ?= qmod
|
||||||
|
|
||||||
# Defines which are the available memory targets for the SAM3S-EK board.
|
# Defines which are the available memory targets for the SAM3S-EK board.
|
||||||
MEMORIES = flash
|
MEMORIES ?= flash dfu
|
||||||
|
|
||||||
# Trace level used for compilation
|
# Trace level used for compilation
|
||||||
# (can be overriden by adding TRACE_LEVEL=#number to the command-line)
|
# (can be overriden by adding TRACE_LEVEL=#number to the command-line)
|
||||||
@@ -48,9 +48,7 @@ MEMORIES = flash
|
|||||||
# TRACE_LEVEL_ERROR 2
|
# TRACE_LEVEL_ERROR 2
|
||||||
# TRACE_LEVEL_FATAL 1
|
# TRACE_LEVEL_FATAL 1
|
||||||
# TRACE_LEVEL_NO_TRACE 0
|
# TRACE_LEVEL_NO_TRACE 0
|
||||||
TRACE_LEVEL = 4
|
TRACE_LEVEL ?= 4
|
||||||
#FIXME: Remove this variable
|
|
||||||
NOAUTOCALLBACK=no
|
|
||||||
|
|
||||||
DEBUG_PHONE_SNIFF=0
|
DEBUG_PHONE_SNIFF=0
|
||||||
|
|
||||||
@@ -60,11 +58,12 @@ DEBUG_PHONE_SNIFF=0
|
|||||||
OPTIMIZATION = -O0
|
OPTIMIZATION = -O0
|
||||||
|
|
||||||
# Output file basename
|
# Output file basename
|
||||||
OUTPUT = project
|
APP = dfu
|
||||||
|
|
||||||
# Output directories
|
# Output directories
|
||||||
|
OUTPUT = $(BOARD)-$(APP)
|
||||||
BIN = bin
|
BIN = bin
|
||||||
OBJ = obj
|
OBJ = obj/$(BOARD)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Tools
|
# Tools
|
||||||
@@ -132,7 +131,7 @@ CFLAGS += -Dprintf=iprintf
|
|||||||
CFLAGS += -D__ARM
|
CFLAGS += -D__ARM
|
||||||
CFLAGS += --param max-inline-insns-single=500 -mcpu=cortex-m3 -mthumb # -mfix-cortex-m3-ldrd
|
CFLAGS += --param max-inline-insns-single=500 -mcpu=cortex-m3 -mthumb # -mfix-cortex-m3-ldrd
|
||||||
CFLAGS += -ffunction-sections -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL) -DDEBUG_PHONE_SNIFF=$(DEBUG_PHONE_SNIFF)
|
CFLAGS += -ffunction-sections -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL) -DDEBUG_PHONE_SNIFF=$(DEBUG_PHONE_SNIFF)
|
||||||
CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
|
CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" -DBOARD=\"$(BOARD)\" -DAPPLICATION=\"$(APP)\"
|
||||||
ASFLAGS = -mcpu=cortex-m3 -mthumb -Wall -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__
|
ASFLAGS = -mcpu=cortex-m3 -mthumb -Wall -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__
|
||||||
LDFLAGS = -mcpu=cortex-m3 -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=ResetException -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols $(LIB)
|
LDFLAGS = -mcpu=cortex-m3 -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=ResetException -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols $(LIB)
|
||||||
#LD_OPTIONAL=-Wl,--print-gc-sections -Wl,--stats
|
#LD_OPTIONAL=-Wl,--print-gc-sections -Wl,--stats
|
||||||
@@ -150,16 +149,27 @@ VPATH += $(AT91LIB)/libchip_sam3s/source/ $(AT91LIB)/libchip_sam3s/cmsis
|
|||||||
VPATH += libboard/common/source libboard/$(BOARD)/source
|
VPATH += libboard/common/source libboard/$(BOARD)/source
|
||||||
VPATH += libcommon/source
|
VPATH += libcommon/source
|
||||||
VPATH += libosmocore/source src_board src_simtrace
|
VPATH += libosmocore/source src_board src_simtrace
|
||||||
|
VPATH += apps/$(APP)
|
||||||
|
|
||||||
# Objects built from C source files
|
# Objects built from C source files
|
||||||
C_CMSIS = core_cm3.o
|
C_OSMOCORE = $(notdir $(wildcard libosmocore/source/*.c))
|
||||||
C_LOWLEVEL = board_cstartup_gnu.o board_lowlevel.o syscalls.o exceptions.o
|
C_LIBCHIP = $(notdir $(wildcard $(AT91LIB)/libchip_sam3s/source/*.c) $(wildcard $(AT91LIB)/libchip_sam3s/cmsis/*.c))
|
||||||
C_LIBLEVEL = spi.o pio.o pmc.o usart.o pio_it.o pio_capture.o uart_console.o iso7816_4.o wdt.o efc.o flashd.o led.o tc.o unique_id.o boardver_adc.o dfu_desc.o dfu_runtime.o
|
|
||||||
C_CCID = cciddriver.o USBD.o USBDDriver.o USBD_HAL.o USBRequests.o USBDCallbacks.o USBDescriptors.o USBDDriverCallbacks.o
|
C_LIBUSB = USBDescriptors.c USBRequests.c USBD.c USBDCallbacks.c USBDDriver.c USBDDriverCallbacks.c
|
||||||
C_SIMTRACE = simtrace_iso7816.o usb.o ccid.o sniffer.o mitm.o ringbuffer.o host_communication.o iso7816_fidi.o tc_etu.o req_ctx.o card_emu.o mode_cardemu.o i2c.o wwan_led.o wwan_perst.o
|
C_LIBUSB_RT = dfu.c dfu_desc.c dfu_runtime.c
|
||||||
C_OSMOCORE = timer.o rbtree.o
|
C_LIBUSB_DFU = dfu.c dfu_desc.c dfu_driver.c
|
||||||
C_APPLEVEL = main.o board_$(BOARD).o
|
C_LIBCOMMON = syscalls.c req_ctx.c ringbuffer.c
|
||||||
C_OBJECTS = $(C_CMSIS) $(C_LOWLEVEL) $(C_LIBLEVEL) $(C_APPLEVEL) $(C_CCID) $(C_SIMTRACE) $(C_OSMOCORE)
|
|
||||||
|
C_BOARD = $(notdir $(wildcard libboard/common/source/*.c))
|
||||||
|
C_BOARD += $(notdir $(wildcard libboard/$(BOARD)/source/*.c))
|
||||||
|
|
||||||
|
C_APPLEVEL = $(notdir $(wildcard apps/$(APP)/*.c))
|
||||||
|
|
||||||
|
C_FILES = $(C_OSMOCORE) $(C_LIBCHIP) $(C_LIBUSB) $(C_LIBCOMMON) $(C_BOARD) $(C_APPLEVEL)
|
||||||
|
|
||||||
|
-include apps/$(APP)/Makefile
|
||||||
|
|
||||||
|
C_OBJECTS = $(C_FILES:%.c=%.o)
|
||||||
|
|
||||||
# Append OBJ and BIN directories to output filename
|
# Append OBJ and BIN directories to output filename
|
||||||
OUTPUT := $(BIN)/$(OUTPUT)
|
OUTPUT := $(BIN)/$(OUTPUT)
|
||||||
@@ -178,18 +188,18 @@ C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS))
|
|||||||
ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS))
|
ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS))
|
||||||
|
|
||||||
$(1): $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1))
|
$(1): $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1))
|
||||||
@$(CC) $(LDFLAGS) $(LD_OPTIONAL) -T"$$@.ld" -Wl,-Map,$(OUTPUT)-$$@.map -o $(OUTPUT)-$$@.elf $$^ $(LIBS)
|
@$(CC) $(LDFLAGS) $(LD_OPTIONAL) -T"libboard/common/resources/$(CHIP)/$$@.ld" -Wl,-Map,$(OUTPUT)-$$@.map -o $(OUTPUT)-$$@.elf $$^ $(LIBS)
|
||||||
@$(NM) $(OUTPUT)-$$@.elf >$(OUTPUT)-$$@.elf.txt
|
@$(NM) $(OUTPUT)-$$@.elf >$(OUTPUT)-$$@.elf.txt
|
||||||
@$(OBJCOPY) -O binary $(OUTPUT)-$$@.elf $(OUTPUT)-$$@.bin
|
@$(OBJCOPY) -O binary $(OUTPUT)-$$@.elf $(OUTPUT)-$$@.bin
|
||||||
@$(SIZE) $$^ $(OUTPUT)-$$@.elf
|
@$(SIZE) $$^ $(OUTPUT)-$$@.elf
|
||||||
|
|
||||||
$$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN)
|
$$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN)
|
||||||
@echo [COMPILING $$<]
|
@echo [COMPILING $$<]
|
||||||
@$(CC) $(CFLAGS) -D$(1) -Wa,-ahlms=$(BIN)/$$*.lst -c -o $$@ $$<
|
@$(CC) $(CFLAGS) -D$(1) -DENVIRONMENT=\"$(1)\" -Wa,-ahlms=$(BIN)/$$*.lst -c -o $$@ $$<
|
||||||
|
|
||||||
$$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN)
|
$$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN)
|
||||||
@echo [ASSEMBLING $$@]
|
@echo [ASSEMBLING $$@]
|
||||||
@$(CC) $(ASFLAGS) -D$(1) -c -o $$@ $$<
|
@$(CC) $(ASFLAGS) -D$(1) -DENVIRONMENT=\"$(1)\" -c -o $$@ $$<
|
||||||
|
|
||||||
debug_$(1): $(1)
|
debug_$(1): $(1)
|
||||||
$(GDB) -x "$(BOARD_LIB)/resources/gcc/$(BOARD)_$(1).gdb" -ex "reset" -readnow -se $(OUTPUT)-$(1).elf
|
$(GDB) -x "$(BOARD_LIB)/resources/gcc/$(BOARD)_$(1).gdb" -ex "reset" -readnow -se $(OUTPUT)-$(1).elf
|
||||||
@@ -207,6 +217,3 @@ log:
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -fR $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf $(BIN)/*.elf.txt $(BIN)/*.map $(BIN)/*.lst
|
-rm -fR $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf $(BIN)/*.elf.txt $(BIN)/*.map $(BIN)/*.lst
|
||||||
|
|
||||||
rmbak:
|
|
||||||
-rm *~ $(BIN)/*~
|
|
||||||
|
|||||||
33
firmware/README.txt
Normal file
33
firmware/README.txt
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
== BOARDS
|
||||||
|
|
||||||
|
A board defines a given circuit board, i.e. SIMtrace, OWHW, QMOD
|
||||||
|
|
||||||
|
It defines the given hardware model for which the program is to be
|
||||||
|
compiled.
|
||||||
|
|
||||||
|
Current boards supported are:
|
||||||
|
* simtrace: The good old Osmocom SIMtrace PCB with SAM3 instead of
|
||||||
|
SAM7, open hardware.
|
||||||
|
* qmod: A sysmocom-proprietary quad mPCIe carrier board, publicly available
|
||||||
|
* owhw: An undisclosed sysmocom-internal board, not publicly available
|
||||||
|
|
||||||
|
== APPLICATIONS
|
||||||
|
|
||||||
|
An application is a specific piece of software with given
|
||||||
|
functionality.
|
||||||
|
|
||||||
|
== ENVIRONMENTS
|
||||||
|
|
||||||
|
An environment is a runtime environment, typically defined by a linker
|
||||||
|
script. The current runtime environments include
|
||||||
|
* flash: Run natively from start of flash memory
|
||||||
|
* dfu: Run after a DFU bootloader from an offset after the first 16k
|
||||||
|
of flash (the first 16k are reserved for the bootloader)
|
||||||
|
* ram: Run from within the RAM of the chip, downloaded via JTAG/SWD
|
||||||
|
|
||||||
|
|
||||||
|
== Building
|
||||||
|
|
||||||
|
A given software build is made for a specific combination of an APP
|
||||||
|
running in a certain ENVIRONMENT on a given BOARD.
|
||||||
3
firmware/apps/cardem/Makefile
Normal file
3
firmware/apps/cardem/Makefile
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
C_FILES += $(C_LIBUSB_RT)
|
||||||
|
|
||||||
|
C_FILES += card_emu.c ccid.c host_communication.c iso7816_4.c iso7816_fidi.c mitm.c mode_cardemu.c simtrace_iso7816.c sniffer.c tc_etu.c usb.c
|
||||||
0
firmware/apps/ccid/main.c
Normal file
0
firmware/apps/ccid/main.c
Normal file
1
firmware/apps/dfu/Makefile
Normal file
1
firmware/apps/dfu/Makefile
Normal file
@@ -0,0 +1 @@
|
|||||||
|
C_FILES += $(C_LIBUSB_DFU)
|
||||||
107
firmware/apps/dfu/main.c
Normal file
107
firmware/apps/dfu/main.c
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
#include "board.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "usb/device/dfu/dfu.h"
|
||||||
|
#include "usb/common/dfu/usb_dfu.h"
|
||||||
|
#include "manifest.h"
|
||||||
|
|
||||||
|
unsigned int g_unique_id[4];
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
* Callbacks
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum)
|
||||||
|
{
|
||||||
|
TRACE_INFO_WP("cfgChanged%d ", cfgnum);
|
||||||
|
simtrace_config = cfgnum;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* returns '1' in case we should break any endless loop */
|
||||||
|
static void check_exec_dbg_cmd(void)
|
||||||
|
{
|
||||||
|
int ch;
|
||||||
|
|
||||||
|
if (!UART_IsRxReady())
|
||||||
|
return;
|
||||||
|
|
||||||
|
ch = UART_GetChar();
|
||||||
|
|
||||||
|
//board_exec_dbg_cmd(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Main
|
||||||
|
*------------------------------------------------------------------------------*/
|
||||||
|
#define MAX_USB_ITER BOARD_MCK/72 // This should be around a second
|
||||||
|
extern int main(void)
|
||||||
|
{
|
||||||
|
uint8_t isUsbConnected = 0;
|
||||||
|
unsigned int i = 0;
|
||||||
|
|
||||||
|
LED_Configure(LED_NUM_RED);
|
||||||
|
LED_Configure(LED_NUM_GREEN);
|
||||||
|
LED_Set(LED_NUM_RED);
|
||||||
|
|
||||||
|
/* Disable watchdog */
|
||||||
|
WDT_Disable(WDT);
|
||||||
|
|
||||||
|
//req_ctx_init();
|
||||||
|
|
||||||
|
PIO_InitializeInterrupts(0);
|
||||||
|
|
||||||
|
EEFC_ReadUniqueID(g_unique_id);
|
||||||
|
|
||||||
|
printf("\r\n\r\n"
|
||||||
|
"=============================================================================\r\n"
|
||||||
|
"DFU bootloader %s for board %s (C) 2010-2017 by Harald Welte\r\n"
|
||||||
|
"=============================================================================\r\n",
|
||||||
|
manifest_revision, manifest_board);
|
||||||
|
|
||||||
|
TRACE_INFO("Serial Nr. %08x-%08x-%08x-%08x\r\n",
|
||||||
|
g_unique_id[0], g_unique_id[1],
|
||||||
|
g_unique_id[2], g_unique_id[3]);
|
||||||
|
|
||||||
|
//board_main_top();
|
||||||
|
|
||||||
|
TRACE_INFO("USB init...\r\n");
|
||||||
|
USBDFU_Initialize(&dfu_descriptors);
|
||||||
|
|
||||||
|
while (USBD_GetState() < USBD_STATE_CONFIGURED) {
|
||||||
|
check_exec_dbg_cmd();
|
||||||
|
#if 0
|
||||||
|
if (i >= MAX_USB_ITER * 3) {
|
||||||
|
TRACE_ERROR("Resetting board (USB could "
|
||||||
|
"not be configured)\r\n");
|
||||||
|
NVIC_SystemReset();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
TRACE_INFO("entering main loop...\r\n");
|
||||||
|
while (1) {
|
||||||
|
#if TRACE_LEVEL >= TRACE_LEVEL_DEBUG
|
||||||
|
const char rotor[] = { '-', '\\', '|', '/' };
|
||||||
|
putchar('\b');
|
||||||
|
putchar(rotor[i++ % ARRAY_SIZE(rotor)]);
|
||||||
|
#endif
|
||||||
|
check_exec_dbg_cmd();
|
||||||
|
//osmo_timers_prepare();
|
||||||
|
//osmo_timers_update();
|
||||||
|
|
||||||
|
if (USBD_GetState() < USBD_STATE_CONFIGURED) {
|
||||||
|
|
||||||
|
if (isUsbConnected) {
|
||||||
|
isUsbConnected = 0;
|
||||||
|
}
|
||||||
|
} else if (isUsbConnected == 0) {
|
||||||
|
TRACE_INFO("USB is now configured\r\n");
|
||||||
|
LED_Set(LED_NUM_GREEN);
|
||||||
|
LED_Clear(LED_NUM_RED);
|
||||||
|
|
||||||
|
isUsbConnected = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
0
firmware/apps/trace/main.c
Normal file
0
firmware/apps/trace/main.c
Normal file
3
firmware/apps/triple_play/Makefile
Normal file
3
firmware/apps/triple_play/Makefile
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
C_FILES += $(C_LIBUSB_RT)
|
||||||
|
|
||||||
|
C_FILES += card_emu.c ccid.c host_communication.c iso7816_4.c iso7816_fidi.c mitm.c mode_cardemu.c simtrace_iso7816.c sniffer.c tc_etu.c usb.c
|
||||||
207
firmware/apps/triple_play/main.c
Normal file
207
firmware/apps/triple_play/main.c
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
// FIXME: Copyright license here
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Headers
|
||||||
|
*------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "board.h"
|
||||||
|
#include "simtrace.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "req_ctx.h"
|
||||||
|
#include "osmocom/core/timer.h"
|
||||||
|
|
||||||
|
uint32_t g_unique_id[4];
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Internal variables
|
||||||
|
*------------------------------------------------------------------------------*/
|
||||||
|
typedef struct {
|
||||||
|
/* static initialization, called whether or not the usb config is active */
|
||||||
|
void (*configure) (void);
|
||||||
|
/* initialization function after the config was selected */
|
||||||
|
void (*init) (void);
|
||||||
|
/* de-initialization before selecting new config */
|
||||||
|
void (*exit) (void);
|
||||||
|
/* main loop content for given configuration */
|
||||||
|
void (*run) (void);
|
||||||
|
/* Interrupt handler for USART1 */
|
||||||
|
void (*usart0_irq) (void);
|
||||||
|
/* Interrupt handler for USART1 */
|
||||||
|
void (*usart1_irq) (void);
|
||||||
|
} conf_func;
|
||||||
|
|
||||||
|
static const conf_func config_func_ptrs[] = {
|
||||||
|
/* array slot 0 is empty, usb configs start at 1 */
|
||||||
|
#ifdef HAVE_SNIFFER
|
||||||
|
[CFG_NUM_SNIFF] = {
|
||||||
|
.configure = Sniffer_configure,
|
||||||
|
.init = Sniffer_init,
|
||||||
|
.exit = Sniffer_exit,
|
||||||
|
.run = Sniffer_run,
|
||||||
|
},
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_CCID
|
||||||
|
[CFG_NUM_CCID] = {
|
||||||
|
.configure = CCID_configure,
|
||||||
|
.init = CCID_init,
|
||||||
|
.exit = CCID_exit,
|
||||||
|
.run = CCID_run,
|
||||||
|
},
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_CARDEM
|
||||||
|
[CFG_NUM_PHONE] = {
|
||||||
|
.configure = mode_cardemu_configure,
|
||||||
|
.init = mode_cardemu_init,
|
||||||
|
.exit = mode_cardemu_exit,
|
||||||
|
.run = mode_cardemu_run,
|
||||||
|
.usart0_irq = mode_cardemu_usart0_irq,
|
||||||
|
.usart1_irq = mode_cardemu_usart1_irq,
|
||||||
|
},
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_MITM
|
||||||
|
[CFG_NUM_MITM] = {
|
||||||
|
.configure = MITM_configure,
|
||||||
|
.init = MITM_init,
|
||||||
|
.exit = MITM_exit,
|
||||||
|
.run = MITM_run,
|
||||||
|
},
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Internal variables
|
||||||
|
*------------------------------------------------------------------------------*/
|
||||||
|
#if defined(HAVE_SNIFFER)
|
||||||
|
static volatile enum confNum simtrace_config = CFG_NUM_SNIFF;
|
||||||
|
#elif defined(HAVE_CARDEM)
|
||||||
|
static volatile enum confNum simtrace_config = CFG_NUM_PHONE;
|
||||||
|
#elif defined(HAVE_CCID)
|
||||||
|
static volatile enum confNum simtrace_config = CFG_NUM_CCID;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
* Callbacks
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum)
|
||||||
|
{
|
||||||
|
TRACE_INFO_WP("cfgChanged%d ", cfgnum);
|
||||||
|
simtrace_config = cfgnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
void USART1_IrqHandler(void)
|
||||||
|
{
|
||||||
|
config_func_ptrs[simtrace_config].usart1_irq();
|
||||||
|
}
|
||||||
|
|
||||||
|
void USART0_IrqHandler(void)
|
||||||
|
{
|
||||||
|
config_func_ptrs[simtrace_config].usart0_irq();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* returns '1' in case we should break any endless loop */
|
||||||
|
static void check_exec_dbg_cmd(void)
|
||||||
|
{
|
||||||
|
int ch;
|
||||||
|
|
||||||
|
if (!UART_IsRxReady())
|
||||||
|
return;
|
||||||
|
|
||||||
|
ch = UART_GetChar();
|
||||||
|
|
||||||
|
board_exec_dbg_cmd(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Main
|
||||||
|
*------------------------------------------------------------------------------*/
|
||||||
|
#define MAX_USB_ITER BOARD_MCK/72 // This should be around a second
|
||||||
|
extern int main(void)
|
||||||
|
{
|
||||||
|
uint8_t isUsbConnected = 0;
|
||||||
|
enum confNum last_simtrace_config = simtrace_config;
|
||||||
|
unsigned int i = 0;
|
||||||
|
|
||||||
|
LED_Configure(LED_NUM_RED);
|
||||||
|
LED_Configure(LED_NUM_GREEN);
|
||||||
|
LED_Set(LED_NUM_RED);
|
||||||
|
|
||||||
|
/* Disable watchdog */
|
||||||
|
WDT_Disable(WDT);
|
||||||
|
|
||||||
|
req_ctx_init();
|
||||||
|
|
||||||
|
PIO_InitializeInterrupts(0);
|
||||||
|
|
||||||
|
EEFC_ReadUniqueID(g_unique_id);
|
||||||
|
|
||||||
|
printf("\r\n\r\n"
|
||||||
|
"=============================================================================\r\n"
|
||||||
|
"SIMtrace2 firmware " GIT_REVISION " (C) 2010-2017 by Harald Welte\r\n"
|
||||||
|
"=============================================================================\r\n");
|
||||||
|
|
||||||
|
TRACE_INFO("Serial Nr. %08x-%08x-%08x-%08x\r\n",
|
||||||
|
g_unique_id[0], g_unique_id[1],
|
||||||
|
g_unique_id[2], g_unique_id[3]);
|
||||||
|
|
||||||
|
board_main_top();
|
||||||
|
|
||||||
|
TRACE_INFO("USB init...\r\n");
|
||||||
|
SIMtrace_USB_Initialize();
|
||||||
|
|
||||||
|
while (USBD_GetState() < USBD_STATE_CONFIGURED) {
|
||||||
|
check_exec_dbg_cmd();
|
||||||
|
#if 0
|
||||||
|
if (i >= MAX_USB_ITER * 3) {
|
||||||
|
TRACE_ERROR("Resetting board (USB could "
|
||||||
|
"not be configured)\r\n");
|
||||||
|
NVIC_SystemReset();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
TRACE_INFO("calling configure of all configurations...\r\n");
|
||||||
|
for (i = 1; i < sizeof(config_func_ptrs) / sizeof(config_func_ptrs[0]);
|
||||||
|
++i) {
|
||||||
|
if (config_func_ptrs[i].configure)
|
||||||
|
config_func_ptrs[i].configure();
|
||||||
|
}
|
||||||
|
|
||||||
|
TRACE_INFO("calling init of config %u...\r\n", simtrace_config);
|
||||||
|
config_func_ptrs[simtrace_config].init();
|
||||||
|
last_simtrace_config = simtrace_config;
|
||||||
|
|
||||||
|
TRACE_INFO("entering main loop...\r\n");
|
||||||
|
while (1) {
|
||||||
|
#if TRACE_LEVEL >= TRACE_LEVEL_DEBUG
|
||||||
|
const char rotor[] = { '-', '\\', '|', '/' };
|
||||||
|
putchar('\b');
|
||||||
|
putchar(rotor[i++ % ARRAY_SIZE(rotor)]);
|
||||||
|
#endif
|
||||||
|
check_exec_dbg_cmd();
|
||||||
|
osmo_timers_prepare();
|
||||||
|
osmo_timers_update();
|
||||||
|
|
||||||
|
if (USBD_GetState() < USBD_STATE_CONFIGURED) {
|
||||||
|
|
||||||
|
if (isUsbConnected) {
|
||||||
|
isUsbConnected = 0;
|
||||||
|
}
|
||||||
|
} else if (isUsbConnected == 0) {
|
||||||
|
TRACE_INFO("USB is now configured\r\n");
|
||||||
|
LED_Set(LED_NUM_GREEN);
|
||||||
|
LED_Clear(LED_NUM_RED);
|
||||||
|
|
||||||
|
isUsbConnected = 1;
|
||||||
|
}
|
||||||
|
if (last_simtrace_config != simtrace_config) {
|
||||||
|
TRACE_INFO("USB config chg %u -> %u\r\n",
|
||||||
|
last_simtrace_config, simtrace_config);
|
||||||
|
config_func_ptrs[last_simtrace_config].exit();
|
||||||
|
config_func_ptrs[simtrace_config].init();
|
||||||
|
last_simtrace_config = simtrace_config;
|
||||||
|
} else {
|
||||||
|
config_func_ptrs[simtrace_config].run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,7 +48,7 @@ __dfudata struct dfudata g_dfu = {
|
|||||||
.total_bytes = 0,
|
.total_bytes = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
WEAK void dfu_drv_updatatus(void)
|
WEAK void dfu_drv_updstatus(void)
|
||||||
{
|
{
|
||||||
TRACE_INFO("DFU: updstatus()\n\r");
|
TRACE_INFO("DFU: updstatus()\n\r");
|
||||||
|
|
||||||
@@ -446,7 +446,7 @@ void USBDFU_Initialize(const USBDDriverDescriptors *pDescriptors)
|
|||||||
USBDDriver_Initialize(&usbdDriver, pDescriptors, if_altsettings);
|
USBDDriver_Initialize(&usbdDriver, pDescriptors, if_altsettings);
|
||||||
|
|
||||||
USBD_Init();
|
USBD_Init();
|
||||||
USBD_ConfigureSpeed(1);
|
//USBD_ConfigureSpeed(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBDFU_SwitchToApp(void)
|
void USBDFU_SwitchToApp(void)
|
||||||
|
|||||||
10
firmware/libboard/common/include/manifest.h
Normal file
10
firmware/libboard/common/include/manifest.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
#ifndef _MANIFEST_H
|
||||||
|
#define _MANIFEST_H
|
||||||
|
|
||||||
|
extern const char *manifest_application;
|
||||||
|
extern const char *manifest_revision;
|
||||||
|
extern const char *manifest_board;
|
||||||
|
extern const char *manifest_environment;
|
||||||
|
|
||||||
|
#endif /* !_MANIFEST_H */
|
||||||
140
firmware/libboard/common/resources/sam3s4/dfu.ld
Normal file
140
firmware/libboard/common/resources/sam3s4/dfu.ld
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* ATMEL Microcontroller Software Support
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
* Copyright (c) 2009, Atmel Corporation
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* - Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the disclaimer below.
|
||||||
|
*
|
||||||
|
* Atmel's name may not be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||||
|
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||||
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Linker script for running in internal FLASH on the ATSAM3S4
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||||
|
OUTPUT_ARCH(arm)
|
||||||
|
SEARCH_DIR(.)
|
||||||
|
|
||||||
|
/* Memory Spaces Definitions */
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
rom (rx) : ORIGIN = 0x00404000, LENGTH = 0x0003c000 /* flash, 256K */
|
||||||
|
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x0000c000 /* sram, 48K */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Section Definitions */
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
.text :
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
_sfixed = .;
|
||||||
|
KEEP(*(.vectors .vectors.*))
|
||||||
|
*(.text .text.* .gnu.linkonce.t.*)
|
||||||
|
*(.glue_7t) *(.glue_7)
|
||||||
|
*(.rodata .rodata* .gnu.linkonce.r.*)
|
||||||
|
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||||
|
|
||||||
|
/* Support C constructors, and C destructors in both user code
|
||||||
|
and the C library. This also provides support for C++ code. */
|
||||||
|
. = ALIGN(4);
|
||||||
|
KEEP(*(.init))
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
|
||||||
|
. = ALIGN(0x4);
|
||||||
|
KEEP (*crtbegin.o(.ctors))
|
||||||
|
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||||
|
KEEP (*(SORT(.ctors.*)))
|
||||||
|
KEEP (*crtend.o(.ctors))
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
KEEP(*(.fini))
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
|
||||||
|
KEEP (*crtbegin.o(.dtors))
|
||||||
|
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||||
|
KEEP (*(SORT(.dtors.*)))
|
||||||
|
KEEP (*crtend.o(.dtors))
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
_efixed = .; /* End of text section */
|
||||||
|
} > rom
|
||||||
|
|
||||||
|
/* .ARM.exidx is sorted, so has to go in its own output section. */
|
||||||
|
PROVIDE_HIDDEN (__exidx_start = .);
|
||||||
|
.ARM.exidx :
|
||||||
|
{
|
||||||
|
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||||
|
} > rom
|
||||||
|
PROVIDE_HIDDEN (__exidx_end = .);
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
_etext = .;
|
||||||
|
|
||||||
|
.relocate : AT (_etext)
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
_srelocate = .;
|
||||||
|
*(.ramfunc .ramfunc.*);
|
||||||
|
*(.data .data.*);
|
||||||
|
. = ALIGN(4);
|
||||||
|
_erelocate = .;
|
||||||
|
} > ram
|
||||||
|
|
||||||
|
/* .bss section which is used for uninitialized data */
|
||||||
|
.bss (NOLOAD) :
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
_sbss = . ;
|
||||||
|
_szero = .;
|
||||||
|
*(.bss .bss.*)
|
||||||
|
*(COMMON)
|
||||||
|
. = ALIGN(4);
|
||||||
|
_ebss = . ;
|
||||||
|
_ezero = .;
|
||||||
|
} > ram
|
||||||
|
|
||||||
|
/* stack section */
|
||||||
|
.stack (NOLOAD):
|
||||||
|
{
|
||||||
|
. = ALIGN(8);
|
||||||
|
*(.stack .stack.*)
|
||||||
|
} > ram
|
||||||
|
|
||||||
|
. = ALIGN(4);
|
||||||
|
_end = . ;
|
||||||
|
}
|
||||||
7
firmware/libboard/common/source/manifest.c
Normal file
7
firmware/libboard/common/source/manifest.c
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
#include "manifest.h"
|
||||||
|
|
||||||
|
const char *manifest_application = APPLICATION;
|
||||||
|
const char *manifest_revision = GIT_VERSION;
|
||||||
|
const char *manifest_board = BOARD;
|
||||||
|
const char *manifest_environment = ENVIRONMENT;
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "chip.h"
|
#include "chip.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
static const Pin pins_cardsim[] = PINS_CARDSIM;
|
static const Pin pins_cardsim[] = PINS_CARDSIM;
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "chip.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
#include "req_ctx.h"
|
#include "req_ctx.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user