forked from Blendman974/faceclaw
Firmware uninstall/revert-to-stock for G1s
This commit is contained in:
1 parent
e103b89510
commit
479308f4a6
17 files changed
+1014
-98
No files matched your search
@@ -1,29 +1,34 @@
|
||||
/**
|
||||
* Prepares the g1v0 image on the phone, as app/g2/firmware-builder.ts does for a G2: downloads Even's public firmware,
|
||||
* checks it, and puts the parts this firmware embeds back into what the app ships. The result is byte for byte the
|
||||
* image that was built, tested and signed, and it is checked to be. It does not touch the glasses.
|
||||
* image that was built, tested and signed, and it is checked to be. Also prepares Even's own images for an uninstall.
|
||||
* It does not touch the glasses.
|
||||
*/
|
||||
import { knownFolders } from "@nativescript/core";
|
||||
|
||||
import { firmwareSha256, writeFirmwareFile } from "../native/firmware-files";
|
||||
import { decodeBase64 } from "../util/base64";
|
||||
import { fetchWithUserAgent } from "../util/http";
|
||||
import { EVEN_G1_RESTORE } from "./even-firmware";
|
||||
import { G1V0_IMAGE } from "./firmware/g1v0-image";
|
||||
import { G1V0_OWN_BYTES_BASE64 } from "./firmware/g1v0-own-bytes";
|
||||
import { assembleG1Image, decodeG1OwnBytes, G1FirmwareError, readZipEntry } from "./firmware-image";
|
||||
import { assembleG1Image, decodeG1OwnBytes, extractEvenG1Images, G1FirmwareError, readZipEntry } from "./firmware-image";
|
||||
|
||||
export type G1BuildProgress = "downloading" | "verifying" | "assembling" | "writing";
|
||||
|
||||
export type BuiltG1Firmware = { path: string; bytes: number; version: string };
|
||||
|
||||
/** Even's release for an uninstall: the application core's image and the network core's. */
|
||||
export type BuiltEvenG1Firmware = { appPath: string; netCorePath: string; bytes: number; version: string };
|
||||
|
||||
function sha256(bytes: Uint8Array): string {
|
||||
return firmwareSha256(bytes.slice().buffer);
|
||||
}
|
||||
|
||||
async function downloadStockZip(): Promise<Uint8Array> {
|
||||
async function downloadStockZip(url: string): Promise<Uint8Array> {
|
||||
let response: Response;
|
||||
try {
|
||||
response = await fetchWithUserAgent(G1V0_IMAGE.stockZipUrl);
|
||||
response = await fetchWithUserAgent(url);
|
||||
} catch (error) {
|
||||
throw new G1FirmwareError(`Could not reach Even's firmware server: ${(error as Error)?.message ?? error}`);
|
||||
}
|
||||
@@ -33,7 +38,7 @@ async function downloadStockZip(): Promise<Uint8Array> {
|
||||
|
||||
export async function buildG1Firmware(onProgress?: (progress: G1BuildProgress) => void): Promise<BuiltG1Firmware> {
|
||||
onProgress?.("downloading");
|
||||
const zip = await downloadStockZip();
|
||||
const zip = await downloadStockZip(G1V0_IMAGE.stockZipUrl);
|
||||
|
||||
onProgress?.("verifying");
|
||||
const zipHash = sha256(zip);
|
||||
@@ -50,3 +55,19 @@ export async function buildG1Firmware(onProgress?: (progress: G1BuildProgress) =
|
||||
writeFirmwareFile(path, image.slice().buffer);
|
||||
return { path, bytes: image.length, version: G1V0_IMAGE.version };
|
||||
}
|
||||
|
||||
export async function buildEvenG1Firmware(onProgress?: (progress: G1BuildProgress) => void): Promise<BuiltEvenG1Firmware> {
|
||||
onProgress?.("downloading");
|
||||
const zip = await downloadStockZip(EVEN_G1_RESTORE.zipUrl);
|
||||
|
||||
onProgress?.("verifying");
|
||||
const { app, netCore } = extractEvenG1Images(zip, EVEN_G1_RESTORE, sha256);
|
||||
|
||||
onProgress?.("writing");
|
||||
const folder = knownFolders.documents().path;
|
||||
const appPath = `${folder}/even_g1_${EVEN_G1_RESTORE.version}_app.bin`;
|
||||
const netCorePath = `${folder}/even_g1_${EVEN_G1_RESTORE.version}_net.bin`;
|
||||
writeFirmwareFile(appPath, app.slice().buffer);
|
||||
writeFirmwareFile(netCorePath, netCore.slice().buffer);
|
||||
return { appPath, netCorePath, bytes: app.length + netCore.length, version: EVEN_G1_RESTORE.version };
|
||||
}
|
||||
Reference in new issue
Block a user