firmware: Generate android-info.txt from device and version info

This commit is contained in:
Danny Lin 2021-11-11 00:23:23 -08:00
parent 5103d18865
commit 07c454a717
3 changed files with 31 additions and 23 deletions

View file

@ -15,6 +15,7 @@ export interface BuildFiles {
export interface VendorDirectories {
outDir: string
proprietaryDir: string
fwDir: string
}
function nameDepKey(entry: BlobEntry) {
@ -137,9 +138,13 @@ export async function createVendorDirs(vendor: string, device: string) {
let proprietaryDir = `${outDir}/proprietary`
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
}

View file

@ -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

View file

@ -7,13 +7,6 @@ export const ANDROID_INFO = 'android-info.txt'
export type FirmwareImages = Map<string, ArrayBuffer>
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<string, ArrayBuffer>()
@ -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}
`
}