mb/dell/snb_ivb_latitude/*/hda_verb.c: Use AZALIA_PIN_DESC macro
[coreboot.git] / util / scripts / ucode_h_to_bin.sh
blobe2f80a5d9f048193749827b783050d30d2993bdd
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: BSD-2-Clause
4 if [ -z "$1" ] || [ -z "$2" ]; then
5 printf "Usage: %s <output file> \"<microcode .h files>\"\\n" "$0"
6 fi
8 OUTFILE=$1
9 TMPFILE=$(mktemp microcode_XXXX)
10 cat > "${TMPFILE}.c" << EOF
11 #include <stdio.h>
12 unsigned int microcode[] = {
13 EOF
15 include_file() {
16 if [ "${1: -4}" == ".inc" ]; then
17 sed '/^;/d' <"$1" | awk '{gsub( /h.*$/, "", $2 ); print "0x" $2 ","; }' \
18 >> "${TMPFILE}.c"
19 else
20 echo "#include \"$1\"" >> "${TMPFILE}.c"
24 for UCODE in ${@:2}; do
25 if [ -d "$UCODE" ]; then
26 for f in "$UCODE/"*.inc
28 include_file "$f"
29 done
30 else
31 include_file "$UCODE"
33 done
35 cat >> "${TMPFILE}.c" << EOF
37 int main(void)
39 FILE *f = fopen("$OUTFILE", "wb");
40 fwrite(microcode, sizeof(microcode), 1, f);
41 fclose(f);
42 return 0;
44 EOF
46 gcc -o "$TMPFILE" "${TMPFILE}.c"
47 [ -f "${TMPFILE}.exe" ] && mv "${TMPFILE}.exe" "$TMPFILE"
48 "./$TMPFILE"
49 rm "$TMPFILE" "${TMPFILE}.c"