From patchwork Mon Jan 27 05:05:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240196 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Sun, 26 Jan 2020 22:05:51 -0700 Subject: [PATCH 044/108] dtoc: Support ACPI paths in of-platdata In-Reply-To: <20200127050655.170614-1-sjg@chromium.org> References: <20200127050655.170614-1-sjg@chromium.org> Message-ID: <20200126220508.44.I59ad0c1b7fc217bc1d2e798324e2dec7db02a3aa@changeid> The start of an ACPI path typically has backslashes in it. These are not preserved during the translation from device tree to C code, since dtc (correctly) uses the first backslash as an escape character, and dtoc therefore leaves it out of the C string. Fix this with special-case handling. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 4 +++- tools/dtoc/dtoc_test_simple.dts | 1 + tools/dtoc/test_dtoc.py | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 037e82c8bb..7bd9a5474e 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -102,7 +102,9 @@ def get_value(ftype, value): elif ftype == fdt.TYPE_BYTE: return '%#x' % tools.ToByte(value[0]) elif ftype == fdt.TYPE_STRING: - return '"%s"' % value + # Handle evil ACPI backslashes by adding another backslash before them. + # So "\\_SB.GPO0" in the device tree effectively stays like that in C + return '"%s"' % value.replace('\\', '\\\\') elif ftype == fdt.TYPE_BOOL: return 'true' elif ftype == fdt.TYPE_INT64: diff --git a/tools/dtoc/dtoc_test_simple.dts b/tools/dtoc/dtoc_test_simple.dts index 165680bd4b..11bfc4c47a 100644 --- a/tools/dtoc/dtoc_test_simple.dts +++ b/tools/dtoc/dtoc_test_simple.dts @@ -34,6 +34,7 @@ longbytearray = [09 0a 0b 0c]; stringval = "message2"; stringarray = "another", "multi-word", "message"; + acpi-name = "\\_SB.GPO0"; }; spl-test3 { diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index d733b70655..6246ce45f5 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -70,6 +70,7 @@ class TestDtoc(unittest.TestCase): @classmethod def setUpClass(cls): tools.PrepareOutputDir(None) + cls.maxDiff = None @classmethod def tearDownClass(cls): @@ -181,6 +182,7 @@ struct dtd_sandbox_pmic_test { \tfdt64_t\t\treg[2]; }; struct dtd_sandbox_spl_test { +\tconst char * acpi_name; \tbool\t\tboolval; \tunsigned char\tbytearray[3]; \tunsigned char\tbyteval; @@ -218,6 +220,7 @@ U_BOOT_DEVICE(spl_test) = { }; static const struct dtd_sandbox_spl_test dtv_spl_test2 = { +\t.acpi_name\t\t= "\\\\_SB.GPO0", \t.bytearray\t\t= {0x1, 0x23, 0x34}, \t.byteval\t\t= 0x8, \t.intarray\t\t= {0x5, 0x0, 0x0, 0x0},