summer restructuring:

* .h include only the strict minimum for their own parsing
  * this forces all files to include explicitment their needs and not count on far streched dependencies
  * this helps Makefile to rebuild only the minimum
  * according to this rule, most standalone .h are now gone
  * big app.h is gone
  * remove seldom __cplusplus, if c++ happens, everything will have to be done properly anyway
* all unrequired include were removed
* split common/ into common/ (client+arm) and common_arm/ (os+bootloader)
  * bring zlib to common/
  * bring stuff not really/not yet used in common back to armsrc/ or client/
  * bring liblua into client/
  * bring uart into client/
  * move some portions of code around (dbprint, protocols,...)
* rename unused files into *_disabled.[ch] to make it explicit
* rename soft Uarts between 14a, 14b and iclass, so a standalone could use several without clash
* remove PrintAndLogDevice
* move deprecated-hid-flasher from client to tools
* Makefiles
  * treat deps in armsrc/ as in client/
  * client: stop on warning (-Werror), same as for armsrc/

Tested on:

* all standalone modes
* Linux
This commit is contained in:
Philippe Teuwen 2019-08-08 16:57:33 +02:00
commit d19754567d
447 changed files with 2553 additions and 2599 deletions

125
common_arm/Makefile.common Normal file
View file

@ -0,0 +1,125 @@
#-----------------------------------------------------------------------------
# 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.
#-----------------------------------------------------------------------------
# Common makefile functions for all platforms
#-----------------------------------------------------------------------------
# This new makefile replaces the previous Makefile/Makefile.linux
# with as much common code for both environments as possible.
# Following is a short OS detection to set up variables, all the
# remaining Makefile should be portable and only depend on these
# variables
#
ifneq ($(V),1)
Q?=@
endif
# To see full command lines, use make V=1
# Make sure that all is the default target
# (The including Makefile still needs to define what 'all' is)
platform = $(shell uname)
all:
CROSS ?= arm-none-eabi-
CC = $(CROSS)gcc
AS = $(CROSS)as
LD = $(CROSS)ld
OBJCOPY = $(CROSS)objcopy
GZIP=gzip
MV=mv
OBJDIR = obj
INCLUDE = -I../include -I../common_arm -I../common -I.
TAR=tar
TARFLAGS = -C .. -rvf
# Windows' echo echos its input verbatim, on Posix there is some
# amount of shell command line parsing going on. echo "" on
# Windows yields literal "", on Linux yields an empty line
ifeq ($(shell echo ""),)
DELETE=rm -rf
MOVE=mv
COPY=cp
PATHSEP=/
FLASH_TOOL=client/flasher
# This is probably a proper system, so we can use uname
DETECTED_OS=$(platform)
else
# Assume that we are running on Windows.
DELETE=del /q
MOVE=ren
COPY=copy
PATHSEP=\\#
FLASH_TOOL=client\\flasher.exe
DETECTED_OS=Windows
endif
# Also search prerequisites in the common directory (for usb.c), the fpga directory (for fpga.bit), and the zlib directory
VPATH = . ../common_arm ../common ../common/crapto1 ../common/mbedtls ../common/zlib ../fpga ../armsrc/Standalone
INCLUDES = ../include/proxmark3_arm.h ../include/at91sam7s512.h ../include/config_gpio.h ../include/pm3_cmd.h
CFLAGS = -c $(INCLUDE) -Wall -Werror -pedantic -Wunused -std=c99 $(APP_CFLAGS) -Os
LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-gc-sections -n
LIBS = -lgcc
# Flags to generate temporary dependency files
DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td
# make temporary to final dependency files after successful compilation
POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d
THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(THUMBSRC)))
ARMOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(ARMSRC)))
ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(notdir $(ASMSRC)))
VERSIONOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(VERSIONSRC)))
$(THUMBOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES)
$(info [-] CC $<)
$(Q)$(CC) $(CFLAGS) $(DEPFLAGS) -mthumb -mthumb-interwork -o $@ $<
$(Q)$(POSTCOMPILE)
$(ARMOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES)
$(info [-] CC $<)
$(Q)$(CC) $(CFLAGS) $(DEPFLAGS) -mthumb-interwork -o $@ $<
$(Q)$(POSTCOMPILE)
$(ASMOBJ): $(OBJDIR)/%.o: %.s
$(info [-] CC $<)
$(Q)$(CC) $(CFLAGS) -mthumb-interwork -o $@ $<
$(VERSIONOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES)
$(info [-] CC $<)
$(Q)$(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $<
# This objcopy call translates physical flash addresses to logical addresses
# without touching start address or RAM addresses (.bss and .data sections)
# See ldscript.common. -- Henryk Plötz <henryk@ploetzli.ch> 2009-08-27
OBJCOPY_TRANSLATIONS = --no-change-warnings \
--change-addresses -0x100000 --change-start 0 \
--change-section-address .bss+0 --change-section-address .data-0x100000 \
--change-section-address .commonarea+0
$(OBJDIR)/%.s19: $(OBJDIR)/%.elf
$(info [=] GEN $@)
$(Q)$(OBJCOPY) -Osrec --srec-forceS3 --strip-debug $(OBJCOPY_TRANSLATIONS) $^ $@
# easy printing of MAKE VARIABLES
print-%: ; @echo $* = $($*)
# Automatic dependency generation
DEPENDENCY_FILES = $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(THUMBSRC))) \
$(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(ARMSRC))) \
$(patsubst %.s,$(OBJDIR)/%.d,$(notdir $(ASMSRC)))
$(DEPENDENCY_FILES): Makefile ../common_arm/Makefile.common
.PRECIOUS: $(DEPENDENCY_FILES)
-include $(DEPENDENCY_FILES)

