From 7bfe0f54273b1ee2f7f2eb7fa89c3d8310801094 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 19 Jan 2018 22:22:29 +0900 Subject: [PATCH] Add binary-edit.sh. --- ChangeLog | 2 ++ NEWS | 16 ++++++++++ src/binary-edit.sh | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 src/binary-edit.sh diff --git a/ChangeLog b/ChangeLog index 281b72b..a874c2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2018-01-19 NIIBE Yutaka + * src/binary-edit.sh: Copied from NeuG 1.0.8. + * chopstx: Update to 1.8. 2018-01-18 NIIBE Yutaka diff --git a/NEWS b/NEWS index 78ca5ea..6df988e 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,21 @@ Gnuk NEWS - User visible changes +* Major changes in Gnuk 1.2.8 + + Released 2018-01-2X, by NIIBE Yutaka + +** No inclusion of VID:PID in gnuk.elf + +Distribution of binary image with VID:PID would violate vendor ID +agreement to USB Forum. Now, we have new file named gnuk-vidpid.elf +for flashing. The file gnuk.elf can be used to generate +gnuk-vidpid.elf and we can check if it is reproducible or not. + + +** Upgrade of Chopstx +We use Chopstx 1.8. + + * Major changes in Gnuk 1.2.7 Released 2017-11-26, by NIIBE Yutaka diff --git a/src/binary-edit.sh b/src/binary-edit.sh new file mode 100644 index 0000000..26acba0 --- /dev/null +++ b/src/binary-edit.sh @@ -0,0 +1,79 @@ +# 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 +# FOFF=0x000110f0 +# ADDR=0x08005ad0 +# file_off_ADDR = ADDR - VMA + FOFF +# = 0x08005ad0 - 0x080010f0 + 0x000110f0 = 0x00015ad0 + +function calc_addr () { + local line_sym="" VMA FOFF ADDR + + arm-none-eabi-objdump -h -t -j .text $FILE | \ + egrep -e '(^ +[0-9] +\.text +|device_desc)' | \ + while read -r F0 F1 F2 F3 F4 F5 F6; do + if [ -z "$line_sym" ]; then + VMA=$F3 + FOFF=$F5 + line_sym="next is a line for the symbol" + else + ADDR=$F0 + echo "$((0x$ADDR - 0x$VMA + 0x$FOFF))" + fi + done +} + +declare -a OFFSETS +OFFSETS=($(calc_addr)) +file_off_ADDR=${OFFSETS[0]} +file_off_fraucheky_ADDR=${OFFSETS[1]} + +echo "Offset is $file_off_ADDR" +if [ -n "$file_off_fraucheky_ADDR" ]; then + echo "Offset is $file_off_fraucheky_ADDR" +fi + +function replace_file_byte_at () { + printf "\x$1" | dd of=$FILE bs=1 seek=$2 conv=notrunc >& /dev/null +} + +# +# vid_lsb: 8 +# vid_msb: 9 +# pid_lsb: 10 +# pid_msb: 11 +# bcd_device_lsb: 12 +# bcd_device_msb: 13 +# + +function replace_vid_lsb () { + replace_file_byte_at $1 $((addr + 8)) +} + +function replace_vid_msb () { + replace_file_byte_at $1 $((addr + 9)) +} + +function replace_pid_lsb () { + replace_file_byte_at $1 $((addr + 10)) +} + +function replace_pid_msb () { + replace_file_byte_at $1 $((addr + 11)) +} + +function replace_bcd_device_lsb () { + replace_file_byte_at $1 $((addr + 12)) +} + +function replace_bcd_device_msb () { + replace_file_byte_at $1 $((addr + 13)) +}