mirror of
https://salsa.debian.org/gnuk-team/gnuk/gnuk.git
synced 2024-09-21 03:10:08 +00:00
189 lines
4.7 KiB
Bash
Executable File
189 lines
4.7 KiB
Bash
Executable File
#! /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 <http://www.gnu.org/licenses/>.
|
|
|
|
# Default settings
|
|
help=no
|
|
target=OLIMEX_STM32_H103
|
|
verbose=no
|
|
with_dfu=default
|
|
with_fsij=no
|
|
debug=no
|
|
pinpad=no
|
|
|
|
# check /dev/random
|
|
if test ! -e /dev/random; then
|
|
echo "/dev/random is required." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# 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;;
|
|
--enable-pinpad)
|
|
pinpad=yes;;
|
|
--disable-pinpad)
|
|
pinpad=no;;
|
|
--with-dfu)
|
|
with_dfu=yes ;;
|
|
--without-dfu)
|
|
with_dfu=no ;;
|
|
--with-fsij)
|
|
with_fsij=yes ;;
|
|
--without-fsij)
|
|
with_fsij=no ;;
|
|
*)
|
|
echo "Unrecognized option \`$option'" >&2
|
|
echo "Try \`$0 --help' for more information." >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if test "$help" = "yes"; then
|
|
cat <<EOF
|
|
Usage: $0 [OPTION]...
|
|
|
|
Defaults for the options are specified in brackets.
|
|
|
|
Configuration:
|
|
-h, --help display this help and exit [no]
|
|
--target=TARGET specify target [OLIMEX_STM32_H103]
|
|
supported targes are:
|
|
OLIMEX_STM32_H103
|
|
STM32_PRIMER2
|
|
CQ_STARM
|
|
STBEE_MINI
|
|
--enable-debug debug with virtual COM port [no]
|
|
--enable-pinpad PIN input device support [no]
|
|
--with-dfu build image for DFU [<target specific>]
|
|
--with-fsij Use FSIJ serial number [no: random number]
|
|
EOF
|
|
exit 0
|
|
fi
|
|
|
|
BOARD_MAKEFILE=../boards/$target/board.mk
|
|
if test -f $BOARD_MAKEFILE; then
|
|
echo "Configured for target: $target"
|
|
else
|
|
echo "Unsupported target \`$target'" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Flash page size in byte
|
|
FLASH_PAGE_SIZE=1024
|
|
# Flash memory size in KB
|
|
FLASH_SIZE=128
|
|
|
|
# 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
|
|
;;
|
|
STM8S_DISCOVERY)
|
|
FLASH_SIZE=64
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
|
|
# --with-fsij option
|
|
if test "$with_fsij" = "no"; then
|
|
echo "Using random serial number for card AID"
|
|
FSIJ_DEFINE="#undef WITH_FSIJ_SERIAL_NUMBER"
|
|
SERIAL_NUMBER_FOUR_BYTES=`od -t u1 -N 4 /dev/random | sed -n -e '/^0000000/s/^0000000 *//' -e 's/ */,/gp'`
|
|
else
|
|
echo "Using FSIJ assigned serial number for card AID"
|
|
if test "x$MAIL" = "x"; then
|
|
echo "ERROR: Please set MAIL shell variable to select FSIJ serial number" >&2
|
|
exit 1
|
|
fi
|
|
FSIJ_DEFINE="#define WITH_FSIJ_SERIAL_NUMBER 1"
|
|
SERIAL_NUMBER_FOUR_BYTES=`sed -n -e "/^$MAIL/s/^.* \(..\):\(..\):\(..\):\(..\)/0x\1, 0x\2, 0x\3, 0x\4/p" ../FSIJ_SERIAL_NUMBER`
|
|
fi
|
|
|
|
# --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
|
|
echo "Configured for DFU"
|
|
ORIGIN=0x08003000
|
|
FLASH_SIZE=`expr $FLASH_SIZE - 12`
|
|
DFU_DEFINE="#define DFU_SUPPORT 1"
|
|
else
|
|
echo "Configured for bare system (no-DFU)"
|
|
ORIGIN=0x08000000
|
|
DFU_DEFINE="#undef DFU_SUPPORT"
|
|
fi
|
|
|
|
# --enable-pinpad option
|
|
if test "$pinpad" = "yes"; then
|
|
PINPAD_MAKE_OPTION="ENABLE_PINPAD=1"
|
|
PINPAD_DEFINE="#define PINPAD_SUPPORT 1"
|
|
echo "PIN pad option enabled"
|
|
else
|
|
PINPAD_MAKE_OPTION="# ENABLE_PINPAD=1"
|
|
PINPAD_DEFINE="#undef PINPAD_SUPPORT"
|
|
echo "PIN pad option disabled"
|
|
fi
|
|
|
|
sed -e "s%@BOARD_MAKEFILE@%$BOARD_MAKEFILE%" \
|
|
-e "s%@DEBUG_MAKE_OPTION@%$DEBUG_MAKE_OPTION%" \
|
|
-e "s%@PINPAD_MAKE_OPTION@%$PINPAD_MAKE_OPTION%" \
|
|
< Makefile.in > Makefile
|
|
sed -e "s/@ORIGIN@/$ORIGIN/" -e "s/@FLASH_SIZE@/$FLASH_SIZE/" \
|
|
-e "s/@FLASH_PAGE_SIZE@/$FLASH_PAGE_SIZE/" \
|
|
< gnuk.ld.in > gnuk.ld
|
|
sed -e "s/@DEBUG_DEFINE@/$DEBUG_DEFINE/" \
|
|
-e "s/@PINPAD_DEFINE@/$PINPAD_DEFINE/" \
|
|
-e "s/@DFU_DEFINE@/$DFU_DEFINE/" \
|
|
-e "s/@FSIJ_DEFINE@/$FSIJ_DEFINE/" \
|
|
-e "s/@SERIAL_NUMBER_FOUR_BYTES@/$SERIAL_NUMBER_FOUR_BYTES/" \
|
|
< config.h.in > config.h
|
|
exit 0
|