#! /bin/bash # # This file is *NOT* generated by GNU Autoconf, but written by NIIBE Yutaka # # Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015 # 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 vidpid=none target=FST_01 verbose=no with_dfu=default debug=no sys1_compat=yes pinpad=no certdo=no hid_card_change=no # Revision number if test -d ../.git; then REVISION=`git describe --dirty="-modified"` else REVISION=`cat ../VERSION` fi # Process each option for option; do case $option in *=*) optarg=`expr "X$option" : '[^=]*=\(.*\)'` ;; *) optarg=yes ;; esac case $option in -h | --help) help=yes ;; -v | --verbose) verbose=yes ;; --vidpid=*) vidpid=$optarg ;; --target=*) target=$optarg ;; --enable-debug) debug=yes ;; --disable-debug) debug=no ;; --enable-pinpad=*) pinpad=$optarg ;; --disable-pinpad) pinpad=no ;; --enable-certdo) certdo=yes ;; --disable-certdo) certdo=no ;; --enable-hid-card-change) hid_card_change=yes ;; --disable-hid-card-change) hid_card_change=no ;; --enable-sys1-compat) sys1_compat=yes ;; --disable-sys1-compat) sys1_compat=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 <] --target=TARGET specify target [FST_01] supported targets are: FST_01 OLIMEX_STM32_H103 STM32_PRIMER2 STBEE STBEE_MINI MAPLE_MINI CQ_STARM FST_01_00 (unreleased version with 8MHz XTAL) --enable-debug debug with virtual COM port [no] --enable-pinpad=cir PIN entry support [no] --enable-certdo support CERT.3 data object [no] --enable-sys1-compat enable SYS 1.0 compatibility [yes] executable is target dependent --disable-sys1-compat disable SYS 1.0 compatibility [no] executable is target independent but requires SYS 2.0 or newer --with-dfu build image for DFU [] EOF exit 0 fi if test "$vidpid" = "none"; then echo "Please specify Vendor ID and Product ID by --vidpid option." exit 1 fi BOARD_HEADER_FILE=board-`echo $target | tr '_[:upper:]' '-[:lower:]'`.h echo Header file is: $BOARD_HEADER_FILE ln -sf ../chopstx/board/$BOARD_HEADER_FILE board.h # Flash page size in byte FLASH_PAGE_SIZE=1024 # Flash memory size in KiB FLASH_SIZE=128 # Memory size in KiB MEMORY_SIZE=20 # Settings for TARGET case $target in CQ_STARM|STBEE_MINI) if test "$with_dfu" = "default"; then with_dfu=yes; fi ;; STM32_PRIMER2) FLASH_PAGE_SIZE=2048 FLASH_SIZE=512 MEMORY_SIZE=64 ;; STBEE) FLASH_PAGE_SIZE=2048 FLASH_SIZE=512 MEMORY_SIZE=64 if test "$with_dfu" = "default"; then with_dfu=yes; fi ;; STM8S_DISCOVERY) FLASH_SIZE=64 ;; *) ;; esac # --enable-debug option if test "$debug" = "yes"; then DEBUG_MAKE_OPTION="ENABLE_DEBUG=1" DEBUG_DEFINE="#define DEBUG 1" echo "Debug option enabled" else DEBUG_MAKE_OPTION="# ENABLE_DEBUG=1" DEBUG_DEFINE="#undef DEBUG" echo "Debug option disabled" fi # --with-dfu option if test "$with_dfu" = "yes"; then if test "$target" = "FST_01" -o "$target" = "FST_01_00"; then echo "FST-01 doesn't have DFU loader, you should not use --with-dfu." exit 1 fi echo "Configured for DFU" ORIGIN=0x08003000 FLASH_SIZE=`expr $FLASH_SIZE - 12` DFU_DEFINE="#define DFU_SUPPORT 1" HEXOUTPUT_MAKE_OPTION="ENABLE_OUTPUT_HEX=yes" else with_dfu=no echo "Configured for bare system (no-DFU)" ORIGIN=0x08000000 DFU_DEFINE="#undef DFU_SUPPORT" HEXOUTPUT_MAKE_OPTION="" fi # --enable-pinpad option MSC_SIZE="0" TIM_SIZE="0" EXT_SIZE="0" if test "$pinpad" = "no"; then PINPAD_MAKE_OPTION="# ENABLE_PINPAD=" PINPAD_DEFINE="#undef PINPAD_SUPPORT" PINPAD_MORE_DEFINE="" echo "PIN pad option disabled" else PINPAD_MAKE_OPTION="ENABLE_PINPAD=$pinpad" PINPAD_DEFINE="#define PINPAD_SUPPORT 1" PINPAD_MORE_DEFINE="#define PINPAD_${pinpad^^[a-z]}_SUPPORT 1" echo "PIN pad option enabled ($pinpad)" if test "$pinpad" = "dnd"; then MSC_SIZE="0x0200" elif test "$pinpad" = "cir"; then TIM_SIZE="0x00c0" EXT_SIZE="0x00c0" fi fi # --enable-certdo option if test "$certdo" = "yes"; then CERTDO_DEFINE="#define CERTDO_SUPPORT 1" echo "CERT.3 Data Object is supported" else CERTDO_DEFINE="#undef CERTDO_SUPPORT" echo "CERT.3 Data Object is NOT supported" fi # --enable-hid-card-change option if test "$hid_card_change" = "yes"; then HID_CARD_CHANGE_DEFINE="#define HID_CARD_CHANGE_SUPPORT 1" echo "Card insert/removal by HID device is supported" else HID_CARD_CHANGE_DEFINE="#undef HID_CARD_CHANGE_SUPPORT" echo "Card insert/removal by HID device is NOT supported" fi ### !!! Replace following string of "FSIJ" to yours !!! #### SERIALNO="FSIJ-`cat ../VERSION | sed -e 's%^[^/]*/%%'`-" SERIALNO_STR_LEN_DEFINE="#define SERIALNO_STR_LEN ${#SERIALNO}" if test "$sys1_compat" = "yes"; then CONFIG="$target:dfu=$with_dfu:debug=$debug:pinpad=$pinpad:certdo=$certdo" else if test "$with_dfu" = "yes"; then echo "Common binary can't support DFU loader, don't use --with-dfu." exit 1 fi # Override settings for common binary. Safer side. FLASH_PAGE_SIZE=2048 FLASH_SIZE=128 MEMORY_SIZE=20 CONFIG="common:debug=$debug:pinpad=$pinpad:certdo=$certdo" fi output_vid_pid_version () { echo $VIDPID | sed -n -e "s%^\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\):\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\)$% 0x\2, 0x\1, /* idVendor */\n 0x\4, 0x\3, /* idProduct */%p" echo $VERSION | sed -n -e "s%^\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\)$% 0x\2, 0x\1, /* bcdDevice */%p" } output_vendor_product_serial_strings () { prefix=$1 echo "static const uint8_t ${prefix}string_vendor[] = {" echo " ${#VENDOR}*2+2, /* bLength */" echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */" echo " /* Manufacturer: \"$VENDOR\" */" echo $VENDOR | sed -n -e "s/\(........\)/\1\n/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p" echo '};' echo echo "static const uint8_t ${prefix}string_product[] = {" echo " ${#PRODUCT}*2+2, /* bLength */" echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */" echo " /* Product name: \"$PRODUCT\" */" echo $PRODUCT | sed -n -e "s/\(........\)/\1\n/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p" echo '};' if test -n "$prefix"; then echo echo "uint8_t ${prefix}string_serial[] = {" echo " ${#SERIALNO}*2+2+16, /* bLength */" echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */" echo " /* Serial number: \"$SERIALNO\" */" echo $SERIALNO | sed -n -e "s/\(........\)/\1\n/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p" echo " 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff," echo " 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff," echo '};' echo echo '#ifdef USB_STRINGS_FOR_GNUK' echo "static const uint8_t ${prefix}revision_detail[] = {" echo " ${#REVISION}*2+2, /* bLength */" echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */" echo " /* revision detail: \"$REVISION\" */" echo $REVISION | sed -n -e "s/\(........\)/\1\n/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p" echo '};' echo echo "static const uint8_t ${prefix}config_options[] = {" echo " ${#CONFIG}*2+2, /* bLength */" echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */" echo " /* configure options: \"$CONFIG\" */" echo $CONFIG | sed -n -e "s/\(........\)/\1\n/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p" echo '};' echo '#endif' fi } if !(IFS=" " while read VIDPID VERSION PRODUCT VENDOR; do if test "$vidpid" = "$VIDPID"; then output_vid_pid_version > usb-vid-pid-ver.c.inc output_vendor_product_serial_strings gnuk_ >usb-strings.c.inc exit 0 fi done; exit 1) < ../GNUK_USB_DEVICE_ID then echo "Please specify valid Vendor ID and Product ID." echo "Check ../GNUK_USB_DEVICE_ID." exit 1 fi if test "$sys1_compat" = "no"; then # Disable when you are sure that it's sys version 2.1. # Note that Gnuk 1.0 and NeuG (until 0.06) uses sys version 1.0. # Disabling the compatibility, executable will be target independent, # assuming the clock initialization will be done by SYS (before entry). have_sys_h="-DHAVE_SYS_H" else have_sys_h="" fi sed -e "s%@HAVE_SYS_H@%$have_sys_h%" \ -e "s%@DEBUG_MAKE_OPTION@%$DEBUG_MAKE_OPTION%" \ -e "s%@PINPAD_MAKE_OPTION@%$PINPAD_MAKE_OPTION%" \ -e "s%@HEXOUTPUT_MAKE_OPTION@%$HEXOUTPUT_MAKE_OPTION%" \ < Makefile.in > Makefile if test "$certdo" = "yes"; then sed -e "/^@CERTDO_SUPPORT_START@$/ d" -e "/^@CERTDO_SUPPORT_END@$/ d" \ -e "s/@ORIGIN@/$ORIGIN/" -e "s/@FLASH_SIZE@/$FLASH_SIZE/" \ -e "s/@MEMORY_SIZE@/$MEMORY_SIZE/" \ -e "s/@FLASH_PAGE_SIZE@/$FLASH_PAGE_SIZE/" \ -e "s/@MSC_SIZE@/$MSC_SIZE/" \ -e "s/@TIM_SIZE@/$TIM_SIZE/" \ -e "s/@EXT_SIZE@/$EXT_SIZE/" \ < gnuk.ld.in > gnuk.ld else sed -e "/^@CERTDO_SUPPORT_START@$/,/^@CERTDO_SUPPORT_END@$/ d" \ -e "s/@ORIGIN@/$ORIGIN/" -e "s/@FLASH_SIZE@/$FLASH_SIZE/" \ -e "s/@MEMORY_SIZE@/$MEMORY_SIZE/" \ -e "s/@FLASH_PAGE_SIZE@/$FLASH_PAGE_SIZE/" \ -e "s/@MSC_SIZE@/$MSC_SIZE/" \ -e "s/@TIM_SIZE@/$TIM_SIZE/" \ -e "s/@EXT_SIZE@/$EXT_SIZE/" \ < gnuk.ld.in > gnuk.ld fi sed -e "s/@DEBUG_DEFINE@/$DEBUG_DEFINE/" \ -e "s/@DFU_DEFINE@/$DFU_DEFINE/" \ -e "s/@PINPAD_DEFINE@/$PINPAD_DEFINE/" \ -e "s/@PINPAD_MORE_DEFINE@/$PINPAD_MORE_DEFINE/" \ -e "s/@CERTDO_DEFINE@/$CERTDO_DEFINE/" \ -e "s/@HID_CARD_CHANGE_DEFINE@/$HID_CARD_CHANGE_DEFINE/" \ -e "s/@SERIALNO_STR_LEN_DEFINE@/$SERIALNO_STR_LEN_DEFINE/" \ < config.h.in > config.h exit 0