diff --git a/android/rescue/LEEME.md b/android/rescue/LEEME.md index 50867f2f..8fce0cb1 100644 --- a/android/rescue/LEEME.md +++ b/android/rescue/LEEME.md @@ -19,8 +19,7 @@ después te va diciendo qué hacer mientras repara el FM-1. | Adaptador **OTG** USB-C (o micro-USB) a USB-A, o un cable USB-C a USB-C | para enchufar el RP2040 al móvil | | **Waveshare RP2040-Zero** o **Seeed XIAO RP2040** | la placa de la guía de GoodPerson42 | | Cable USB-C con 4 hilos sueltos | negro, rojo, blanco, verde | -| El archivo **FM-1.fwsc de la V15 oficial** (699.956 bytes) | también llamado `FM-1v15.fwsc` o `V15-FM-1.fwsc` | -| Internet **la primera vez** | para descargar el loader de JieLi (24 KB); luego funciona sin conexión | +| Internet **la primera vez** | la app descarga sola la V15 oficial (700 KB); luego funciona sin conexión | ## Instalar @@ -30,8 +29,9 @@ desconocido" si Android lo pide. ## Usar -1. **Abre la app y elige el `FM-1.fwsc` de la V15.** Se comprueba por su hash; si no es la V15 oficial, se - rechaza (la V16 no sirve aquí). Solo hay que hacerlo una vez: la app lo guarda. +1. **Abre la app con internet.** Descarga sola la V15 oficial y la comprueba por su hash (sale "✓ V15 oficial + lista"). Solo la primera vez: la guarda. Si prefieres usar tu propio `FM-1.fwsc` de la V15, pulsa "O elegir + mi propio FM-1.fwsc" (cualquier otro archivo se rechaza; la V16 no sirve aquí). 2. **Elige tu placa:** RP2040-Zero o XIAO RP2040. 3. **Cableado**, con el FM-1 **apagado** (el rojo no se conecta): @@ -78,8 +78,17 @@ azul = trabajando, verde fijo = listo, rojo parpadeando rápido = error. V15, cada uno verificado, con una relectura final completa. - **Nunca** toca la cabecera de arranque (`0x0000..0x3FFF`) ni tus datos (`0x93000..`: ajustes, sonidos, canciones). A diferencia del método con Python, **no** guarda una copia completa del FM-1 antes. -- El móvil solo alimenta el RP2040 y lee su progreso. Nada sale del móvil salvo la descarga del loader desde - GitHub (`kagaimiq/jl-uboot-tool`, commit fijado, hash comprobado). +- El móvil solo alimenta el RP2040 y lee su progreso. Lo único que se descarga es la V15: el `V15-FM-1.fwsc` de + [Quixotic7/FM1Backups](https://github.com/Quixotic7/FM1Backups) en un commit fijado, idéntico al archivo de + M-VAVE (sha256 `db1642b2…`), y la app solo lo acepta si el hash de su región de firmware es el de la V15. + La V15 no va dentro del APK porque es software de M-VAVE; el loader de JieLi sí (jl-uboot-tool, MIT, + licencia en `assets/wl82loader-LICENSE.txt`). + +### ¿Y la V16? + +No se puede escribir con este método. La V16 ocupa hasta `0xA8FFF` (más allá de la zona `0x4000..0x92FFF`) y trae +su propio bootloader en la cabecera, que este método nunca toca para no arriesgar un brick peor. Se repara con +la V15 y después se actualiza a la V16 (o a JIANT) con el instalador normal. ## Para desarrolladores @@ -96,8 +105,8 @@ Compilar: `gradle -p android/rescue assembleDebug` (JDK 17, Gradle 8.9); el firm ## English -FM-1 Rescue for Android unbricks an FM-1 with an RP2040 and the phone: choose the official V15 `FM-1.fwsc` -once, pick the board, wire green → GP0, white → GP1, black → GND (FM-1 off, red unconnected), hold BOOT and +FM-1 Rescue for Android unbricks an FM-1 with an RP2040 and the phone: on first launch it downloads the +official V15 (pinned, hash-checked; or choose your own), JieLi's loader is bundled; pick the board, wire green → GP0, white → GP1, black → GND (FM-1 off, red unconnected), hold BOOT and plug the RP2040 into the phone with an OTG adapter. The app programs the board over PICOBOOT, reboots it, and then shows the rescue's progress read from the board: "switch the FM-1 on now", "repairing…", "done". Only the differing sectors of `0x4000..0x92FFF` are written, each verified; the boot head and user data are never diff --git a/android/rescue/app/src/main/assets/wl82loader-LICENSE.txt b/android/rescue/app/src/main/assets/wl82loader-LICENSE.txt new file mode 100644 index 00000000..e917978b --- /dev/null +++ b/android/rescue/app/src/main/assets/wl82loader-LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Andrey Grigoryev (kagaimiq) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/android/rescue/app/src/main/assets/wl82loader.bin b/android/rescue/app/src/main/assets/wl82loader.bin new file mode 100644 index 00000000..3b47cffa Binary files /dev/null and b/android/rescue/app/src/main/assets/wl82loader.bin differ diff --git a/android/rescue/app/src/main/java/fm/jiant/rescue/MainActivity.java b/android/rescue/app/src/main/java/fm/jiant/rescue/MainActivity.java index 6194867e..8aa95ab3 100644 --- a/android/rescue/app/src/main/java/fm/jiant/rescue/MainActivity.java +++ b/android/rescue/app/src/main/java/fm/jiant/rescue/MainActivity.java @@ -151,7 +151,7 @@ public class MainActivity extends Activity { LinearLayout c1 = card(root); text(c1, t("1 · Firmware oficial V15", "1 · Official V15 firmware"), 16, true); fwscText = text(c1, "", 14, false); - button(c1, t("Elegir FM-1.fwsc", "Choose FM-1.fwsc")).setOnClickListener(v -> { + button(c1, t("O elegir mi propio FM-1.fwsc", "Or choose my own FM-1.fwsc")).setOnClickListener(v -> { Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); @@ -236,7 +236,6 @@ public class MainActivity extends Activity { // ------------------------------------------------------------ files private File fwscFile() { return new File(getFilesDir(), "FM-1-V15.fwsc"); } - private File loaderFile() { return new File(getFilesDir(), "wl82loader.bin"); } private void loadFiles() { try { @@ -246,39 +245,55 @@ public class MainActivity extends Activity { fwsc = d; } } catch (Exception e) { fwsc = null; } - try { - if (loaderFile().exists()) loader = RescueImage.checkLoader(Files.readAllBytes(loaderFile().toPath())); - } catch (Exception e) { loader = null; } + // jl-uboot-tool's loader ships in the APK (MIT, assets/wl82loader-LICENSE.txt). + try (InputStream in = getAssets().open("wl82loader.bin")) { + loader = RescueImage.checkLoader(readAll(in)); + } catch (Exception e) { + loader = null; + logLine("loader: " + e.getMessage()); + } updateFileTexts(); - if (loader == null) net.execute(this::downloadLoader); + if (fwsc == null) net.execute(this::downloadV15); } + private volatile boolean downloading; + private void updateFileTexts() { ui.post(() -> { - fwscText.setText(fwsc != null ? t("✓ V15 oficial verificada", "✓ Official V15 verified") - : t("Elige el FM-1.fwsc de la V15 de M-VAVE (699.956 bytes). Se comprueba por su hash.", - "Choose M-VAVE's V15 FM-1.fwsc (699,956 bytes). It is checked by its hash.")); + fwscText.setText(fwsc != null ? t("✓ V15 oficial lista (verificada por su hash)", "✓ Official V15 ready (hash-verified)") + : downloading ? t("Descargando la V15 oficial…", "Downloading the official V15…") + : t("No se pudo descargar la V15 (¿sin internet?). Se reintenta sola, o elige tu FM-1.fwsc de la V15.", + "Could not download V15 (no internet?). It retries by itself, or choose your V15 FM-1.fwsc.")); fwscText.setTextColor(fwsc != null ? 0xFF2E8B57 : 0xFF1D1D1B); - loaderText.setText(loader != null ? t("✓ Loader de JieLi listo", "✓ JieLi loader ready") - : t("Descargando el loader de JieLi (jl-uboot-tool)…", "Downloading JieLi's loader (jl-uboot-tool)…")); + loaderText.setText(loader != null ? t("✓ Loader de JieLi incluido", "✓ JieLi loader included") + : t("✗ El loader incluido está dañado: reinstala la app.", "✗ The bundled loader is damaged: reinstall the app.")); }); } - private void downloadLoader() { + /** The official V15, downloaded once and kept; accepted only if its firmware region hash is V15's. */ + private void downloadV15() { + if (fwsc != null) return; + downloading = true; + updateFileTexts(); try { - HttpURLConnection c = (HttpURLConnection) new URL(RescueImage.LOADER_URL).openConnection(); + HttpURLConnection c = (HttpURLConnection) new URL(RescueImage.V15_URL).openConnection(); c.setConnectTimeout(15000); - c.setReadTimeout(15000); + c.setReadTimeout(30000); byte[] d; try (InputStream in = c.getInputStream()) { d = readAll(in); } - RescueImage.checkLoader(d); - try (FileOutputStream o = new FileOutputStream(loaderFile())) { o.write(d); } - loader = d; + RescueImage.checkV15(d); + if (fwsc == null) { + try (FileOutputStream o = new FileOutputStream(fwscFile())) { o.write(d); } + fwsc = d; + logLine(t("V15 descargada y verificada", "V15 downloaded and verified")); + } + downloading = false; updateFileTexts(); } catch (Exception e) { - ui.post(() -> loaderText.setText(t("No se pudo descargar el loader (¿sin internet?). Se reintenta…", - "Could not download the loader (no internet?). Retrying…"))); - ui.postDelayed(() -> net.execute(this::downloadLoader), 10000); + downloading = false; + logLine("V15: " + e.getMessage()); + updateFileTexts(); + ui.postDelayed(() -> net.execute(this::downloadV15), 15000); } } @@ -366,8 +381,9 @@ public class MainActivity extends Activity { if (boot != null) { if (fwsc == null || loader == null) { show(t("RP2040 conectado", "RP2040 connected"), - fwsc == null ? t("Elige primero el FM-1.fwsc (paso 1).", "Choose the FM-1.fwsc first (step 1).") - : t("Esperando el loader de JieLi…", "Waiting for JieLi's loader…"), 0); + fwsc == null ? t("Esperando la V15 (paso 1): necesita internet la primera vez.", + "Waiting for V15 (step 1): it needs the internet the first time.") + : t("El loader incluido está dañado: reinstala la app.", "The bundled loader is damaged: reinstall the app."), 0); return; } if (!permitted(boot)) return; @@ -537,8 +553,8 @@ public class MainActivity extends Activity { resetToBootsel(d); } else { show(t("El RP2040 no tiene la V15 dentro", "The RP2040 has no V15 inside"), - t("Elige el FM-1.fwsc y pulsa \"Volver a grabar el RP2040\".", - "Choose the FM-1.fwsc and press \"Reprogram the RP2040\"."), 0); + t("Espera a que la V15 esté lista y pulsa \"Volver a grabar el RP2040\".", + "Wait for V15 to be ready and press \"Reprogram the RP2040\"."), 0); } break; case "wait": diff --git a/android/rescue/app/src/main/java/fm/jiant/rescue/RescueImage.java b/android/rescue/app/src/main/java/fm/jiant/rescue/RescueImage.java index 0b8eabda..23fca73e 100644 --- a/android/rescue/app/src/main/java/fm/jiant/rescue/RescueImage.java +++ b/android/rescue/app/src/main/java/fm/jiant/rescue/RescueImage.java @@ -26,6 +26,10 @@ public final class RescueImage { public static final int LOADER_LEN = 24064; public static final String LOADER_SHA256 = "d41da6126760c9d66660bcc0cac8d27d221806c5e369a8036921efe68dca5376"; + /** The official M-VAVE V15 FM-1.fwsc (file sha256 db1642b2..., the genuine one), as kept in + * Quixotic7/FM1Backups at a pinned commit; checkV15 accepts it only by its region hash. */ + public static final String V15_URL = "https://raw.githubusercontent.com/Quixotic7/FM1Backups/" + + "8cbc3b066ed15ec6a0d5a990efb78b56f6c17183/V15-FM-1.fwsc"; public static final String LOADER_URL = "https://raw.githubusercontent.com/kagaimiq/jl-uboot-tool/" + "adb3f18889e88ac512ce0a3c4d8cc3d3cb30696a/data/loaderblobs/usb/wl82loader.bin";