From de246559201b455a06961fe2ab26244687282b2a Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 19 Jan 2018 22:36:01 +0900 Subject: [PATCH] VIDPID substitution at the last stage of build. --- .gitignore | 1 + ChangeLog | 5 ++++- src/Makefile | 8 +++++++- src/binary-edit.sh | 3 --- src/configure | 39 +++++++++++++++++++++++++++++++++++---- src/usb_desc.c | 4 +++- 6 files changed, 50 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 5e0e382..0e065f6 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ src/gnuk.ld src/board.h src/build/* src/*.inc +src/put-vid-pid-ver.sh regnual/regnual.bin regnual/regnual.hex regnual/regnual.elf diff --git a/ChangeLog b/ChangeLog index a874c2f..63d951a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ 2018-01-19 NIIBE Yutaka - * src/binary-edit.sh: Copied from NeuG 1.0.8. + * src/binary-edit.sh: Copied from NeuG 1.0.8. Exclude FILE. + * src/configure (output_vid_pid_version): Generate a shell script. + * src/Makefile (build/gnuk-vidpid.elf): New target. + * src/usb_desc.c (device_desc): Make this array as a template. * chopstx: Update to 1.8. diff --git a/src/Makefile b/src/Makefile index 5c728e6..a321d04 100644 --- a/src/Makefile +++ b/src/Makefile @@ -76,7 +76,13 @@ distclean: clean -rm -f gnuk.ld config.h board.h config.mk \ usb-strings.c.inc usb-vid-pid-ver.c.inc -ifneq ($(EMULATION),) +ifeq ($(EMULATION),) +build/gnuk-vidpid.elf: build/gnuk.elf binary-edit.sh put-vid-pid-ver.sh + cp -p build/gnuk.elf build/gnuk-vidpid.elf + bash put-vid-pid-ver.sh + $(OBJCOPY) -O ihex build/gnuk-vidpid.elf build/gnuk-vidpid.hex + $(OBJCOPY) -O binary build/gnuk-vidpid.elf build/gnuk-vidpid.bin +else # By specifying DESTDIR on invocation of "make", you can install # program to different ROOT. diff --git a/src/binary-edit.sh b/src/binary-edit.sh index 26acba0..83ace3f 100644 --- a/src/binary-edit.sh +++ b/src/binary-edit.sh @@ -1,11 +1,8 @@ # This is a Bash script to be included. -FILE="build/neug-vidpid.elf" - # Idx Name Size VMA LMA File off Algn # ================= # 2 .text 00004a40 080010f0 080010f0 000110f0 2**4 -# 08006500 l O .text 00000012 vcom_device_desc # 08006550 l O .text 00000012 device_desc # ================= # VMA =0x080010f0 diff --git a/src/configure b/src/configure index 09925e2..ebc11ff 100755 --- a/src/configure +++ b/src/configure @@ -6,7 +6,7 @@ nl=$'\n' # # This file is *NOT* generated by GNU Autoconf, but written by NIIBE Yutaka # -# Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 +# Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 # Free Software Initiative of Japan # # This file is a part of Gnuk, a GnuPG USB Token implementation. @@ -327,8 +327,32 @@ else 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 */\\${nl} 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" + 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]\)$%\1\t\2\t\3\t\4%p" | \ + while read -r FIRST SECOND THIRD FOURTH; do + if test $FIRST != 00; then + echo replace_vid_msb $FIRST + fi + if test $SECOND != 00; then + echo replace_vid_lsb $SECOND + fi + if test $THIRD != 00; then + echo replace_pid_msb $THIRD + fi + if test $FOURTH != 00; then + echo replace_pid_lsb $FOURTH + fi + done + echo "$VERSION" | \ + sed -n -e "s%^\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\)$%\1\t\2%p" | \ + while read -r FIRST SECOND; do + if test $FIRST != 00; then + echo replace_bcd_device_msb $FIRST + fi + if test $SECOND != 00; then + echo replace_bcd_device_lsb $SECOND + fi + done } output_vendor_product_serial_strings () { @@ -382,10 +406,17 @@ output_vendor_product_serial_strings () { fi } +(echo "#! /bin/bash" + echo + echo 'FILE="build/gnuk-vidpid.elf"' + echo '. "binary-edit.sh"') > put-vid-pid-ver.sh + if !(IFS=" " while read -r VIDPID VERSION PRODUCT VENDOR; do if test "$vidpid" = "$VIDPID"; then - output_vid_pid_version > usb-vid-pid-ver.c.inc + echo >> put-vid-pid-ver.sh + echo 'addr=$file_off_ADDR' >> put-vid-pid-ver.sh + output_vid_pid_version >> put-vid-pid-ver.sh output_vendor_product_serial_strings gnuk_ >usb-strings.c.inc exit 0 fi diff --git a/src/usb_desc.c b/src/usb_desc.c index 2995acc..d568d36 100644 --- a/src/usb_desc.c +++ b/src/usb_desc.c @@ -70,7 +70,9 @@ uint8_t device_desc[] = { 0x00, /* bDeviceSubClass */ 0x00, /* bDeviceProtocol */ 0x40, /* bMaxPacketSize0 */ -#include "usb-vid-pid-ver.c.inc" + 0x00, 0x00, /* idVendor (will be replaced) */ + 0x00, 0x00, /* idProduct (will be replaced) */ + 0x00, 0x00, /* bcdDevice (will be replaced) */ 1, /* Index of string descriptor describing manufacturer */ 2, /* Index of string descriptor describing product */ 3, /* Index of string descriptor describing the device's serial number */