interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / scripts / fetch_gpu_ucode.sh

79 lines · 2986 bytes Raw Blame History
1#!/bin/sh
2# scripts/fetch_gpu_ucode.sh -- Fetch AMD polaris11 firmware blobs from linux-firmware
3# and verify SHA-256 before embedding. Never commit the blobs.
4# Run from the repo root: sh scripts/fetch_gpu_ucode.sh
5# Produces: target/native-kernel/gpu_ucode.inc (C arrays for amd_ucode.c)
6# AMD firmware is redistributable under AMD's license; see THIRD_PARTY_NOTICES.
7
8set -e
9
10# Work from the repo root whatever the caller's directory (the .inc lands in $REPO/target).
11ROOT=$(cd "$(dirname "$0")/.." && pwd)
12cd "$ROOT"
13
14OUT=target/native-kernel
15mkdir -p "$OUT"
16
17LINUX_FW_BASE="https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/amdgpu"
18
19# Pinned SHA-256 hashes and the upstream commit they were taken from.
20# Source: scripts/gpu_ucode_sha256.txt
21. scripts/gpu_ucode_sha256.txt
22
23fetch_blob() {
24 local name="$1" sha="$2"
25 local path="$OUT/$name"
26 if [ -f "$path" ]; then
27 echo " $name: already present, checking SHA256..."
28 else
29 echo " $name: fetching at $LINUX_FW_COMMIT..."
30 curl -fsSL "$LINUX_FW_BASE/$name?id=$LINUX_FW_COMMIT" -o "$path"
31 fi
32 local actual
33 actual=$(sha256sum "$path" | awk '{print $1}')
34 if [ "$actual" != "$sha" ]; then
35 echo " ERROR: $name SHA256 mismatch (expected $sha got $actual)" >&2
36 rm -f "$path"
37 exit 1
38 fi
39 echo " $name: OK ($sha)"
40}
41
42echo "Fetching polaris11 firmware blobs..."
43fetch_blob polaris11_pfp.bin "$SHA_PFP"
44fetch_blob polaris11_me.bin "$SHA_ME"
45fetch_blob polaris11_ce.bin "$SHA_CE"
46fetch_blob polaris11_mec.bin "$SHA_MEC"
47fetch_blob polaris11_mec2.bin "$SHA_MEC2"
48fetch_blob polaris11_rlc.bin "$SHA_RLC"
49fetch_blob polaris11_sdma.bin "$SHA_SDMA"
50fetch_blob polaris11_sdma1.bin "$SHA_SDMA1"
51fetch_blob polaris11_smc.bin "$SHA_SMC"
52
53echo "Generating $OUT/gpu_ucode.inc..."
54cat > "$OUT/gpu_ucode.inc" << 'HEADER'
55/* target/native-kernel/gpu_ucode.inc -- auto-generated by scripts/fetch_gpu_ucode.sh
56 * Do not commit: blobs are not checked in (see scripts/gpu_ucode_sha256.txt for pins). */
57HEADER
58
59embed_blob() {
60 local name="$1" varname="$2" sizevar="$3"
61 local path="$OUT/$name"
62 local size
63 size=$(stat -c %s "$path")
64 local dwords=$(( size / 4 ))
65 printf "static const uint32_t g_%s[] = {\n" "$varname" >> "$OUT/gpu_ucode.inc"
66 od -An -tx4 -v "$path" | tr -s ' ' | sed 's/ \([0-9a-f]\{8\}\)/0x\1u,/g' >> "$OUT/gpu_ucode.inc"
67 printf "};\n" >> "$OUT/gpu_ucode.inc"
68 printf "#define %s %uu\n" "$sizevar" "$dwords" >> "$OUT/gpu_ucode.inc"
69 echo " embedded $name: $dwords dwords"
70}
71
72embed_blob polaris11_pfp.bin pfp_ucode PFP_UCODE_SIZE
73embed_blob polaris11_me.bin me_ucode ME_UCODE_SIZE
74embed_blob polaris11_ce.bin ce_ucode CE_UCODE_SIZE
75embed_blob polaris11_mec.bin mec_ucode MEC_UCODE_SIZE
76embed_blob polaris11_mec2.bin mec2_ucode MEC2_UCODE_SIZE
77embed_blob polaris11_rlc.bin rlc_ucode RLC_UCODE_SIZE
78
79echo "gpu_ucode.inc ready. Build with: make imac-kernel CK_X86_GPU_UCODE=1"