183
common_arm/Makefile.hal Normal file
View file

@ -0,0 +1,183 @@
# Default platform if no platform specified
PLATFORM?=PM3RDV4
# Standalone Mode info (path depends if make is called at top or from armsrc)
# Guard Makefile.hal against implicit rules: (with % to avoid being first goal)
%/Makefile.hal: ;
-include armsrc/Standalone/Makefile.hal
-include Standalone/Makefile.hal
ifndef DEFAULT_STANDALONE
$(error Could not find armsrc/Standalone/Makefile.hal)
endif
define KNOWN_PLATFORM_DEFINITIONS
Known definitions:
+==========================================================+
| PLATFORM | DESCRIPTION |
+==========================================================+
| PM3RDV4 (def) | Proxmark3 rdv4 with AT91SAM7S512 |
+----------------------------------------------------------+
| PM3EVO | Proxmark3 EVO with AT91SAM7S512 |
+----------------------------------------------------------+
| PM3EASY | Proxmark3 rdv3 Easy with AT91SAM7S256 |
+----------------------------------------------------------+
| PM3RDV2 | Proxmark3 rdv2 with AT91SAM7S512 |
+----------------------------------------------------------+
| PM3OLD256 | Proxmark3 V1 with AT91SAM7S256 |
+----------------------------------------------------------+
| PM3OLD512 | Proxmark3 V1 with AT91SAM7S512 |
+----------------------------------------------------------+
+==========================================================+
| PLATFORM_EXTRAS | DESCRIPTION |
+==========================================================+
| BTADDON | Proxmark3 rdv4 BT add-on |
+----------------------------------------------------------+
endef
define HELP_DEFINITIONS
Options to define platform, platform extras and/or standalone mode:
(1) Run make with PLATFORM, PLATFORM_EXTRAS and/or STANDALONE as follows:
make PLATFORM=PM3EASY STANDALONE=$(HELP_EXAMPLE_STANDALONE)
(2) Save a file called Makefile.platform with contents:
PLATFORM=PM3EASY
or if you have a Proxmark 3 RDV4 with the BT add-on:
PLATFORM=PM3RDV4
PLATFORM_EXTRAS=BTADDON
Default standalone mode is $(DEFAULT_STANDALONE).
To disable standalone modes, set explicitly an empty STANDALONE:
STANDALONE=
endef
define KNOWN_DEFINITIONS
$(KNOWN_PLATFORM_DEFINITIONS)
$(KNOWN_STANDALONE_DEFINITIONS)
$(HELP_DEFINITIONS)
endef
PLTNAME = Unknown Platform
ifeq ($(PLATFORM),PM3RDV4)
MCU = AT91SAM7S512
PLATFORM_DEFS = -DWITH_SMARTCARD -DWITH_FLASH
PLTNAME = Proxmark3 rdv4
else ifeq ($(PLATFORM),PM3EVO)
MCU = AT91SAM7S512
PLTNAME = Proxmark3 EVO
else ifeq ($(PLATFORM),PM3EASY)
MCU = AT91SAM7S256
PLTNAME = Proxmark3 rdv3 Easy
else ifeq ($(PLATFORM),PM3RDV2)
MCU = AT91SAM7S512
PLTNAME = Proxmark3 rdv2
else ifeq ($(PLATFORM),PM3OLD256)
MCU = AT91SAM7S256
PLTNAME = Proxmark3 V1 with AT91SAM7S256
else ifeq ($(PLATFORM),PM3OLD512)
MCU = AT91SAM7S512
PLTNAME = Proxmark3 V1 with AT91SAM7S512
else
$(error Invalid or empty PLATFORM: $(PLATFORM). $(KNOWN_DEFINITIONS))
endif
# parsing additional PLATFORM_EXTRAS tokens
PLATFORM_EXTRAS_TMP:=$(PLATFORM_EXTRAS)
ifneq (,$(findstring BTADDON,$(PLATFORM_EXTRAS_TMP)))
PLATFORM_DEFS += -DWITH_FPC_USART_HOST
PLATFORM_EXTRAS_TMP := $(strip $(filter-out BTADDON,$(PLATFORM_EXTRAS_TMP)))
endif
ifneq (,$(findstring FPC_USART_DEV,$(PLATFORM_EXTRAS_TMP)))
PLATFORM_DEFS += -DWITH_FPC_USART_DEV
PLATFORM_EXTRAS_TMP := $(strip $(filter-out FPC_USART_DEV,$(PLATFORM_EXTRAS_TMP)))
endif
ifneq (,$(PLATFORM_EXTRAS_TMP))
$(error Unknown PLATFORM_EXTRAS token(s): $(PLATFORM_EXTRAS_TMP))
endif
# common LF support
PLATFORM_DEFS += \
-DWITH_LF \
-DWITH_HITAG
# common HF support
PLATFORM_DEFS += \
-DWITH_ISO15693 \
-DWITH_LEGICRF \
-DWITH_ISO14443b \
-DWITH_ISO14443a \
-DWITH_ICLASS \
-DWITH_FELICA \
-DWITH_NFCBARCODE \
-DWITH_HFSNIFF
# Standalone mode
ifneq ($(strip $(filter $(PLATFORM_DEFS),$(STANDALONE_REQ_DEFS))),$(strip $(STANDALONE_REQ_DEFS)))
$(error Chosen Standalone mode $(STANDALONE) requires $(strip $(STANDALONE_REQ_DEFS)), unsupported by $(PLTNAME))
endif
PLATFORM_DEFS+=$(STANDALONE_PLATFORM_DEFS)
$(info $(findstring WITH_STANDALONE_*,$(PLATFORM_DEFS)))
# Misc
#PLATFORM_DEFS += -DWITH_LCD
# Add flags dependencies :
# WITH_FPC_USART_* needs WITH_FPC_USART :
ifneq (,$(findstring WITH_FPC_USART_,$(PLATFORM_DEFS)))
PLATFORM_DEFS += -DWITH_FPC_USART
endif
PLATFORM_DEFS_INFO = $(strip $(filter-out STANDALONE%, $(subst -DWITH_,,$(PLATFORM_DEFS))))
PLATFORM_DEFS_INFO_STANDALONE = $(strip $(subst STANDALONE_,, $(filter STANDALONE%, $(subst -DWITH_,,$(PLATFORM_DEFS)))))
# Check that only one Standalone mode has been chosen
ifneq (,$(word 2, $(PLATFORM_DEFS_INFO_STANDALONE)))
$(error You must choose only one Standalone mode!: $(PLATFORM_DEFS_INFO_STANDALONE))
endif
PLATFORM_EXTRAS_INFO = $(PLATFORM_EXTRAS)
# info when no extra
ifeq (,$(PLATFORM_EXTRAS_INFO))
PLATFORM_EXTRAS_INFO = No extra selected
endif
# info when no standalone mode
ifeq (,$(PLATFORM_DEFS_INFO_STANDALONE))
PLATFORM_DEFS_INFO_STANDALONE = No standalone mode selected
endif
PLATFORM_CHANGED=false
ifneq ($(PLATFORM), $(CACHED_PLATFORM))
PLATFORM_CHANGED=true
else ifneq ($(PLATFORM_EXTRAS), $(CACHED_PLATFORM_EXTRAS))
PLATFORM_CHANGED=true
else ifneq ($(PLATFORM_DEFS), $(CACHED_PLATFORM_DEFS))
PLATFORM_CHANGED=true
endif
export PLATFORM
export PLATFORM_EXTRAS
export PLATFORM_EXTRAS_INFO
export PLTNAME
export MCU
export PLATFORM_DEFS
export PLATFORM_DEFS_INFO
export PLATFORM_DEFS_INFO_STANDALONE
export PLATFORM_CHANGED
$(info ===================================================================)
$(info Platform name: $(PLTNAME))
$(info PLATFORM: $(PLATFORM))
$(info Platform extras: $(PLATFORM_EXTRAS_INFO))
$(info Included options: $(PLATFORM_DEFS_INFO))
$(info Standalone mode: $(PLATFORM_DEFS_INFO_STANDALONE))
$(info ===================================================================)

