blob: b4c43d0b7da397e310cae1ca2d7198365bf4bc0f [file] [log] [blame]
Stefan Reinauer0ce691f2012-08-03 14:20:24 -07001#!/bin/bash
2#
Stefan Reinauer489da9f2018-10-09 10:45:19 -07003# Copyright 2012 Google Inc.
Stefan Reinauer0ce691f2012-08-03 14:20:24 -07004#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; version 2 of the License.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
Stefan Reinauer0ce691f2012-08-03 14:20:24 -070014
Stefan Reinauer21b60e62020-11-16 12:03:50 -080015URL="https://www.dediprog.com/download/save/78.msi"
Stefan Reinauer0ce691f2012-08-03 14:20:24 -070016
17if ! which curl > /dev/null; then
18 echo "Install curl to run this script."
19 exit 1;
20fi
Stefan Reinauerdcf351f2018-01-22 14:48:57 -080021if ! which msiextract > /dev/null; then
22 echo "Install msitools (https://wiki.gnome.org/msitools) to run this script."
Stefan Reinauer0ce691f2012-08-03 14:20:24 -070023 exit 1
24fi
Stefan Reinauer0ce691f2012-08-03 14:20:24 -070025
Stefan Reinauerddb30012018-10-09 10:43:49 -070026FILE=EM100Pro.msi
Vadim Bendebury16f048e2013-09-24 11:00:58 -070027TEMP=$(mktemp -d /tmp/makech.XXXXXX)
Stefan Reinauer3f66bc62019-11-30 16:39:47 -080028WD=$(cd "$(dirname `eval echo "$0"`)"; pwd)
Stefan Reinauerc57d9af2019-11-22 00:31:13 -080029TD=$WD/em100_home
Stefan Reinauer0ce691f2012-08-03 14:20:24 -070030
31cd $TEMP
Stefan Reinauer8a6e3412012-10-18 09:51:50 -070032if [ -r $WD/$FILE ]; then
Stefan Reinauerdcf351f2018-01-22 14:48:57 -080033 echo " Copying $FILE..."
Stefan Reinauer8a6e3412012-10-18 09:51:50 -070034 cp $WD/$FILE .
35else
Stefan Reinauerdcf351f2018-01-22 14:48:57 -080036 echo " Downloading $FILE..."
Stefan Reinauer8a6e3412012-10-18 09:51:50 -070037 curl -s $URL -o $FILE || exit
38fi
Stefan Reinauerdcf351f2018-01-22 14:48:57 -080039echo " Unpacking ..."
Stefan Reinauerdcf351f2018-01-22 14:48:57 -080040if ! msiextract $FILE > /dev/null ; then
41 echo " Could not unpack Windows installer..."
Vadim Bendebury16f048e2013-09-24 11:00:58 -070042 rm -rf $TEMP
43 exit 1
44fi
Stefan Reinauere2d48372019-12-01 21:51:36 -080045VERSION="$( strings -e l Program\ Files/DediProg/EM100/EM100.exe | grep -A1 ProductVersion | grep EM100 )"
46echo " Detected SPI flash database \"$VERSION\""
Stefan Reinauerdcf351f2018-01-22 14:48:57 -080047
48echo " Creating configs..."
Stefan Reinauerc57d9af2019-11-22 00:31:13 -080049mkdir -p $TD/configs
50cp -a $TEMP/Program\ Files/DediProg/EM100/config/EM100Pro/*.cfg $TD/configs
51echo -n "${VERSION}" > $TD/configs/VERSION
Stefan Reinauer1dc80862017-11-21 12:27:07 -080052
Stefan Reinauerdcf351f2018-01-22 14:48:57 -080053echo " Extract firmware files..."
Stefan Reinauerc57d9af2019-11-22 00:31:13 -080054mkdir -p $TD/firmware
Stefan Reinauerdcf351f2018-01-22 14:48:57 -080055for i in $TEMP/Program\ Files/DediProg/EM100/firmware/EM100ProFW_*
Stefan Reinauer1dc80862017-11-21 12:27:07 -080056do
Stefan Reinauerdcf351f2018-01-22 14:48:57 -080057 firmware=$( basename "$i" )
58 tuple=${firmware#EM100ProFW_}
59 v=${tuple: -3}
60 voltage=${v/V/.}V
61 mcu_version=${tuple: 1:1}.${tuple: 2:2}
62 fpga_version=${tuple: 4:1}.${tuple: 5:2}
63
64 $WD/makedpfw -m "$i/2.bin" -M $mcu_version -f "$i/1.bin" -F $fpga_version \
Stefan Reinauerc57d9af2019-11-22 00:31:13 -080065 -o $TD/firmware/em100pro_fw_${mcu_version}_${fpga_version}_${voltage}.dpfw
Stefan Reinauer1dc80862017-11-21 12:27:07 -080066done
Stefan Reinauerc57d9af2019-11-22 00:31:13 -080067echo -n "${VERSION}" > $TD/firmware/VERSION
Stefan Reinauer1dc80862017-11-21 12:27:07 -080068
Stefan Reinauerc57d9af2019-11-22 00:31:13 -080069cd $TD
70LANG=C tar cJf configs.tar.xz --sort=name configs
71LANG=C tar cJf firmware.tar.xz --sort=name firmware
72echo -n "Time: " > VERSION
73date +%s >> VERSION
74echo "Version: ${VERSION}" >> VERSION
Stefan Reinauer0ce691f2012-08-03 14:20:24 -070075cd $WD
Stefan Reinauerc57d9af2019-11-22 00:31:13 -080076
Stefan Reinauer0ce691f2012-08-03 14:20:24 -070077rm -rf $TEMP