From 7ea6e2089a33b7c5242ded12e95fa75ff1883a43 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 14 Oct 2010 17:08:09 +0900 Subject: [PATCH] Added configure and DFU support. --- ChangeLog | 15 ++++ NEWS | 11 +++ README | 13 ++-- THANKS | 1 + boards/OLIMEX_STM32_H103/board.c | 15 +--- boards/STM32_PRIMER2/board.c | 15 +--- boards/common/hwinit0.c | 9 +++ boards/common/hwinit1.c | 14 ++++ src/{Makefile => Makefile.in} | 13 ++-- src/{config.h => config.h.in} | 3 + src/configure | 113 +++++++++++++++++++++++++++++++ src/{gnuk.ld => gnuk.ld.in} | 2 +- 12 files changed, 184 insertions(+), 40 deletions(-) create mode 100644 boards/common/hwinit0.c create mode 100644 boards/common/hwinit1.c rename src/{Makefile => Makefile.in} (97%) rename src/{config.h => config.h.in} (89%) create mode 100755 src/configure rename src/{gnuk.ld => gnuk.ld.in} (98%) diff --git a/ChangeLog b/ChangeLog index 7858222..de1813f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2010-10-14 NIIBE Yutaka + + Adding 'configure' support. + * src/configure: New file. + * src/Makefile.in: Renamed from src/Makefile. + * src/config.h: Renamed from src/config.h. + * src/gnuk.ld: Renamed from src/gnuk.ld. + + Adding DFU_SUPPORT. + * boards/common/hwinit0.c: New file adding DFU_SUPPORT. + * boards/common/hwinit1.c: New file. + * boards/OLIMEX_STM32_H103/board.c: Include config.h. + Use common/hwinit0.c and common/hwinit1.c. + * boards/STM32_PRIMER2/board.c: Likewise. + 2010-09-16 NIIBE Yutaka * src/usb-icc.c (icc_error): New function. diff --git a/NEWS b/NEWS index 867886d..9fdc3fa 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,16 @@ Gnuk NEWS - User visible changes +* Major changes in Gnuk 0.3 + + Released 2010-10-XX, by NIIBE Yutaka + +** Now we have 'configure' script to select target. + +** Support system with DFU (Device Firmware Upgrade) downloader. + +** Improved USB-ICCD implementation. Works fine with GPG's protocol stack. + + * Major changes in Gnuk 0.2 Released 2010-09-13, by NIIBE Yutaka diff --git a/README b/README index c8dfdee..d898749 100644 --- a/README +++ b/README @@ -50,7 +50,7 @@ It is known not-working well: * Changing value of password status bytes (0x00C4). - * For some version of kernel and libccid, ENABLE_DEBUG=1 can't + * For some version of kernel and libccid, --enable-debug can't work well. Please disable DEBUG option if it doesn't work well. @@ -134,14 +134,13 @@ You need GNU toolchain and newlib for 'arm-none-eabi' target. See http://github.com/esden/summon-arm-toolchain/ for preparation of GNU Toolchain for 'arm-none-eabi' target. +Change directory to `src': + $ cd gnuk-VERSION/src -Edit the Makefile. Comment out the line: ----------------- -ENABLE_DEBUG=1 ----------------- +Then, run `configure': -if you don't want to debug Gnuk. + $ ./configure Type: @@ -173,7 +172,7 @@ Then, with another terminal, type following to write "gnuk.elf" to Flash ROM: > exit $ -If you compiled with ENABLE_DEBUG=1, Gnuk has two interfaces +If you compiled with --enable-debug option, Gnuk has two interfaces (one is CCID/ICCD device and another is virtual COM port). Open virtual COM port by: diff --git a/THANKS b/THANKS index 6c7b619..42e1131 100644 --- a/THANKS +++ b/THANKS @@ -5,6 +5,7 @@ Gnuk was originally written by NIIBE Yutaka. People contributed by encouraging the development, testing the implementation, suggesting improvements, or fixing bugs. Here is a list of those people. +Hironobu SUZUKI hironobu@h2np.net Jan Sur jan@suhr.info Kaz Kojima kkojima@rr.iij4u.or.jp NAGAMI Takeshi nagami-takeshi@aist.go.jp diff --git a/boards/OLIMEX_STM32_H103/board.c b/boards/OLIMEX_STM32_H103/board.c index ae47ec9..5f00d74 100644 --- a/boards/OLIMEX_STM32_H103/board.c +++ b/boards/OLIMEX_STM32_H103/board.c @@ -24,6 +24,7 @@ for full details of how and when the exception can be applied. */ +#include "config.h" #include "ch.h" #include "hal.h" @@ -33,8 +34,7 @@ * segments initialization. */ void hwinit0(void) { - - stm32_clock_init(); +#include "../common/hwinit0.c" } /* @@ -43,14 +43,5 @@ void hwinit0(void) { * and before invoking the main() function. */ void hwinit1(void) { - - /* - * HAL initialization. - */ - halInit(); - - /* - * ChibiOS/RT initialization. - */ - chSysInit(); +#include "../common/hwinit1.c" } diff --git a/boards/STM32_PRIMER2/board.c b/boards/STM32_PRIMER2/board.c index 2be0e93..56969d3 100644 --- a/boards/STM32_PRIMER2/board.c +++ b/boards/STM32_PRIMER2/board.c @@ -24,6 +24,7 @@ for full details of how and when the exception can be applied. */ +#include "config.h" #include "ch.h" #include "hal.h" @@ -33,8 +34,7 @@ * segments initialization. */ void hwinit0(void) { - - stm32_clock_init(); +#include "../common/hwinit0.c" } /* @@ -43,16 +43,7 @@ void hwinit0(void) { * and before invoking the main() function. */ void hwinit1(void) { - - /* - * HAL initialization. - */ - halInit(); - - /* - * ChibiOS/RT initialization. - */ - chSysInit(); +#include "../common/hwinit1.c" /* * Clear LED and SHUTDOWN output. diff --git a/boards/common/hwinit0.c b/boards/common/hwinit0.c new file mode 100644 index 0000000..642019e --- /dev/null +++ b/boards/common/hwinit0.c @@ -0,0 +1,9 @@ +/* + * Common code for hwinit0 + */ + +#ifdef DFU_SUPPORT + SCB->VTOR = 0x08003000; +#endif + + stm32_clock_init(); diff --git a/boards/common/hwinit1.c b/boards/common/hwinit1.c new file mode 100644 index 0000000..aae1029 --- /dev/null +++ b/boards/common/hwinit1.c @@ -0,0 +1,14 @@ +/* + * Common code for hwinit1 + * + */ + + /* + * HAL initialization. + */ + halInit(); + + /* + * ChibiOS/RT initialization. + */ + chSysInit(); diff --git a/src/Makefile b/src/Makefile.in similarity index 97% rename from src/Makefile rename to src/Makefile.in index 8cec464..22267fb 100644 --- a/src/Makefile +++ b/src/Makefile.in @@ -1,8 +1,6 @@ # Makefile for Gnuk -# -ENABLE_DEBUG=1 - +@DEBUG_MAKE_OPTION@ ifneq ($(ENABLE_DEBUG),) ENABLE_VCOMPORT=1 endif @@ -73,7 +71,7 @@ include $(CHIBIOS)/os/kernel/kernel.mk include stmusb.mk include vcomport.mk include crypt.mk -include ../boards/OLIMEX_STM32_H103/board.mk +include @BOARD_MAKEFILE@ # C sources that can be compiled in ARM or THUMB mode depending on the global # setting. @@ -151,11 +149,7 @@ CPPWARN = -Wall -Wextra # # List all default C defines here, like -D_DEBUG=1 -ifeq ($(ENABLE_DEBUG),) DDEFS = -DCORTEX_USE_BASEPRI=TRUE -else -DDEFS = -DCORTEX_USE_BASEPRI=TRUE -DDEBUG -endif # List all default ASM defines here, like -D_DEBUG=1 DADEFS = @@ -218,3 +212,6 @@ random-data.o: random_bits $@ $(PROJECT).elf: random-data.o + +distclean: clean + -rm -f Makefile gnuk.ld config.h diff --git a/src/config.h b/src/config.h.in similarity index 89% rename from src/config.h rename to src/config.h.in index 3dd0958..b3ae78b 100644 --- a/src/config.h +++ b/src/config.h.in @@ -1,3 +1,4 @@ +@DEBUG_DEFINE@ #ifdef DEBUG #define ENABLE_VIRTUAL_COM_PORT 1 #endif @@ -11,3 +12,5 @@ #endif #define SERIAL_NUMBER_IN_AID 0x00, 0x00, 0x00, 0x01 + +@DFU_DEFINE@ diff --git a/src/configure b/src/configure new file mode 100755 index 0000000..6f6da43 --- /dev/null +++ b/src/configure @@ -0,0 +1,113 @@ +#! /bin/sh + +# +# This file is *NOT* generated by GNU Autoconf, but written by NIIBE Yutaka +# +# Copyright (C) 2010 Free Software Initiative of Japan +# +# This file is a part of Gnuk, a GnuPG USB Token implementation. +# Gnuk is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Gnuk is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Default settings +help=no +target=OLIMEX_STM32_H103 +verbose=no +with_dfu=no +debug=no + +# Process each option +for option; do + case $option in + *=*) optarg=`expr "X$option" : '[^=]*=\(.*\)'` ;; + *) optarg=yes ;; + esac + + case $option in + -h | --help) + help=yes ;; + --target=*) + target=$optarg ;; + -v | --verbose) + verbose=yes ;; + --enable-debug) + debug=yes;; + --disable-debug) + debug=no;; + --with-dfu) + with_dfu=yes ;; + --without-dfu) + with_dfu=no ;; + *) + echo "Unrecognized option \`$option'" >&2 + echo "Try \`$0 --help' for more information." >&2 + exit 1 + ;; + esac +done + +if test "$help" = "yes"; then + cat <&2 + exit 1 +fi + +if test "$debug" = "yes"; then + DEBUG_MAKE_OPTION="ENABLE_DEBUG=1" + DEBUG_DEFINE="#define DEBUG 1" +else + DEBUG_MAKE_OPTION="# ENABLE_DEBUG=1" + DEBUG_DEFINE="#undef DEBUG" +fi + +if test "$with_dfu" = "yes"; then + echo "Configured for DFU" + ORIGIN=0x08003000 + FLASH_SIZE=116k + DFU_DEFINE="#define DFU_SUPPORT 1" +else + echo "Configured for bare system (no-DFU)" + ORIGIN=0x08000000 + FLASH_SIZE=128k + DFU_DEFINE="#undef DFU_SUPPORT" +fi + +sed -e "s%@BOARD_MAKEFILE@%$BOARD_MAKEFILE%" \ + -e "s%@DEBUG_MAKE_OPTION@%$DEBUG_MAKE_OPTION%" \ + < Makefile.in > Makefile +sed -e "s/@ORIGIN@/$ORIGIN/" -e "s/@FLASH_SIZE@/$FLASH_SIZE/" \ + < gnuk.ld.in > gnuk.ld +sed -e "s/@DEBUG_DEFINE@/$DEBUG_DEFINE/" \ + -e "s/@DFU_DEFINE@/$DFU_DEFINE/" \ + < config.h.in > config.h +exit 0 diff --git a/src/gnuk.ld b/src/gnuk.ld.in similarity index 98% rename from src/gnuk.ld rename to src/gnuk.ld.in index c89ee1e..c14c068 100644 --- a/src/gnuk.ld +++ b/src/gnuk.ld.in @@ -32,7 +32,7 @@ __stacks_total_size__ = __main_stack_size__; MEMORY { - flash : org = 0x08000000, len = 128k + flash : org = @ORIGIN@, len = @FLASH_SIZE@ ram : org = 0x20000000, len = 20k }