* feat(artifacts): add U-Boot legacy uImage reader (part of #7129) Recognize legacy uImages by their 0x27051956 magic and inventory them as containers: 64-byte header facts (arch/os/type/compression raw and named, load/entry addresses, name, timestamp) with header and data CRC32 verified, stored payload extractable as payload.bin, and multi-file images split from the stored size table into image-<n>.bin. Compressed payloads stay as stored; nothing is executed or decompressed. Wires the format through classification, the artifact reader dispatch, extraction, and the evidence/snapshot format vocabularies. Related to #7129 (uImage part only); HEX/SREC and FIT are out of scope. * fix(uimage): preserve aligned component ranges and exact header facts * fix(uimage): retain buffered members through consumption and cancellation * fix(uimage): preserve active read and validation failure precedence --------- Co-authored-by: gensokyo-dev <[email protected]>
85 lines
2.8 KiB
TypeScript
85 lines
2.8 KiB
TypeScript
import { readFile, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { expect } from "vitest";
|
|
|
|
import { cliTest } from "../support/cli/cliFixture.js";
|
|
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
|
import { buildMultiPayload, buildUImage } from "../fixtures/uimage.js";
|
|
import { parseEvidence } from "../../src/domain/evidence.js";
|
|
import { artifactInspectionResultSchema } from "../../src/domain/artifactInspection.js";
|
|
import {
|
|
artifactExtractionResultSchema,
|
|
artifactInventoryResultSchema,
|
|
} from "../../src/domain/artifactGraph.js";
|
|
|
|
cliTest(
|
|
"inspects and extracts a uImage through the compiled CLI",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-uimage-cli-");
|
|
const partA = Buffer.from("first-part");
|
|
const partB = Buffer.from("second-part");
|
|
const source = join(root, "firmware.bin");
|
|
await writeFile(
|
|
source,
|
|
buildUImage({
|
|
arch: 22,
|
|
os: 14,
|
|
type: 4,
|
|
compression: 0,
|
|
loadAddress: 0x8000,
|
|
entryPoint: 0x8000,
|
|
name: "multi-test",
|
|
payload: buildMultiPayload([partA, partB]),
|
|
}),
|
|
);
|
|
const inspected = await cli.run({
|
|
arguments: ["inspect-artifact", source, "--json"],
|
|
});
|
|
expect(inspected.exitCode, inspected.stdout + inspected.stderr).toBe(0);
|
|
const inspection = artifactInspectionResultSchema.parse(
|
|
parseEvidence(inspected.json).normalized_result,
|
|
);
|
|
const graph = artifactInventoryResultSchema.parse(
|
|
inspection.substeps[0]?.evidence.normalized_result,
|
|
);
|
|
expect(graph.manifest.root_format).toBe("uimage");
|
|
expect(graph.coverage.status).toBe("complete");
|
|
expect(
|
|
graph.occurrences.find((row) => row.logical_path === ".")
|
|
?.format_metadata,
|
|
).toMatchObject({
|
|
kind: "uimage",
|
|
arch: 22,
|
|
arch_name: "arm64",
|
|
os: 14,
|
|
os_name: "vxworks",
|
|
type_name: "multi",
|
|
compression_name: "none",
|
|
name: "multi-test",
|
|
crc_verified: true,
|
|
sub_image_count: 2,
|
|
});
|
|
const extracted = await cli.run({
|
|
arguments: ["extract-artifact", source, "--json"],
|
|
environment: { TMPDIR: root, TMP: root, TEMP: root },
|
|
});
|
|
expect(extracted.exitCode, extracted.stdout + extracted.stderr).toBe(0);
|
|
const result = artifactExtractionResultSchema.parse(
|
|
parseEvidence(extracted.json).normalized_result,
|
|
);
|
|
expect(result.containment_verified).toBe(true);
|
|
expect(
|
|
(await readFile(join(result.output_root, "payload.bin"))).equals(
|
|
buildMultiPayload([partA, partB]),
|
|
),
|
|
).toBe(true);
|
|
expect(
|
|
(await readFile(join(result.output_root, "image-0.bin"))).equals(partA),
|
|
).toBe(true);
|
|
expect(
|
|
(await readFile(join(result.output_root, "image-1.bin"))).equals(partB),
|
|
).toBe(true);
|
|
},
|
|
);
|