From 07c454a7176bb5396ae37b718486b6097547eeed Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Thu, 11 Nov 2021 00:23:23 -0800 Subject: [PATCH] firmware: Generate android-info.txt from device and version info --- src/blobs/build.ts | 11 ++++++++--- src/commands/generate-full.ts | 18 +++++++++++++----- src/factory/firmware.ts | 25 ++++++++++--------------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/blobs/build.ts b/src/blobs/build.ts index 9bdde62..2ce9de9 100644 --- a/src/blobs/build.ts +++ b/src/blobs/build.ts @@ -15,6 +15,7 @@ export interface BuildFiles { export interface VendorDirectories { outDir: string proprietaryDir: string + fwDir: string } function nameDepKey(entry: BlobEntry) { @@ -131,15 +132,19 @@ export async function generateBuild( export async function createVendorDirs(vendor: string, device: string) { let outDir = `vendor/${vendor}/${device}` - await fs.rm(outDir, {force: true, recursive: true}) - await fs.mkdir(outDir, {recursive: true}) + await fs.rm(outDir, { force: true, recursive: true }) + await fs.mkdir(outDir, { recursive: true }) let proprietaryDir = `${outDir}/proprietary` - await fs.mkdir(proprietaryDir, {recursive: true}) + await fs.mkdir(proprietaryDir, { recursive: true }) + + let fwDir = `${proprietaryDir}/firmware` + await fs.mkdir(fwDir, { recursive: true }) return { outDir: outDir, proprietaryDir: proprietaryDir, + fwDir: fwDir, } as VendorDirectories } diff --git a/src/commands/generate-full.ts b/src/commands/generate-full.ts index 9a2f447..d0626c2 100644 --- a/src/commands/generate-full.ts +++ b/src/commands/generate-full.ts @@ -12,7 +12,7 @@ import { findOverrideModules } from '../build/overrides' import { parseModuleInfo } from '../build/soong-info' import { parseDeviceConfig } from '../config/device' import { parseSystemState, SystemState } from '../config/system-state' -import { ANDROID_INFO, extractFactoryFirmware, writeFirmwareImages } from '../factory/firmware' +import { ANDROID_INFO, extractFactoryFirmware, generateAndroidInfo, writeFirmwareImages } from '../factory/firmware' import { diffPartContexts, parseContextsRecursive, parsePartContexts, resolvePartContextDiffs, SelinuxContexts } from '../sepolicy/contexts' import { startActionSpinner, stopActionSpinner } from '../util/cli' import { ALL_PARTITIONS } from '../util/partitions' @@ -96,7 +96,7 @@ export default class GenerateFull extends Command { // 4. Extract // Prepare output directories - let {proprietaryDir} = await createVendorDirs(config.device.vendor, config.device.name) + let {proprietaryDir, fwDir} = await createVendorDirs(config.device.vendor, config.device.name) // Copy blobs (this has its own spinner) if (!skipCopy) { await copyBlobs(entries, stockRoot, proprietaryDir) @@ -149,7 +149,16 @@ export default class GenerateFull extends Command { if (factoryZip != undefined) { spinner = startActionSpinner('Extracting firmware') let fwImages = await extractFactoryFirmware(factoryZip) - fwPaths = await writeFirmwareImages(fwImages, proprietaryDir) + fwPaths = await writeFirmwareImages(fwImages, fwDir) + + // Generate android-info.txt from device and versions + let androidInfo = generateAndroidInfo( + config.device.name, + stockProps.get('vendor')!.get('ro.build.expect.bootloader')!, + stockProps.get('vendor')!.get('ro.build.expect.baseband')!, + ) + await fs.writeFile(`${fwDir}/${ANDROID_INFO}`, androidInfo) + stopActionSpinner(spinner) } @@ -173,9 +182,8 @@ export default class GenerateFull extends Command { // Add firmware if (fwPaths != null) { - build.boardMakefile.boardInfo = fwPaths.find(p => p.includes(ANDROID_INFO)) + build.boardMakefile.boardInfo = `${fwDir}/${ANDROID_INFO}` build.modulesMakefile.radioFiles = fwPaths.map(p => path.relative(proprietaryDir, p)) - .filter(p => !p.includes(ANDROID_INFO)) } // Dump list diff --git a/src/factory/firmware.ts b/src/factory/firmware.ts index 66b650b..c26dc6a 100644 --- a/src/factory/firmware.ts +++ b/src/factory/firmware.ts @@ -7,13 +7,6 @@ export const ANDROID_INFO = 'android-info.txt' export type FirmwareImages = Map -async function extractNestedImages(images: FirmwareImages, nestedZip: ArrayBuffer) { - let { entries } = await unzipit.unzip(nestedZip) - if (ANDROID_INFO in entries) { - images.set(ANDROID_INFO, await entries[ANDROID_INFO].arrayBuffer()) - } -} - export async function extractFactoryFirmware(zipPath: string) { let reader = new NodeFileReader(zipPath) let images: FirmwareImages = new Map() @@ -23,10 +16,7 @@ export async function extractFactoryFirmware(zipPath: string) { // Find images for (let [name, entry] of Object.entries(entries)) { - if (name.includes('/image-')) { - // Extract nested zip to get android-info.txt - await extractNestedImages(images, await entry.arrayBuffer()) - } else if (name.includes('/bootloader-')) { + if (name.includes('/bootloader-')) { images.set('bootloader.img', await entry.arrayBuffer()) } else if (name.includes('/radio-')) { images.set('radio.img', await entry.arrayBuffer()) @@ -39,10 +29,7 @@ export async function extractFactoryFirmware(zipPath: string) { } } -export async function writeFirmwareImages(images: FirmwareImages, proprietaryDir: string) { - let fwDir = `${proprietaryDir}/firmware` - await fs.mkdir(fwDir, { recursive: true }) - +export async function writeFirmwareImages(images: FirmwareImages, fwDir: string) { let paths = [] for (let [name, buffer] of images.entries()) { let path = `${fwDir}/${name}` @@ -52,3 +39,11 @@ export async function writeFirmwareImages(images: FirmwareImages, proprietaryDir return paths } + +export function generateAndroidInfo(device: string, blVersion: string, radioVersion: string) { + return `require board=${device} + +require version-bootloader=${blVersion} +require version-baseband=${radioVersion} +` +}