View file

@ -0,0 +1,9 @@
#include "proxmark3_arm.h"
/* This is the default version.c file that Makefile.common falls back to if perl is not available */
const struct version_information __attribute__((section(".version_information"))) version_information = {
VERSION_INFORMATION_MAGIC,
1, /* version 1 */
0, /* version information not present */
2, /* cleanliness couldn't be determined */
/* Remaining fields: zero */
};

View file

@ -0,0 +1,32 @@
/*
-----------------------------------------------------------------------------
This code is licensed to you under the ter
ms of the GNU GPL, version 2 or,
at your option, any later version. See the LICENSE.txt file for the text of
the license.
-----------------------------------------------------------------------------
Common linker script
-----------------------------------------------------------------------------
*/
/* AT91SAM7S256 has 256k Flash and 64k RAM */
/* AT91SAM7S512 has 512k Flash and 64k RAM */
/* boot space = 8192bytes (0x2000) */
/* osimage space = (512k - 0x2000 == 524288 - 8192 == 516096bytes == 0x7E000 ) */
MEMORY
{
bootphase1 : ORIGIN = 0x00100000, LENGTH = 0x200 /* Phase 1 bootloader: Copies real bootloader to RAM */
bootphase2 : ORIGIN = 0x00100200, LENGTH = 0x2000 - 0x200 /* Main bootloader code, stored in Flash, executed from RAM */
osimage : ORIGIN = 0x00102000, LENGTH = 512K - 0x2000 /* Place where the main OS will end up */
ram : ORIGIN = 0x00200000, LENGTH = 64K - 0x20 /* RAM, minus small common area */
commonarea : ORIGIN = 0x00200000 + 64K - 0x20, LENGTH = 0x20 /* Communication between bootloader and main OS */
}
/* Export some information that can be used from within the firmware */
_bootphase1_version_pointer = ORIGIN(bootphase1) + LENGTH(bootphase1) - 0x4;
_osimage_entry = ORIGIN(osimage);
_bootrom_start = ORIGIN(bootphase1);
_bootrom_end = ORIGIN(bootphase2) + LENGTH(bootphase2);
_flash_start = ORIGIN(bootphase1);
_flash_end = ORIGIN(osimage) + LENGTH(osimage);
_stack_end = ORIGIN(ram) + LENGTH(ram) - 8;

