-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
142 lines (123 loc) · 4.37 KB
/
Makefile
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Original script by Jannis Pinter (jannispinter)
# Makefile by Roberto M.F. (Roboe)
# https://github.com/WeAreFairphone/flashabe-zip_emojione
SHELL := /bin/bash
# Dependencies
CURL := $(shell command -v curl 2>&1)
ZIP := $(shell command -v zip 2>&1)
UNZIP := $(shell command -v unzip 2>&1)
ifeq ($(shell uname -s),Darwin)
CP := $(shell command -v gcp 2>&1)
FIND := $(shell command -v gfind 2>&1)
SORT := $(shell command -v gsort 2>&1)
SHA256SUM := $(shell command -v gsha256sum 2>&1)
MKTEMP := $(shell command -v gmktemp 2>&1)
else
CP := $(shell command -v cp 2>&1)
FIND := $(shell command -v find 2>&1)
SORT := $(shell command -v sort 2>&1)
SHA256SUM := $(shell command -v sha256sum 2>&1)
MKTEMP := $(shell command -v mktemp 2>&1)
endif
# Version and release
VERSION := 22.06.0-rel.0
FLASHABLEZIP := ./build/modem.zip
RELEASENAME := $(shell date +"modem-$(VERSION)_%Y-%m-%d.zip")
RELEASEZIP := release/$(RELEASENAME)
RELEASESUM := $(RELEASEZIP).sha256sum
# Paths
ROOT := $(shell pwd)
SOURCE := ./src/
FIRMWARE_DIR := ./src/firmware-update/
EDIFY_BINARY := ./src/META-INF/com/google/android/update-binary
EDIFY_SCRIPT := ./src/META-INF/com/google/android/updater-script
TEMP_DIR := $(shell $(MKTEMP) --dry-run -d /tmp/modem.XXXXXXXX)
TEMP_EDIFY_DIR := $(TEMP_DIR)/META-INF/com/google/android/
# Update ZIPs
## OTA update for the Edify interpreter
OTA_FILENAME := $(VERSION)-sibon-89581e6c-ota.zip
OTA_FILE := ./updates/$(OTA_FILENAME)
OTA_URL := https://storage.googleapis.com/fairphone-updates/b36bdc44-f786-402b-90a0-4f4074cf0db0/$(OTA_FILENAME)
OTA_CHECKSUM := a3f841390748023d028f726e28309a92d214f2e0739aa874857c1017244b23c6
## Update with desired firmware images (ota or manual)
FWUPDATE_FILENAME := $(OTA_FILENAME)
FWUPDATE_FILE := ./updates/$(FWUPDATE_FILENAME)
FWUPDATE_URL := $(OTA_URL)
FWUPDATE_CHECKSUM := $(OTA_CHECKSUM)
### Images directory uses to be 'firmware-update' for OTA ZIPs and 'images' for manual ZIPs
FWUPDATE_IMGSDIR := firmware-update
.PHONY: all build clean release install
all: build
build: $(FLASHABLEZIP)
$(FLASHABLEZIP): $(FIRMWARE_DIR) $(EDIFY_BINARY) $(EDIFY_SCRIPT)
@mkdir -p "$(TEMP_DIR)"
@$(CP) -r \
$(FIRMWARE_DIR) \
-t "$(TEMP_DIR)"
@mkdir -p "$(TEMP_EDIFY_DIR)/"
@$(CP) -r \
$(EDIFY_BINARY) \
$(EDIFY_SCRIPT) \
-t "$(TEMP_EDIFY_DIR)"
@$(FIND) "$(TEMP_DIR)" -exec touch -t 197001010000 {} + # Reproducibility
@$(FIND) "$(TEMP_DIR)" -type f -exec chmod u=rw,go=r {} + # Reproducibility
@echo "Building flashable ZIP..."
@mkdir -pv "$(@D)"
@rm -f "$@"
@cd "$(TEMP_DIR)" && $(FIND) -type f | LC_ALL=C $(SORT) | $(ZIP) -X \
"$(ROOT)/$@" -@
@rm -rf "$(TEMP_DIR)"
@echo "Result: $@"
$(FWUPDATE_FILE):
@echo "Downloading $(FWUPDATE_FILENAME)..."
@mkdir -pv `dirname $(FWUPDATE_FILE)`
@$(CURL) --progress-bar "$(FWUPDATE_URL)" -o $(FWUPDATE_FILE)
@$(SHA256SUM) --check <(echo "$(FWUPDATE_CHECKSUM) $(FWUPDATE_FILE)") || rm -f "$(FWUPDATE_FILE)"
$(OTA_FILE):
@echo "Downloading $(OTA_FILENAME)..."
@mkdir -pv "$(@D)"
@$(CURL) --progress-bar "$(OTA_URL)" -o "$@"
@$(SHA256SUM) --check <(echo "$(OTA_CHECKSUM) $@") || rm -f "$@"
$(EDIFY_BINARY): $(OTA_FILE)
@echo "Unpacking Edify interpreter..."
@rm -rf "$@"
@$(UNZIP) -j \
$(OTA_FILE) \
META-INF/com/google/android/update-binary \
-d "$(@D)"
@touch "$@" # Update filedate so Make doesn't unpack it always
$(FIRMWARE_DIR): $(FWUPDATE_FILE)
@echo "Unpacking firmware files..."
@rm -rf "$@"
@$(UNZIP) -j \
$(FWUPDATE_FILE) \
$(FWUPDATE_IMGSDIR)/rpm.mbn \
$(FWUPDATE_IMGSDIR)/emmc_appsboot.mbn \
$(FWUPDATE_IMGSDIR)/NON-HLOS.bin \
$(FWUPDATE_IMGSDIR)/tz.mbn \
$(FWUPDATE_IMGSDIR)/splash.img \
$(FWUPDATE_IMGSDIR)/sbl1.mbn \
$(FWUPDATE_IMGSDIR)/sdi.mbn \
-d "$@"
clean:
@echo "Removing files..."
# Build
rm -f "$(FLASHABLEZIP)"
@# only remove dir if it's empty:
@rmdir -p `dirname $(FLASHABLEZIP)` 2>/dev/null || true
# Firmware images
rm -rf "$(FIRMWARE_DIR)"
# Edify binary
rm -f "$(EDIFY_BINARY)"
release: $(RELEASEZIP) $(RELEASESUM)
$(RELEASEZIP): $(FLASHABLEZIP)
@mkdir -pv "$(@D)"
@echo -n "Release file: "
@$(CP) -v "$(FLASHABLEZIP)" "$@"
$(RELEASESUM): $(RELEASEZIP)
@echo "Release checksum: $@"
@cd "$(@D)" && $(SHA256SUM) $(RELEASENAME) > $(@F)
install: $(FLASHABLEZIP)
@echo "Waiting for ADB sideload mode"
@adb wait-for-sideload
@adb sideload $(FLASHABLEZIP)