-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
64 lines (51 loc) · 1.92 KB
/
Makefile
File metadata and controls
64 lines (51 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# IP32 PROM Decompiler Makefile
# Decompiles firmware and rebuilds it into a new image
#
# Requirements:
# - Rust toolchain (for building the decompiler)
# - MIPS cross-toolchain (for rebuilding the firmware)
#
# Usage:
# make # Decompile and rebuild
# make decompile # Decompile only
# make rebuild # Rebuild only (after decompile)
# make check # Verify rebuilt image matches original
# make clean # Clean all generated files
PROM_IMAGE ?= ../ip32prom.rev4.18.bin
OUTPUT_DIR ?= output
# Variables to export to the generated Makefile
export CHECKSUM = $(CURDIR)/target/release/ip32prom-checksum
.PHONY: all clean decompile rebuild check
all: rebuild
# All Rust source files
RUST_SOURCES := $(shell find src -name '*.rs')
# Build all Rust binaries
target/release/ip32prom-decompiler target/release/ip32prom-checksum: $(RUST_SOURCES) Cargo.toml Cargo.lock
cargo build --release
# Annotation files that affect decompiler output
ANNOTATION_FILES := $(wildcard annotations/*.json)
# Sentinel file to track decompiler execution
DECOMPILE_STAMP := $(OUTPUT_DIR)/.decompile.stamp
# Decompile the firmware
decompile: $(DECOMPILE_STAMP)
$(DECOMPILE_STAMP): target/release/ip32prom-decompiler $(PROM_IMAGE) $(ANNOTATION_FILES)
@mkdir -p $(OUTPUT_DIR)
./target/release/ip32prom-decompiler $(PROM_IMAGE) -o $(OUTPUT_DIR)
@touch $@
# Rebuild the PROM image using the generated Makefile
rebuild: $(DECOMPILE_STAMP) target/release/ip32prom-checksum
$(MAKE) -C $(OUTPUT_DIR) all
# Verify the rebuilt image matches the original
check: rebuild
@echo "Comparing rebuilt PROM with original..."
@if cmp -s $(PROM_IMAGE) $(OUTPUT_DIR)/prom.bin; then \
echo "PASS: Rebuilt image matches original"; \
else \
echo "FAIL: Rebuilt image differs from original"; \
cmp $(PROM_IMAGE) $(OUTPUT_DIR)/prom.bin || true; \
exit 1; \
fi
# Clean everything
clean:
rm -rf $(OUTPUT_DIR)
cargo clean