Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement updater tool #60

Open
wants to merge 5 commits into
base: icedream-experiments
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
*.exe*
*.img
*.sfx
buildroot/
engineos/*
!engineos/.gitkeep
media/
unpacked-img/
updater/
*.dll
*.so
/go/updater
/go/find_update
/buildroot/
/engineos/*
!/engineos/.gitkeep
/media/
/unpacked-img/
/updater/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To reproduce the modified firmware with OpenSSH:
2. Run `./clone-buildroot.sh` to download the matching buildroot environment via Git to the `buildroot/2021.02.10` directory.
3. Run `./compile-buildroot.sh` to build the required toolchain and packages in buildroot. Note that this will ask for sudo access to modify the unpacked firmware images via loopback mount.
4. Run `./pack.sh` to finally pack the modified image files back into a new firmware package. It will have a `.dtb` extension but you can rename this to `.img` and flash it directly to your hardware.
5. Optionally run `./unpack-updater.sh` to download Denon's original Windows tool for flashing firmware via USB cable, then run `./generate-updater-win.sh` to download 7-zip's SFX module to generate a self-extracting executable based on that tool but with your own image instead.
5. Optionally, install [Go](https://go.dev/) 1.22 or newer and run `./generate-updater-win.sh` to download 7-zip's SFX module to generate a self-extracting executable based on that tool but with your own image instead.

## Customizations

Expand Down
22 changes: 11 additions & 11 deletions devices.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
numark mixstreampro NH08 MIXSTREAMPRO https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/MIXSTREAMPRO-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Mixstream+Pro+4.0.0+Updater.exe
numark mixstreamprogo --- MIXSTREAMPROGO https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/MIXSTREAMPROGO-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Mixstream+Pro+Go+4.0.0+Updater.exe
numark mixstreamproplus --- MIXSTREAMPROPLUS https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/MIXSTREAMPROPLUS-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Mixstream+Pro+Plus+4.0.0+Updater.exe
denon prime4 JC11 PRIME4 https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/PRIME4-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Prime+4+4.0.0+Updater.exe
denon prime4plus --- PRIME4PLUS https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/PRIME4PLUS-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Prime+4+Plus+4.0.0+Updater.exe
denon primego JP11 PRIMEGO https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/PRIMEGO-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Prime+GO+4.0.0+Updater.exe
denon prime2 JC16 PRIME2 https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/PRIME2-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Prime+2+4.0.0+Updater.exe
denon sc6000prime JP13 SC6000 https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC6000-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC6000+Prime+4.0.0+Updater.exe
denon sc6000mprime JP14 SC6000M https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC6000M-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC6000M+Prime+4.0.0+Updater.exe
denon sc5000prime JP07 SC5000 https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC5000-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC5000+Prime+4.0.0+Updater.exe
denon sc5000mprime JP08 SC5000M https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC5000M-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC5000M+Prime+4.0.0+Updater.exe
numark mixstreampro NH08 MIXSTREAMPRO https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/MIXSTREAMPRO-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Mixstream+Pro+4.0.0+Updater.exe Numark Mixstream Pro
numark mixstreamprogo --- MIXSTREAMPROGO https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/MIXSTREAMPROGO-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Mixstream+Pro+Go+4.0.0+Updater.exe Numark Mixstream Pro Go
numark mixstreamproplus --- MIXSTREAMPROPLUS https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/MIXSTREAMPROPLUS-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Mixstream+Pro+Plus+4.0.0+Updater.exe Numark Mixstream Pro Plus
denon prime4 JC11 PRIME4 https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/PRIME4-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Prime+4+4.0.0+Updater.exe Denon DJ PRIME 4
denon prime4plus --- PRIME4PLUS https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/PRIME4PLUS-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Prime+4+Plus+4.0.0+Updater.exe Denon DJ PRIME 4+
denon primego JP11 PRIMEGO https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/PRIMEGO-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Prime+GO+4.0.0+Updater.exe Denon DJ PRIME GO
denon prime2 JC16 PRIME2 https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/PRIME2-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/Prime+2+4.0.0+Updater.exe Denon DJ PRIME 2
denon sc6000prime JP13 SC6000 https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC6000-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC6000+Prime+4.0.0+Updater.exe Denon DJ SC6000 PRIME
denon sc6000mprime JP14 SC6000M https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC6000M-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC6000M+Prime+4.0.0+Updater.exe Denon DJ SC6000M PRIME
denon sc5000prime JP07 SC5000 https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC5000-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC5000+Prime+4.0.0+Updater.exe Denon DJ SC5000 PRIME
denon sc5000mprime JP08 SC5000M https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC5000M-4.0.0-Update.img https://enginedj.inmusiccdn.com/Engine/4.0.0/Release/af2cdcfdbe977f25/SC5000M+Prime+4.0.0+Updater.exe Denon DJ SC5000M PRIME
1 change: 0 additions & 1 deletion dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ rm -rf unpacked-img
./unpack.sh "$@"
./compile-buildroot.sh "$@"
./pack.sh "$@"
./unpack-updater.sh "$@"
./generate-updater-win.sh "$@"
4 changes: 3 additions & 1 deletion functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ device_update_download_filename=
device_application_name=
device_updater_win_download_url=
device_updater_win_download_filename=
device_name=

while read -r current_vendor current_device current_device_id current_device_application_name current_img_download_url current_updater_download_url _; do
while read -r current_vendor current_device current_device_id current_device_application_name current_img_download_url current_updater_download_url current_device_name; do
if [ "$current_vendor" = "$vendor" ] && [ "$current_device" = "$device" ]; then
device_id="$current_device_id"
device_update_download_url="$current_img_download_url"
Expand All @@ -80,6 +81,7 @@ while read -r current_vendor current_device current_device_id current_device_app
device_updater_win_download_url="${current_updater_download_url}"
fi
device_application_name="$current_device_application_name"
device_name="$current_device_name"
break
fi
done <devices.txt
Expand Down
30 changes: 24 additions & 6 deletions generate-updater-win.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,38 @@ if [ "${#files[@]}" -lt 1 ]; then
log_fatal "Need at least one .dtb file to process. Generate it with ./pack.sh or put it into the current working directory ($(pwd))."
fi

output_dir="./updater/$device_id"
if [ ! -d "$output_dir" ]; then
log_fatal "Run ./unpack-updater.sh for this device first." >&2
fi
make -C go all-windows-amd64

tempdir=$(mktemp -d)
trap 'rm -rf ${tempdir}' EXIT

for file in "${files[@]}"; do
cp -v "${file}" "${output_dir}/win"/update.img
dtb_name="$(basename "${file}" .dtb)"
dtb_dir="$(dirname "$dtb_name")"

# generate config file
cat >"$tempdir"/config.toml <<EOF
[[devices]]
name = "${device_name}"
imagePath = "${dtb_name}.dtb"
usbConfig = 1
usbInterface = 0
usbAlternate = 0
usbInputEndpoint = 1
usbOutputEndpoint = 2
usbReadSize = 256
usbReadBufferSize = 0
usbWriteSize = 4096
usbWriteBufferSize = 0
usbOpTimeout = "1m"
EOF
for sfx_file in "${sfx[@]}"; do
sfx_name="$(basename "$sfx_file" .sfx)"
exe_name="${dtb_name}_${sfx_name}.exe"
archive_name="${dtb_name}_${sfx_name}.7z"
echo "*** Packing updater files"
7z a "$archive_name" "${output_dir}"/win*
# NOTE - keep ./ to make 7z strip dir paths
7z a "$archive_name" ./go/updater.exe ./go/*.dll "$tempdir"/./config.toml "${dtb_dir}"/./"${dtb_name}".dtb
trap 'rm -f "$archive_name"' EXIT
echo "*** Generating ${exe_name} with ${sfx_file}"
cat "${sfx_file}" sfx-config.txt "$archive_name" >"$exe_name"
Expand Down
101 changes: 101 additions & 0 deletions go/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
TRIPLET=x86_64-linux-gnu
CC=$(TRIPLET)-gcc
CXX=$(TRIPLET)-g++
PREFIX=/usr
WINDOWS_AMD64_TRIPLET=x86_64-w64-mingw32
WINDOWS_AMD64_PREFIX=/usr/$(WINDOWS_AMD64_TRIPLET)
WINDOWS_386_TRIPLET=i686-w64-mingw32
WINDOWS_386_PREFIX=/usr/$(WINDOWS_386_TRIPLET)
GOTAGS=libxz
LINUX_AMD64_TRIPLET=x86_64-linux-gnu
GO=go
GOOS=
GOARCH=
GOBUILDFLAGS=
CGO_ENABLED=1
DLLEXT=.so
BINEXT=
LINUX_DLL_BLACKLIST="^(libc.so)([\.\d+]+)\$$"
WINDOWS_DLL_BLACKLIST="^(advapi32.dll|comctl32.dll|comdlg32.dll|gdi32.dll|kernel32.dll|gdi32.dll|gdiplus.dll|glu32.dll|kernel32.dll|msvcrt.dll|ole32.dll|opengl32.dll|shell32.dll|user32.dll|ws2_32.dll)\$$"
DLL_BLACKLIST=$(WINDOWS_DLL_BLACKLIST)
LIB_PREFIX=$(PREFIX)/lib
BINS=find_update updater
GOGUIBUILDFLAGS=
GOBUILDLDFLAGS="-s -w"
GOBUILDFLAGS=

export CC CXX GOOS GOARCH CGO_ENABLED

all: $(addsuffix $(BINEXT),$(BINS))

#
# WINDOWS AMD64 BUILD CONVENIENCE TASKS
#

.PHONY: all-windows-amd64

all-windows-amd64:
$(MAKE) \
GOOS=windows \
GOARCH=amd64 \
TRIPLET=$(WINDOWS_AMD64_TRIPLET) \
PREFIX=$(WINDOWS_AMD64_PREFIX) \
LIB_PREFIX=$(WINDOWS_AMD64_PREFIX)/bin \
GOGUIBUILDFLAGS='"-H windowsgui"' \
BINEXT=.exe \
DLLEXT=.dll \
all \
$(addprefix copy-libs-,$(addsuffix .exe,$(BINS)))

.PHONY: clean-windows-amd64

clean-windows-amd64:
$(MAKE) \
GOOS=windows \
GOARCH=amd64 \
TRIPLET=$(WINDOWS_AMD64_TRIPLET) \
PREFIX=$(WINDOWS_AMD64_PREFIX) \
LIB_PREFIX=$(WINDOWS_AMD64_PREFIX)/bin \
GOGUIBUILDFLAGS="-H windowsgui" \
BINEXT=.exe \
DLLEXT=.dll \
clean

#
# MAIN BINARY TARGETS
#

find_update$(BINEXT): go.mod go.sum $(wildcard ./pkg/**/*.go ./cmd/find_update/**/*.go)
$(GO) build -tags $(GOTAGS) -ldflags $(GOBUILDLDFLAGS) $(GOBUILDFLAGS) -o $@ -v ./cmd/find_update

