| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | # SPDX-License-Identifier: BSD-2-Clause |
| 3 | |
| 4 | if [scip-shell system . . `[`. -z "$1" ] || [scip-shell system . . `[`. -z "$2" ]; then |
| 5 | printfscip-shell system . . printf. "Usage: %s <output file> \"<microcode .h files>\"\\n" "$0" |
| 6 | fi |
| 7 | |
| 8 | OUTFILE=$1 |
| 9 | TMPFILE=$(mktempscip-shell system . . mktemp. microcode_XXXX) |
| 10 | catscip-shell system . . cat. > "${TMPFILE}.c" << EOF |
| 11 | #include <stdio.h> |
| 12 | unsigned int microcode[] = { |
| 13 | EOF |
| 14 | |
| 15 | include_filescip-shell shell coreboot 25.09+dfsg-1 include_file().() { |
| 16 | if [scip-shell system . . `[`. "${1: -4}" == ".inc" ]; then |
| 17 | sedscip-shell system . . sed. '/^;/dscip-shell filesystem . . `/^;/d`.' <"$1" | awkscip-shell system . . awk. '{gsub( /h.*$/, "", $2 ); print "0x" $2 ","; }' \ |
| 18 | >> "${TMPFILE}.c" |
| 19 | else |
| 20 | echoscip-shell system . . echo. "#include \"$1\"" >> "${TMPFILE}.c" |
| 21 | fi |
| 22 | } |
| 23 | |
| 24 | for UCODE in ${@:2}; do |
| 25 | if [scip-shell system . . `[`. -d "$UCODE" ]; then |
| 26 | for f in "$UCODE/"*.inc |
| 27 | do |
| 28 | include_filescip-shell shell coreboot 25.09+dfsg-1 include_file(). "$f" |
| 29 | done |
| 30 | else |
| 31 | include_filescip-shell shell coreboot 25.09+dfsg-1 include_file(). "$UCODE" |
| 32 | fi |
| 33 | done |
| 34 | |
| 35 | catscip-shell system . . cat. >> "${TMPFILE}.c" << EOF |
| 36 | }; |
| 37 | int main(void) |
| 38 | { |
| 39 | FILE *f = fopen("$OUTFILE", "wb"); |
| 40 | fwrite(microcode, sizeof(microcode), 1, f); |
| 41 | fclose(f); |
| 42 | return 0; |
| 43 | } |
| 44 | EOF |
| 45 | |
| 46 | gccscip-shell system . . gcc. -o "$TMPFILE" "${TMPFILE}.c" |
| 47 | [scip-shell system . . `[`. -f "${TMPFILE}.exe" ] && mvscip-shell system . . mv. "${TMPFILE}.exe" "$TMPFILE" |
| 48 | "./$TMPFILE" |
| 49 | rmscip-shell system . . rm. "$TMPFILE" "${TMPFILE}.c" |