]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
expo: Tidy up the expo.py tool and usage
authorSimon Glass <sjg@chromium.org>
Mon, 14 Aug 2023 22:40:28 +0000 (16:40 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 25 Aug 2023 17:54:33 +0000 (13:54 -0400)
Tidy up this tool a little:

- define which arguments are needed
- split the enum values out into a header file
- warn if no enum values are found
- display the dtc error if something goes wrong
- avoid a Python traceback on error

Signed-off-by: Simon Glass <sjg@chromium.org>
doc/develop/expo.rst
test/boot/files/expo_ids.h [new file with mode: 0644]
test/boot/files/expo_layout.dts
test/py/tests/test_ut.py
tools/expo.py

index 2ac4af232da46dba3b1048af685e6b419cef193a..0643283ae4815f335907c0fd9e69bbd93ffcdff4 100644 (file)
@@ -367,22 +367,27 @@ strings are provided inline in the nodes where they are used.
 
 ::
 
-    #define ID_PROMPT           1
-    #define ID_SCENE1           2
-    #define ID_SCENE1_TITLE     3
-
-    #define ID_CPU_SPEED        4
-    #define ID_CPU_SPEED_TITLE  5
-    #define ID_CPU_SPEED_1      6
-    #define ID_CPU_SPEED_2      7
-    #define ID_CPU_SPEED_3      8
-
-    #define ID_POWER_LOSS       9
-    #define ID_AC_OFF           10
-    #define ID_AC_ON            11
-    #define ID_AC_MEMORY        12
-
-    #define ID_DYNAMIC_START    13
+    /* this comment is parsed by the expo.py tool to insert the values below
+
+    enum {
+        ZERO,
+        ID_PROMPT,
+        ID_SCENE1,
+        ID_SCENE1_TITLE,
+
+        ID_CPU_SPEED,
+        ID_CPU_SPEED_TITLE,
+        ID_CPU_SPEED_1,
+        ID_CPU_SPEED_2,
+        ID_CPU_SPEED_3,
+
+        ID_POWER_LOSS,
+        ID_AC_OFF,
+        ID_AC_ON,
+        ID_AC_MEMORY,
+
+        ID_DYNAMIC_START,
+    */
 
     &cedit {
         dynamic-start = <ID_DYNAMIC_START>;
diff --git a/test/boot/files/expo_ids.h b/test/boot/files/expo_ids.h
new file mode 100644 (file)
index 0000000..027d44b
--- /dev/null
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Sample expo screen layout (ID numbers)
+ */
+
+enum {
+       ZERO,
+       ID_PROMPT,
+
+       ID_SCENE1,
+       ID_SCENE1_TITLE,
+
+       ID_CPU_SPEED,
+       ID_CPU_SPEED_TITLE,
+       ID_CPU_SPEED_1,
+       ID_CPU_SPEED_2,
+       ID_CPU_SPEED_3,
+
+       ID_POWER_LOSS,
+       ID_AC_OFF,
+       ID_AC_ON,
+       ID_AC_MEMORY,
+
+       ID_DYNAMIC_START,
+};
index 55d5c910dd5e4b983b716c29c09b5a313d4cf51b..913140bace9830aaa52af7cf8a242a6607e7e9cd 100644 (file)
@@ -5,28 +5,7 @@
 
 /dts-v1/;
 
-/*
-enum {
-       ZERO,
-       ID_PROMPT,
-
-       ID_SCENE1,
-       ID_SCENE1_TITLE,
-
-       ID_CPU_SPEED,
-       ID_CPU_SPEED_TITLE,
-       ID_CPU_SPEED_1,
-       ID_CPU_SPEED_2,
-       ID_CPU_SPEED_3,
-
-       ID_POWER_LOSS,
-       ID_AC_OFF,
-       ID_AC_ON,
-       ID_AC_MEMORY,
-
-       ID_DYNAMIC_START,
-};
-*/
+/* see expo_ids.h for the IDs */
 
 / {
        dynamic-start = <ID_DYNAMIC_START>;
index aa1d477cd5653e0c5511668b2c35c83f32e1dc3e..6a59c306322f422076c65fcc0ce2c660d96912fa 100644 (file)
@@ -285,10 +285,12 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
 def setup_cedit_file(cons):
     infname = os.path.join(cons.config.source_dir,
                            'test/boot/files/expo_layout.dts')
+    inhname = os.path.join(cons.config.source_dir,
+                           'test/boot/files/expo_ids.h')
     expo_tool = os.path.join(cons.config.source_dir, 'tools/expo.py')
     outfname = 'cedit.dtb'
     u_boot_utils.run_and_log(
-        cons, f'{expo_tool} -e {infname} -l {infname} -o {outfname}')
+        cons, f'{expo_tool} -e {inhname} -l {infname} -o {outfname}')
 
 
 @pytest.mark.buildconfigspec('ut_dm')
index c6eb87aec739960b737fa8cb36d6ff5659e36b81..ea80c70f04e3b911605245b1efadaa5ae7d0ecf3 100755 (executable)
@@ -69,7 +69,10 @@ def calc_ids(fname):
 
 def run_expo(args):
     """Run the expo program"""
-    ids = calc_ids(args.enum_fname)
+    fname = args.enum_fname or args.layout
+    ids = calc_ids(fname)
+    if not ids:
+        print(f"Warning: No enum ID values found in file '{fname}'")
 
     indata = tools.read_file(args.layout)
 
@@ -88,10 +91,10 @@ def run_expo(args):
 
     with open('/tmp/asc', 'wb') as outf:
         outf.write(data)
-    proc = subprocess.run('dtc', input=data, capture_output=True, check=True)
+    proc = subprocess.run('dtc', input=data, capture_output=True)
     edtb = proc.stdout
     if proc.stderr:
-        print(proc.stderr)
+        print(f"Devicetree compiler error:\n{proc.stderr.decode('utf-8')}")
         return 1
     tools.write_file(args.outfile, edtb)
     return 0
@@ -109,11 +112,13 @@ def parse_args(argv):
             args is a list of string arguments
     """
     parser = argparse.ArgumentParser()
+    parser.add_argument('-D', '--debug', action='store_true',
+        help='Enable full debug traceback')
     parser.add_argument('-e', '--enum-fname', type=str,
-        help='C file containing enum declaration for expo items')
-    parser.add_argument('-l', '--layout', type=str,
-        help='Devicetree file source .dts for expo layout')
-    parser.add_argument('-o', '--outfile', type=str,
+        help='.dts or C file containing enum declaration for expo items')
+    parser.add_argument('-l', '--layout', type=str, required=True,
+        help='Devicetree file source .dts for expo layout (and perhaps enums)')
+    parser.add_argument('-o', '--outfile', type=str, required=True,
         help='Filename to write expo layout dtb')
 
     return parser.parse_args(argv)
@@ -122,6 +127,9 @@ def start_expo():
     """Start the expo program"""
     args = parse_args(sys.argv[1:])
 
+    if not args.debug:
+        sys.tracebacklimit = 0
+
     ret_code = run_expo(args)
     sys.exit(ret_code)