1014
common_arm/usb_cdc.c Normal file

File diff suppressed because it is too large Load diff

60
common_arm/usb_cdc.h Normal file
View file

@ -0,0 +1,60 @@
/*
* at91sam7s USB CDC device implementation
*
* Copyright (c) 2012, Roel Verdult
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS 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.
*
* based on the "Basic USB Example" from ATMEL (doc6123.pdf)
*
* @file usb_cdc.c
* @brief
*/
#ifndef _USB_CDC_H_
#define _USB_CDC_H_
#include "common.h"
#include "at91sam7s512.h"
void usb_disable(void);
void usb_enable(void);
bool usb_check(void);
bool usb_poll(void);
bool usb_poll_validate_length(void);
uint32_t usb_read(uint8_t *data, size_t len);
int usb_write(const uint8_t *data, const size_t len);
uint32_t usb_read_ng(uint8_t *data, size_t len);
void SetUSBreconnect(int value);
int GetUSBreconnect(void);
void SetUSBconfigured(int value);
int GetUSBconfigured(void);
void AT91F_USB_SendData(AT91PS_UDP pUdp, const char *pData, uint32_t length);
void AT91F_USB_SendZlp(AT91PS_UDP pUdp);
void AT91F_USB_SendStall(AT91PS_UDP pUdp);
void AT91F_CDC_Enumerate(void);
#endif // _USB_CDC_H_