diff options
author | Nicholas Sudsgaard <devel+coreboot@nsudsgaard.com> | 2024-10-05 05:25:51 +0000 |
---|---|---|
committer | Martin L Roth <gaumless@gmail.com> | 2024-10-07 21:10:03 +0000 |
commit | 33b2fb93bbf368b7b34fa9bd5de7f9edeb55ad11 (patch) | |
tree | 60034d85314f54ff41de0c0e490cf64a0128a604 /util/hda-decoder/main.go | |
parent | 1ec25777df4bd40f174fd7083ce60aec46141e2b (diff) |
util/hda-decoder: Add feature to print configuration defaults as verbs
This feature simply goes through pin configurations stored in a file and
converts them into their corresponding verbs. This can be useful when
trying to find verb data stored inside a binary (e.g. when reverse
engineering).
Input:
0x16 0x04211040
0x17 0x91170110
0x18 0x40f001f0
Output:
address: 0, node ID: 0x16, configuration default: 0x04211040
0x01671c40
0x01671d10
0x01671e21
0x01671f04
address: 0, node ID: 0x17, configuration default: 0x91170110
0x01771c10
0x01771d01
0x01771e17
0x01771f91
address: 0, node ID: 0x18, configuration default: 0x40f001f0
0x01871cf0
0x01871d01
0x01871ef0
0x01871f40
Change-Id: I1fb74ff4b2b654987fd25ee32d0f94e5f2f783e3
Signed-off-by: Nicholas Sudsgaard <devel+coreboot@nsudsgaard.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/84669
Reviewed-by: Paul Menzel <paulepanter@mailbox.org>
Reviewed-by: Sean Rhodes <sean@starlabs.systems>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'util/hda-decoder/main.go')
-rw-r--r-- | util/hda-decoder/main.go | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/util/hda-decoder/main.go b/util/hda-decoder/main.go index d686f19967..c0a88adf2e 100644 --- a/util/hda-decoder/main.go +++ b/util/hda-decoder/main.go @@ -14,6 +14,13 @@ import ( "strings" ) +type decodeOperation int + +const ( + decodeToHumanReadable decodeOperation = iota + decodeToVerbs +) + var indentLevel int = 0 func indentedPrintf(format string, args ...interface{}) (n int, err error) { @@ -58,7 +65,7 @@ func printDisconnectedPort(config uint32) { } } -func decodeFile(path string, codec uint32) { +func decodeFile(path string, codec uint32, operation decodeOperation) { file, err := os.Open(path) if err != nil { log.Fatal(err) @@ -77,15 +84,27 @@ func decodeFile(path string, codec uint32) { pin := stringToUint32(fields[0]) config := stringToUint32(fields[1]) - indentedPrintf("AZALIA_PIN_CFG(%d, 0x%02x, ", codec, pin) - if decoder.PortIsConnected(config) { - fmt.Printf("AZALIA_PIN_DESC(\n") - indentLevel += 1 - decodeConfig(config) - indentLevel -= 1 - indentedPrintf(")),\n") - } else { - printDisconnectedPort(config) + switch operation { + case decodeToVerbs: + fmt.Printf("address: %d, node ID: %#02x, configuration default: %#08x\n", + codec, pin, config) + + verbs := decoder.ConfigToVerbs(codec, pin, config) + fmt.Printf(" %#08x\n", verbs[0]) + fmt.Printf(" %#08x\n", verbs[1]) + fmt.Printf(" %#08x\n", verbs[2]) + fmt.Printf(" %#08x\n", verbs[3]) + case decodeToHumanReadable: + indentedPrintf("AZALIA_PIN_CFG(%d, 0x%02x, ", codec, pin) + if decoder.PortIsConnected(config) { + fmt.Printf("AZALIA_PIN_DESC(\n") + indentLevel += 1 + decodeConfig(config) + indentLevel -= 1 + indentedPrintf(")),\n") + } else { + printDisconnectedPort(config) + } } } } @@ -116,7 +135,7 @@ func decodeDeviceCodec(path string, codec uint32, isLastCodec bool, generate boo indentedPrintf("AZALIA_SUBVENDOR(%d, %s),\n\n", codec, subsystemId) } - decodeFile(path+"/init_pin_configs", codec) + decodeFile(path+"/init_pin_configs", codec, decodeToHumanReadable) if !isLastCodec { fmt.Printf("\n") } @@ -155,12 +174,19 @@ func main() { file := flag.String("file", "", "Decode configurations in a file\n"+ "The decoder assumes each line in the file has the format: <pin> <config>") generate := flag.Bool("generate", false, "Automatically generate hda_verb.c for the host device") + toVerbs := flag.Bool("to-verbs", false, "Convert configuration defaults to their corresponding verbs\n"+ + "This flag is only meaningful in combination with the 'file' flag") flag.Parse() + operation := decodeToHumanReadable + if *toVerbs { + operation = decodeToVerbs + } + if isFlagPassed("config") { decodeConfig(uint32(*config)) } else if isFlagPassed("file") { - decodeFile(*file, uint32(*codec)) + decodeFile(*file, uint32(*codec), operation) } else { if *generate { fmt.Printf("/* SPDX-License-Identifier: GPL-2.0-only */\n\n") |