aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / scripts / fetch_gpu_ucode.sh
| 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 | |
| 8 | set -e |
| 9 | |
| 10 | # Work from the repo root whatever the caller's directory (the .inc lands in $REPO/target). |
| 11 | ROOT=$(cd "$(dirname "$0")/.." && pwd) |
| 12 | cd "$ROOT" |
| 13 | |
| 14 | OUT=target/native-kernel |
| 15 | mkdir -p "$OUT" |
| 16 | |
| 17 | LINUX_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 | |
| 23 | fetch_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 | |
| 42 | echo "Fetching polaris11 firmware blobs..." |
| 43 | fetch_blob polaris11_pfp.bin "$SHA_PFP" |
| 44 | fetch_blob polaris11_me.bin "$SHA_ME" |
| 45 | fetch_blob polaris11_ce.bin "$SHA_CE" |
| 46 | fetch_blob polaris11_mec.bin "$SHA_MEC" |
| 47 | fetch_blob polaris11_mec2.bin "$SHA_MEC2" |
| 48 | fetch_blob polaris11_rlc.bin "$SHA_RLC" |
| 49 | fetch_blob polaris11_sdma.bin "$SHA_SDMA" |
| 50 | fetch_blob polaris11_sdma1.bin "$SHA_SDMA1" |
| 51 | fetch_blob polaris11_smc.bin "$SHA_SMC" |
| 52 | |
| 53 | echo "Generating $OUT/gpu_ucode.inc..." |
| 54 | cat > "$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). */ |
| 57 | HEADER |
| 58 | |
| 59 | embed_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 | |
| 72 | embed_blob polaris11_pfp.bin pfp_ucode PFP_UCODE_SIZE |
| 73 | embed_blob polaris11_me.bin me_ucode ME_UCODE_SIZE |
| 74 | embed_blob polaris11_ce.bin ce_ucode CE_UCODE_SIZE |
| 75 | embed_blob polaris11_mec.bin mec_ucode MEC_UCODE_SIZE |
| 76 | embed_blob polaris11_mec2.bin mec2_ucode MEC2_UCODE_SIZE |
| 77 | embed_blob polaris11_rlc.bin rlc_ucode RLC_UCODE_SIZE |
| 78 | |
| 79 | echo "gpu_ucode.inc ready. Build with: make imac-kernel CK_X86_GPU_UCODE=1" |