updater$(BINEXT): go.mod go.sum $(wildcard ./pkg/**/*.go ./cmd/updater/**/*.go)
$(GO) build -tags $(GOTAGS) -ldflags $(GOGUIBUILDFLAGS)\ $(GOBUILDLDFLAGS) $(GOBUILDFLAGS) -o $@ -v ./cmd/updater

#
# PACKAGING TASKS
#

.PHONY: copy-libs-%

copy-libs-%: %
$(MAKE) -s TARGET=$< copy-libs

.PHONY: copy-libs

# Extract list of DLL files that are used by imports.
#
# Windows output only.
copy-libs:
$(TRIPLET)-objdump -p $(TARGET) | \
grep -F "DLL Name:" | \
sed -e "s/\t*DLL Name: //g" | \
grep -Evi $(DLL_BLACKLIST) | \
tr "\n" " " | \
xargs -r -t $(MAKE)

%$(DLLEXT): $(LIB_PREFIX)/%$(DLLEXT)
cp $< $@
$(MAKE) -s TARGET=$@ copy-libs

clean:
$(RM) $(wildcard updater$(BINEXT) *$(DLLEXT))
32 changes: 32 additions & 0 deletions go/cmd/updater/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"flag"
"fmt"
"log"
"log/slog"
)

var (
flagDebugLevel = flag.Int("debug", int(slog.LevelError), fmt.Sprintf("logging level (ranges from %d for debug to %d for error)", int(slog.LevelDebug), int(slog.LevelError)))
flagLibusbDebugLevel = flag.Int("libusb_debug", 0, fmt.Sprintf("libusb debug level (%d..%d)", 0, 3))
flagSkipRebootAfterFlash = flag.Bool("skip_reboot", false, "Whether to skip reboot after flashing")
flagDryRun = flag.Bool("dry", false, "Enable dry run (device still needs to be plugged in but will not actually flash)")
)

func main() {
err := run()
if err != nil {
log.Fatal(err)
}
}

func run() error {
flag.Parse()

if err := initUI(); err != nil {
panic(err)
}

return nil
}
Loading