├── .gitignore ├── LICENSE ├── Makefile ├── README.md └── src └── META-INF └── com └── google └── android └── updater-script /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore ZIPs altogether 2 | *.zip 3 | 4 | # Ignore specific directories 5 | build/ 6 | release/ 7 | updates/ 8 | src/firmware-update/ 9 | 10 | # Ignore specific files 11 | src/META-INF/com/google/android/update-binary 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Original script by Jannis Pinter (jannispinter) 2 | # Makefile by Roberto M.F. (Roboe) 3 | # https://github.com/WeAreFairphone/flashabe-zip_emojione 4 | 5 | SHELL := /bin/bash 6 | 7 | # Dependencies 8 | CURL := $(shell command -v curl 2>&1) 9 | ZIP := $(shell command -v zip 2>&1) 10 | UNZIP := $(shell command -v unzip 2>&1) 11 | ifeq ($(shell uname -s),Darwin) 12 | CP := $(shell command -v gcp 2>&1) 13 | FIND := $(shell command -v gfind 2>&1) 14 | SORT := $(shell command -v gsort 2>&1) 15 | SHA256SUM := $(shell command -v gsha256sum 2>&1) 16 | MKTEMP := $(shell command -v gmktemp 2>&1) 17 | else 18 | CP := $(shell command -v cp 2>&1) 19 | FIND := $(shell command -v find 2>&1) 20 | SORT := $(shell command -v sort 2>&1) 21 | SHA256SUM := $(shell command -v sha256sum 2>&1) 22 | MKTEMP := $(shell command -v mktemp 2>&1) 23 | endif 24 | 25 | # Version and release 26 | VERSION := 22.06.0-rel.0 27 | FLASHABLEZIP := ./build/modem.zip 28 | RELEASENAME := $(shell date +"modem-$(VERSION)_%Y-%m-%d.zip") 29 | RELEASEZIP := release/$(RELEASENAME) 30 | RELEASESUM := $(RELEASEZIP).sha256sum 31 | 32 | # Paths 33 | ROOT := $(shell pwd) 34 | SOURCE := ./src/ 35 | FIRMWARE_DIR := ./src/firmware-update/ 36 | EDIFY_BINARY := ./src/META-INF/com/google/android/update-binary 37 | EDIFY_SCRIPT := ./src/META-INF/com/google/android/updater-script 38 | TEMP_DIR := $(shell $(MKTEMP) --dry-run -d /tmp/modem.XXXXXXXX) 39 | TEMP_EDIFY_DIR := $(TEMP_DIR)/META-INF/com/google/android/ 40 | 41 | # Update ZIPs 42 | ## OTA update for the Edify interpreter 43 | OTA_FILENAME := $(VERSION)-sibon-89581e6c-ota.zip 44 | OTA_FILE := ./updates/$(OTA_FILENAME) 45 | OTA_URL := https://storage.googleapis.com/fairphone-updates/b36bdc44-f786-402b-90a0-4f4074cf0db0/$(OTA_FILENAME) 46 | OTA_CHECKSUM := a3f841390748023d028f726e28309a92d214f2e0739aa874857c1017244b23c6 47 | ## Update with desired firmware images (ota or manual) 48 | FWUPDATE_FILENAME := $(OTA_FILENAME) 49 | FWUPDATE_FILE := ./updates/$(FWUPDATE_FILENAME) 50 | FWUPDATE_URL := $(OTA_URL) 51 | FWUPDATE_CHECKSUM := $(OTA_CHECKSUM) 52 | ### Images directory uses to be 'firmware-update' for OTA ZIPs and 'images' for manual ZIPs 53 | FWUPDATE_IMGSDIR := firmware-update 54 | 55 | 56 | .PHONY: all build clean release install 57 | all: build 58 | 59 | 60 | build: $(FLASHABLEZIP) 61 | 62 | $(FLASHABLEZIP): $(FIRMWARE_DIR) $(EDIFY_BINARY) $(EDIFY_SCRIPT) 63 | @mkdir -p "$(TEMP_DIR)" 64 | @$(CP) -r \ 65 | $(FIRMWARE_DIR) \ 66 | -t "$(TEMP_DIR)" 67 | @mkdir -p "$(TEMP_EDIFY_DIR)/" 68 | @$(CP) -r \ 69 | $(EDIFY_BINARY) \ 70 | $(EDIFY_SCRIPT) \ 71 | -t "$(TEMP_EDIFY_DIR)" 72 | @$(FIND) "$(TEMP_DIR)" -exec touch -t 197001010000 {} + # Reproducibility 73 | @$(FIND) "$(TEMP_DIR)" -type f -exec chmod u=rw,go=r {} + # Reproducibility 74 | @echo "Building flashable ZIP..." 75 | @mkdir -pv "$(@D)" 76 | @rm -f "$@" 77 | @cd "$(TEMP_DIR)" && $(FIND) -type f | LC_ALL=C $(SORT) | $(ZIP) -X \ 78 | "$(ROOT)/$@" -@ 79 | @rm -rf "$(TEMP_DIR)" 80 | @echo "Result: $@" 81 | 82 | $(FWUPDATE_FILE): 83 | @echo "Downloading $(FWUPDATE_FILENAME)..." 84 | @mkdir -pv `dirname $(FWUPDATE_FILE)` 85 | @$(CURL) --progress-bar "$(FWUPDATE_URL)" -o $(FWUPDATE_FILE) 86 | @$(SHA256SUM) --check <(echo "$(FWUPDATE_CHECKSUM) $(FWUPDATE_FILE)") || rm -f "$(FWUPDATE_FILE)" 87 | 88 | $(OTA_FILE): 89 | @echo "Downloading $(OTA_FILENAME)..." 90 | @mkdir -pv "$(@D)" 91 | @$(CURL) --progress-bar "$(OTA_URL)" -o "$@" 92 | @$(SHA256SUM) --check <(echo "$(OTA_CHECKSUM) $@") || rm -f "$@" 93 | 94 | $(EDIFY_BINARY): $(OTA_FILE) 95 | @echo "Unpacking Edify interpreter..." 96 | @rm -rf "$@" 97 | @$(UNZIP) -j \ 98 | $(OTA_FILE) \ 99 | META-INF/com/google/android/update-binary \ 100 | -d "$(@D)" 101 | @touch "$@" # Update filedate so Make doesn't unpack it always 102 | 103 | $(FIRMWARE_DIR): $(FWUPDATE_FILE) 104 | @echo "Unpacking firmware files..." 105 | @rm -rf "$@" 106 | @$(UNZIP) -j \ 107 | $(FWUPDATE_FILE) \ 108 | $(FWUPDATE_IMGSDIR)/rpm.mbn \ 109 | $(FWUPDATE_IMGSDIR)/emmc_appsboot.mbn \ 110 | $(FWUPDATE_IMGSDIR)/NON-HLOS.bin \ 111 | $(FWUPDATE_IMGSDIR)/tz.mbn \ 112 | $(FWUPDATE_IMGSDIR)/splash.img \ 113 | $(FWUPDATE_IMGSDIR)/sbl1.mbn \ 114 | $(FWUPDATE_IMGSDIR)/sdi.mbn \ 115 | -d "$@" 116 | 117 | clean: 118 | @echo "Removing files..." 119 | # Build 120 | rm -f "$(FLASHABLEZIP)" 121 | @# only remove dir if it's empty: 122 | @rmdir -p `dirname $(FLASHABLEZIP)` 2>/dev/null || true 123 | # Firmware images 124 | rm -rf "$(FIRMWARE_DIR)" 125 | # Edify binary 126 | rm -f "$(EDIFY_BINARY)" 127 | 128 | release: $(RELEASEZIP) $(RELEASESUM) 129 | 130 | $(RELEASEZIP): $(FLASHABLEZIP) 131 | @mkdir -pv "$(@D)" 132 | @echo -n "Release file: " 133 | @$(CP) -v "$(FLASHABLEZIP)" "$@" 134 | 135 | $(RELEASESUM): $(RELEASEZIP) 136 | @echo "Release checksum: $@" 137 | @cd "$(@D)" && $(SHA256SUM) $(RELEASENAME) > $(@F) 138 | 139 | install: $(FLASHABLEZIP) 140 | @echo "Waiting for ADB sideload mode" 141 | @adb wait-for-sideload 142 | @adb sideload $(FLASHABLEZIP) 143 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fairphone 2 `modem.zip` 2 | Update the proprietary firmware of your [Fairphone 2](https://shop.fairphone.com) to the latest available. Fairphone updates the software of the Fairphone 2 with [security patches](https://source.android.com/security/bulletin/) on a monthly basis. 3 | 4 | This repo host the code to generate a reproducible, flashable ZIP file (called `modem.zip`) with the latest proprietary firmware from a recent Fairphone OS or Fairphone Open OTA. 5 | 6 | ### Download 7 | You can always download the latest `modem.zip` release from [this link](https://github.com/WeAreFairphone/modem_zip_generator/releases "Download latest modem.zip"). Also, previous releases can be found at the [releases page at GitHub](https://github.com/WeAreFairphone/modem_zip_generator/releases "Previous releases of the modem.zip"). 8 | 9 | ### System requirements 10 | The following tools are required for the script to run: 11 | - GNU `make` 12 | - `bash` 13 | - `curl` 14 | - `zip` & `unzip` 15 | - `sha256sum` 16 | 17 | The project has been developed on GNU/Linux systems, it should however run on other UNIX systems, too. For Mac OS you'll need the GNU coreutils and findutils. Using [Homebrew](https://brew.sh): `$ brew install coreutils findutils`. 18 | 19 | 20 | ### Build 21 | Clone the repository and execute `make build`, it will download and verify the official Fairphone 2 firmware images and extract the proprietary firmware images. 22 | 23 | If you want to test your changes, just run `make install` and connect your device in recovery mode and sideload to your computer. 24 | 25 | To make a release, just execute `make release`. It will output a `modem-{VERSION}_YYYY-MM-DD.zip` to the `release/` folder. 26 | 27 | ### Contributing 28 | We welcome contributions to this project, specially for new releases. We do this on our free time and we can fall behind the security releases schedule of Fairphone. [Fork this repo](https://github.com/WeAreFairphone/modem_zip_generator/fork), commit your changes and [open a pull request](https://github.com/WeAreFairphone/modem_zip_generator/pull/new). 29 | 30 | Usually, if you want to update to the newest release, you'll just need to tweak the variable definitions at the top of the `Makefile`. The general flow of the Makefile is: 31 | 1. get the Edify interpreter from a OTA release → set ```OTA_*``` variables accordingly. 32 | 2. get the firmware images from a MANUAL release → set ```FWUPDATE_*``` variables accordingly. 33 | - In case latest OTA release includes every firmware image, these variables can be assigned to their `OTA_*` counterparts (```FWUPDATE_FILENAME := $(OTA_FILENAME)``` and so on). Don't worry, GNU Make is a clever system and won't re-download two identical ZIPs. 34 | 3. pack them into a ready-to-flash ZIP file. 35 | 36 | You can also find useful these links: 37 | - Fairphone Open update files can be found at https://code.fairphone.com/projects/fp-osos/user/fairphone-open-source-os-downloads.html 38 | - Fairphone OS update files can be found at https://support.fairphone.com/hc/en-us/articles/213290023-Fairphone-OS-downloads-for-Fairphone-2 39 | 40 | 41 | ### Misc 42 | See this [forum post](https://forum.fairphone.com/t/pencil2-fp2-modem-firmware/35374) for more information about this project. 43 | -------------------------------------------------------------------------------- /src/META-INF/com/google/android/updater-script: -------------------------------------------------------------------------------- 1 | assert(getprop("ro.product.device") == "FP2" || getprop("ro.build.product") == "FP2" || abort("E3004: This package is for device: FP2; this device is " + getprop("ro.product.device") + ".");); 2 | set_progress(0.200000); 3 | 4 | ui_print("Patching firmware images..."); 5 | 6 | package_extract_file("firmware-update/tz.mbn", "/dev/block/platform/msm_sdcc.1/by-name/tz"); 7 | set_progress(0.300000); 8 | 9 | package_extract_file("firmware-update/sbl1.mbn", "/dev/block/platform/msm_sdcc.1/by-name/sbl1"); 10 | set_progress(0.400000); 11 | 12 | package_extract_file("firmware-update/sdi.mbn", "/dev/block/platform/msm_sdcc.1/by-name/sdi"); 13 | set_progress(0.500000); 14 | 15 | package_extract_file("firmware-update/rpm.mbn", "/dev/block/platform/msm_sdcc.1/by-name/rpm"); 16 | set_progress(0.600000); 17 | 18 | package_extract_file("firmware-update/emmc_appsboot.mbn", "/dev/block/platform/msm_sdcc.1/by-name/aboot"); 19 | msm.boot_update("backup"); 20 | msm.boot_update("finalize"); 21 | set_progress(0.800000); 22 | 23 | package_extract_file("firmware-update/splash.img", "/dev/block/platform/msm_sdcc.1/by-name/splash"); 24 | set_progress(0.900000); 25 | 26 | package_extract_file("firmware-update/NON-HLOS.bin", "/dev/block/platform/msm_sdcc.1/by-name/modem"); 27 | 28 | ui_print("Flashing successful! You have updated your modem firmware."); 29 | set_progress(1.000000); 30 | --------------------------------------------------------------------------------