Browse Source

patman: Move library functions into a library directory

The patman directory has a number of modules which are used by other tools
in U-Boot. This makes it hard to package the tools using pypi since the
common files must be copied along with the tool that uses them.

To address this, move these files into a new u_boot_pylib library. This
can be packaged separately and listed as a dependency of each tool.

Signed-off-by: Simon Glass <sjg@chromium.org>
Simon Glass 1 year ago
parent
commit
4583c00236
87 changed files with 182 additions and 151 deletions
  1. 1 1
      scripts/event_dump.py
  2. 1 0
      test/run
  3. 4 4
      tools/binman/bintool.py
  4. 4 4
      tools/binman/bintool_test.py
  5. 1 1
      tools/binman/btool/lz4.py
  6. 1 1
      tools/binman/btool/lzma_alone.py
  7. 2 2
      tools/binman/cbfs_util.py
  8. 2 2
      tools/binman/cbfs_util_test.py
  9. 3 3
      tools/binman/control.py
  10. 3 3
      tools/binman/elf.py
  11. 4 4
      tools/binman/elf_test.py
  12. 3 3
      tools/binman/entry.py
  13. 1 1
      tools/binman/entry_test.py
  14. 1 1
      tools/binman/etype/_testing.py
  15. 1 1
      tools/binman/etype/atf_fip.py
  16. 2 2
      tools/binman/etype/blob.py
  17. 2 2
      tools/binman/etype/blob_ext.py
  18. 2 2
      tools/binman/etype/blob_ext_list.py
  19. 2 2
      tools/binman/etype/fdtmap.py
  20. 1 1
      tools/binman/etype/files.py
  21. 1 1
      tools/binman/etype/fill.py
  22. 1 1
      tools/binman/etype/fit.py
  23. 3 3
      tools/binman/etype/fmap.py
  24. 2 2
      tools/binman/etype/gbb.py
  25. 1 1
      tools/binman/etype/intel_ifwi.py
  26. 1 1
      tools/binman/etype/mkimage.py
  27. 1 1
      tools/binman/etype/null.py
  28. 1 1
      tools/binman/etype/pre_load.py
  29. 3 3
      tools/binman/etype/section.py
  30. 1 1
      tools/binman/etype/text.py
  31. 1 1
      tools/binman/etype/u_boot_dtb_with_ucode.py
  32. 1 1
      tools/binman/etype/u_boot_elf.py
  33. 1 1
      tools/binman/etype/u_boot_env.py
  34. 1 1
      tools/binman/etype/u_boot_spl_bss_pad.py
  35. 1 1
      tools/binman/etype/u_boot_spl_expanded.py
  36. 1 1
      tools/binman/etype/u_boot_tpl_bss_pad.py
  37. 1 1
      tools/binman/etype/u_boot_tpl_expanded.py
  38. 2 2
      tools/binman/etype/u_boot_tpl_with_ucode_ptr.py
  39. 1 1
      tools/binman/etype/u_boot_ucode.py
  40. 1 1
      tools/binman/etype/u_boot_vpl_bss_pad.py
  41. 1 1
      tools/binman/etype/u_boot_vpl_expanded.py
  42. 2 2
      tools/binman/etype/u_boot_with_ucode_ptr.py
  43. 1 1
      tools/binman/etype/vblock.py
  44. 1 1
      tools/binman/fdt_test.py
  45. 2 2
      tools/binman/fip_util.py
  46. 2 2
      tools/binman/fip_util_test.py
  47. 1 1
      tools/binman/fmap_util.py
  48. 4 4
      tools/binman/ftest.py
  49. 2 2
      tools/binman/image.py
  50. 1 1
      tools/binman/image_test.py
  51. 4 3
      tools/binman/main.py
  52. 2 2
      tools/binman/state.py
  53. 3 3
      tools/buildman/builder.py
  54. 1 1
      tools/buildman/builderthread.py
  55. 1 1
      tools/buildman/cfgutil.py
  56. 4 4
      tools/buildman/control.py
  57. 4 4
      tools/buildman/func_test.py
  58. 2 2
      tools/buildman/main.py
  59. 4 4
      tools/buildman/test.py
  60. 3 3
      tools/buildman/toolchain.py
  61. 1 1
      tools/dtoc/fdt.py
  62. 2 2
      tools/dtoc/fdt_util.py
  63. 3 2
      tools/dtoc/main.py
  64. 2 2
      tools/dtoc/test_dtoc.py
  65. 4 3
      tools/dtoc/test_fdt.py
  66. 2 2
      tools/dtoc/test_src_scan.py
  67. 3 4
      tools/patman/__init__.py
  68. 4 4
      tools/patman/__main__.py
  69. 2 2
      tools/patman/checkpatch.py
  70. 1 1
      tools/patman/control.py
  71. 3 3
      tools/patman/func_test.py
  72. 1 1
      tools/patman/get_maintainer.py
  73. 2 2
      tools/patman/gitutil.py
  74. 1 1
      tools/patman/patchstream.py
  75. 2 2
      tools/patman/series.py
  76. 2 2
      tools/patman/status.py
  77. 1 1
      tools/patman/test_settings.py
  78. 1 1
      tools/rmboard.py
  79. 4 0
      tools/u_boot_pylib/__init__.py
  80. 23 0
      tools/u_boot_pylib/__main__.py
  81. 1 1
      tools/u_boot_pylib/command.py
  82. 0 0
      tools/u_boot_pylib/cros_subprocess.py
  83. 0 0
      tools/u_boot_pylib/terminal.py
  84. 1 1
      tools/u_boot_pylib/test_util.py
  85. 2 2
      tools/u_boot_pylib/tools.py
  86. 1 1
      tools/u_boot_pylib/tout.py
  87. 1 0
      tools/u_boot_pylib/u_boot_pylib

+ 1 - 1
scripts/event_dump.py

@@ -15,7 +15,7 @@ src_path = os.path.dirname(our_path)
 sys.path.insert(1, os.path.join(our_path, '../tools'))
 
 from binman import elf
-from patman import tools
+from u_boot_pylib import tools
 
 # A typical symbol looks like this:
 #   _u_boot_list_2_evspy_info_2_EVT_MISC_INIT_F_3_sandbox_misc_init_f

+ 1 - 0
test/run

@@ -76,6 +76,7 @@ TOOLS_DIR=build-sandbox_spl/tools
 
 run_test "binman" ./tools/binman/binman --toolpath ${TOOLS_DIR} test
 run_test "patman" ./tools/patman/patman test
+run_test "u_boot_pylib" ./tools/u_boot_pylib/u_boot_pylib
 
 run_test "buildman" ./tools/buildman/buildman -t ${skip}
 run_test "fdt" ./tools/dtoc/test_fdt -t

+ 4 - 4
tools/binman/bintool.py

@@ -18,10 +18,10 @@ import shutil
 import tempfile
 import urllib.error
 
-from patman import command
-from patman import terminal
-from patman import tools
-from patman import tout
+from u_boot_pylib import command
+from u_boot_pylib import terminal
+from u_boot_pylib import tools
+from u_boot_pylib import tout
 
 BINMAN_DIR = os.path.dirname(os.path.realpath(__file__))
 

+ 4 - 4
tools/binman/bintool_test.py

@@ -16,10 +16,10 @@ import urllib.error
 from binman import bintool
 from binman.bintool import Bintool
 
-from patman import command
-from patman import terminal
-from patman import test_util
-from patman import tools
+from u_boot_pylib import command
+from u_boot_pylib import terminal
+from u_boot_pylib import test_util
+from u_boot_pylib import tools
 
 # pylint: disable=R0904
 class TestBintool(unittest.TestCase):

+ 1 - 1
tools/binman/btool/lz4.py

@@ -60,7 +60,7 @@ import re
 import tempfile
 
 from binman import bintool
-from patman import tools
+from u_boot_pylib import tools
 
 # pylint: disable=C0103
 class Bintoollz4(bintool.Bintool):

+ 1 - 1
tools/binman/btool/lzma_alone.py

@@ -37,7 +37,7 @@ import re
 import tempfile
 
 from binman import bintool
-from patman import tools
+from u_boot_pylib import tools
 
 # pylint: disable=C0103
 class Bintoollzma_alone(bintool.Bintool):

+ 2 - 2
tools/binman/cbfs_util.py

@@ -22,8 +22,8 @@ import sys
 
 from binman import bintool
 from binman import elf
-from patman import command
-from patman import tools
+from u_boot_pylib import command
+from u_boot_pylib import tools
 
 # Set to True to enable printing output while working
 DEBUG = False

+ 2 - 2
tools/binman/cbfs_util_test.py

@@ -20,8 +20,8 @@ from binman import bintool
 from binman import cbfs_util
 from binman.cbfs_util import CbfsWriter
 from binman import elf
-from patman import test_util
-from patman import tools
+from u_boot_pylib import test_util
+from u_boot_pylib import tools
 
 U_BOOT_DATA           = b'1234'
 U_BOOT_DTB_DATA       = b'udtb'

+ 3 - 3
tools/binman/control.py

@@ -12,14 +12,14 @@ import pkg_resources
 import re
 
 import sys
-from patman import tools
 
 from binman import bintool
 from binman import cbfs_util
-from patman import command
 from binman import elf
 from binman import entry
-from patman import tout
+from u_boot_pylib import command
+from u_boot_pylib import tools
+from u_boot_pylib import tout
 
 # These are imported if needed since they import libfdt
 state = None

+ 3 - 3
tools/binman/elf.py

@@ -13,9 +13,9 @@ import shutil
 import struct
 import tempfile
 
-from patman import command
-from patman import tools
-from patman import tout
+from u_boot_pylib import command
+from u_boot_pylib import tools
+from u_boot_pylib import tout
 
 ELF_TOOLS = True
 try:

+ 4 - 4
tools/binman/elf_test.py

@@ -12,10 +12,10 @@ import tempfile
 import unittest
 
 from binman import elf
-from patman import command
-from patman import test_util
-from patman import tools
-from patman import tout
+from u_boot_pylib import command
+from u_boot_pylib import test_util
+from u_boot_pylib import tools
+from u_boot_pylib import tout
 
 binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
 

+ 3 - 3
tools/binman/entry.py

@@ -14,9 +14,9 @@ import time
 from binman import bintool
 from binman import elf
 from dtoc import fdt_util
-from patman import tools
-from patman.tools import to_hex, to_hex_size
-from patman import tout
+from u_boot_pylib import tools
+from u_boot_pylib.tools import to_hex, to_hex_size
+from u_boot_pylib import tout
 
 modules = {}
 

+ 1 - 1
tools/binman/entry_test.py

@@ -14,7 +14,7 @@ from binman import entry
 from binman.etype.blob import Entry_blob
 from dtoc import fdt
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 class TestEntry(unittest.TestCase):
     def setUp(self):

+ 1 - 1
tools/binman/etype/_testing.py

@@ -9,7 +9,7 @@ from collections import OrderedDict
 
 from binman.entry import Entry, EntryArg
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 
 class Entry__testing(Entry):

+ 1 - 1
tools/binman/etype/atf_fip.py

@@ -11,7 +11,7 @@ from binman.entry import Entry
 from binman.etype.section import Entry_section
 from binman.fip_util import FIP_TYPES, FipReader, FipWriter, UUID_LEN
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 class Entry_atf_fip(Entry_section):
     """ARM Trusted Firmware's Firmware Image Package (FIP)

+ 2 - 2
tools/binman/etype/blob.py

@@ -8,8 +8,8 @@
 from binman.entry import Entry
 from binman import state
 from dtoc import fdt_util
-from patman import tools
-from patman import tout
+from u_boot_pylib import tools
+from u_boot_pylib import tout
 
 class Entry_blob(Entry):
     """Arbitrary binary blob

+ 2 - 2
tools/binman/etype/blob_ext.py

@@ -9,8 +9,8 @@ import os
 
 from binman.etype.blob import Entry_blob
 from dtoc import fdt_util
-from patman import tools
-from patman import tout
+from u_boot_pylib import tools
+from u_boot_pylib import tout
 
 class Entry_blob_ext(Entry_blob):
     """Externally built binary blob

+ 2 - 2
tools/binman/etype/blob_ext_list.py

@@ -9,8 +9,8 @@ import os
 
 from binman.etype.blob import Entry_blob
 from dtoc import fdt_util
-from patman import tools
-from patman import tout
+from u_boot_pylib import tools
+from u_boot_pylib import tout
 
 class Entry_blob_ext_list(Entry_blob):
     """List of externally built binary blobs

+ 2 - 2
tools/binman/etype/fdtmap.py

@@ -9,8 +9,8 @@ image.
 """
 
 from binman.entry import Entry
-from patman import tools
-from patman import tout
+from u_boot_pylib import tools
+from u_boot_pylib import tout
 
 FDTMAP_MAGIC   = b'_FDTMAP_'
 FDTMAP_HDR_LEN = 16

+ 1 - 1
tools/binman/etype/files.py

@@ -11,7 +11,7 @@ import os
 
 from binman.etype.section import Entry_section
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 # This is imported if needed
 state = None

+ 1 - 1
tools/binman/etype/fill.py

@@ -5,7 +5,7 @@
 
 from binman.entry import Entry
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 class Entry_fill(Entry):
     """An entry which is filled to a particular byte value

+ 1 - 1
tools/binman/etype/fit.py

@@ -12,7 +12,7 @@ from binman.etype.section import Entry_section
 from binman import elf
 from dtoc import fdt_util
 from dtoc.fdt import Fdt
-from patman import tools
+from u_boot_pylib import tools
 
 # Supported operations, with the fit,operation property
 OP_GEN_FDT_NODES, OP_SPLIT_ELF = range(2)

+ 3 - 3
tools/binman/etype/fmap.py

@@ -7,9 +7,9 @@
 
 from binman.entry import Entry
 from binman import fmap_util
-from patman import tools
-from patman.tools import to_hex_size
-from patman import tout
+from u_boot_pylib import tools
+from u_boot_pylib.tools import to_hex_size
+from u_boot_pylib import tout
 
 
 class Entry_fmap(Entry):

+ 2 - 2
tools/binman/etype/gbb.py

@@ -8,11 +8,11 @@
 
 from collections import OrderedDict
 
-from patman import command
+from u_boot_pylib import command
 from binman.entry import Entry, EntryArg
 
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 # Build GBB flags.
 # (src/platform/vboot_reference/firmware/include/gbb_header.h)

+ 1 - 1
tools/binman/etype/intel_ifwi.py

@@ -10,7 +10,7 @@ from collections import OrderedDict
 from binman.entry import Entry
 from binman.etype.blob_ext import Entry_blob_ext
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 class Entry_intel_ifwi(Entry_blob_ext):
     """Intel Integrated Firmware Image (IFWI) file

+ 1 - 1
tools/binman/etype/mkimage.py

@@ -9,7 +9,7 @@ from collections import OrderedDict
 
 from binman.entry import Entry
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 class Entry_mkimage(Entry):
     """Binary produced by mkimage

+ 1 - 1
tools/binman/etype/null.py

@@ -5,7 +5,7 @@
 
 from binman.entry import Entry
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 class Entry_null(Entry):
     """An entry which has no contents of its own

+ 1 - 1
tools/binman/etype/pre_load.py

@@ -8,7 +8,7 @@
 import os
 import struct
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 from binman.entry import Entry
 from binman.etype.collection import Entry_collection

+ 3 - 3
tools/binman/etype/section.py

@@ -16,9 +16,9 @@ import sys
 from binman.entry import Entry
 from binman import state
 from dtoc import fdt_util
-from patman import tools
-from patman import tout
-from patman.tools import to_hex_size
+from u_boot_pylib import tools
+from u_boot_pylib import tout
+from u_boot_pylib.tools import to_hex_size
 
 
 class Entry_section(Entry):

+ 1 - 1
tools/binman/etype/text.py

@@ -7,7 +7,7 @@ from collections import OrderedDict
 
 from binman.entry import Entry, EntryArg
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 
 class Entry_text(Entry):

+ 1 - 1
tools/binman/etype/u_boot_dtb_with_ucode.py

@@ -7,7 +7,7 @@
 
 from binman.entry import Entry
 from binman.etype.blob_dtb import Entry_blob_dtb
-from patman import tools
+from u_boot_pylib import tools
 
 # This is imported if needed
 state = None

+ 1 - 1
tools/binman/etype/u_boot_elf.py

@@ -9,7 +9,7 @@ from binman.entry import Entry
 from binman.etype.blob import Entry_blob
 
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 class Entry_u_boot_elf(Entry_blob):
     """U-Boot ELF image

+ 1 - 1
tools/binman/etype/u_boot_env.py

@@ -8,7 +8,7 @@ import zlib
 
 from binman.etype.blob import Entry_blob
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 class Entry_u_boot_env(Entry_blob):
     """An entry which contains a U-Boot environment

+ 1 - 1
tools/binman/etype/u_boot_spl_bss_pad.py

@@ -10,7 +10,7 @@
 from binman import elf
 from binman.entry import Entry
 from binman.etype.blob import Entry_blob
-from patman import tools
+from u_boot_pylib import tools
 
 class Entry_u_boot_spl_bss_pad(Entry_blob):
     """U-Boot SPL binary padded with a BSS region

+ 1 - 1
tools/binman/etype/u_boot_spl_expanded.py

@@ -5,7 +5,7 @@
 # Entry-type module for expanded U-Boot SPL binary
 #
 
-from patman import tout
+from u_boot_pylib import tout
 
 from binman import state
 from binman.etype.blob_phase import Entry_blob_phase

+ 1 - 1
tools/binman/etype/u_boot_tpl_bss_pad.py

@@ -10,7 +10,7 @@
 from binman import elf
 from binman.entry import Entry
 from binman.etype.blob import Entry_blob
-from patman import tools
+from u_boot_pylib import tools
 
 class Entry_u_boot_tpl_bss_pad(Entry_blob):
     """U-Boot TPL binary padded with a BSS region

+ 1 - 1
tools/binman/etype/u_boot_tpl_expanded.py

@@ -5,7 +5,7 @@
 # Entry-type module for expanded U-Boot TPL binary
 #
 
-from patman import tout
+from u_boot_pylib import tout
 
 from binman import state
 from binman.etype.blob_phase import Entry_blob_phase

+ 2 - 2
tools/binman/etype/u_boot_tpl_with_ucode_ptr.py

@@ -7,11 +7,11 @@
 
 import struct
 
-from patman import command
 from binman.entry import Entry
 from binman.etype.blob import Entry_blob
 from binman.etype.u_boot_with_ucode_ptr import Entry_u_boot_with_ucode_ptr
-from patman import tools
+from u_boot_pylib import command
+from u_boot_pylib import tools
 
 class Entry_u_boot_tpl_with_ucode_ptr(Entry_u_boot_with_ucode_ptr):
     """U-Boot TPL with embedded microcode pointer

+ 1 - 1
tools/binman/etype/u_boot_ucode.py

@@ -7,7 +7,7 @@
 
 from binman.entry import Entry
 from binman.etype.blob import Entry_blob
-from patman import tools
+from u_boot_pylib import tools
 
 class Entry_u_boot_ucode(Entry_blob):
     """U-Boot microcode block

+ 1 - 1
tools/binman/etype/u_boot_vpl_bss_pad.py

@@ -10,7 +10,7 @@
 from binman import elf
 from binman.entry import Entry
 from binman.etype.blob import Entry_blob
-from patman import tools
+from u_boot_pylib import tools
 
 class Entry_u_boot_vpl_bss_pad(Entry_blob):
     """U-Boot VPL binary padded with a BSS region

+ 1 - 1
tools/binman/etype/u_boot_vpl_expanded.py

@@ -5,7 +5,7 @@
 # Entry-type module for expanded U-Boot VPL binary
 #
 
-from patman import tout
+from u_boot_pylib import tout
 
 from binman import state
 from binman.etype.blob_phase import Entry_blob_phase

+ 2 - 2
tools/binman/etype/u_boot_with_ucode_ptr.py

@@ -11,8 +11,8 @@ from binman import elf
 from binman.entry import Entry
 from binman.etype.blob import Entry_blob
 from dtoc import fdt_util
-from patman import tools
-from patman import command
+from u_boot_pylib import tools
+from u_boot_pylib import command
 
 class Entry_u_boot_with_ucode_ptr(Entry_blob):
     """U-Boot with embedded microcode pointer

+ 1 - 1
tools/binman/etype/vblock.py

@@ -13,7 +13,7 @@ from binman.entry import EntryArg
 from binman.etype.collection import Entry_collection
 
 from dtoc import fdt_util
-from patman import tools
+from u_boot_pylib import tools
 
 class Entry_vblock(Entry_collection):
     """An entry which contains a Chromium OS verified boot block

+ 1 - 1
tools/binman/fdt_test.py

@@ -12,7 +12,7 @@ import unittest
 from dtoc import fdt
 from dtoc import fdt_util
 from dtoc.fdt import FdtScan
-from patman import tools
+from u_boot_pylib import tools
 
 class TestFdt(unittest.TestCase):
     @classmethod

+ 2 - 2
tools/binman/fip_util.py

@@ -37,8 +37,8 @@ OUR_PATH = os.path.dirname(OUR_FILE)
 sys.path.insert(2, os.path.join(OUR_PATH, '..'))
 
 # pylint: disable=C0413
-from patman import command
-from patman import tools
+from u_boot_pylib import command
+from u_boot_pylib import tools
 
 # The TOC header, at the start of the FIP
 HEADER_FORMAT = '<IIQ'

+ 2 - 2
tools/binman/fip_util_test.py

@@ -20,10 +20,10 @@ OUR_PATH = os.path.dirname(os.path.realpath(__file__))
 sys.path.insert(2, os.path.join(OUR_PATH, '..'))
 
 # pylint: disable=C0413
-from patman import test_util
-from patman import tools
 from binman import bintool
 from binman import fip_util
+from u_boot_pylib import test_util
+from u_boot_pylib import tools
 
 FIPTOOL = bintool.Bintool.create('fiptool')
 HAVE_FIPTOOL = FIPTOOL.is_present()

+ 1 - 1
tools/binman/fmap_util.py

@@ -10,7 +10,7 @@ import collections
 import struct
 import sys
 
-from patman import tools
+from u_boot_pylib import tools
 
 # constants imported from lib/fmap.h
 FMAP_SIGNATURE = b'__FMAP__'

+ 4 - 4
tools/binman/ftest.py

@@ -34,10 +34,10 @@ from dtoc import fdt_util
 from binman.etype import fdtmap
 from binman.etype import image_header
 from binman.image import Image
-from patman import command
-from patman import test_util
-from patman import tools
-from patman import tout
+from u_boot_pylib import command
+from u_boot_pylib import test_util
+from u_boot_pylib import tools
+from u_boot_pylib import tout
 
 # Contents of test files, corresponding to different entry types
 U_BOOT_DATA           = b'1234'

+ 2 - 2
tools/binman/image.py

@@ -18,8 +18,8 @@ from binman.etype import image_header
 from binman.etype import section
 from dtoc import fdt
 from dtoc import fdt_util
-from patman import tools
-from patman import tout
+from u_boot_pylib import tools
+from u_boot_pylib import tout
 
 class Image(section.Entry_section):
     """A Image, representing an output from binman

+ 1 - 1
tools/binman/image_test.py

@@ -7,7 +7,7 @@
 import unittest
 
 from binman.image import Image
-from patman.test_util import capture_sys_output
+from u_boot_pylib.test_util import capture_sys_output
 
 class TestImage(unittest.TestCase):
     def testInvalidFormat(self):

+ 4 - 3
tools/binman/main.py

@@ -34,7 +34,7 @@ sys.pycache_prefix = os.path.relpath(our_path, srctree)
 sys.path.insert(2, our1_path)
 
 from binman import bintool
-from patman import test_util
+from u_boot_pylib import test_util
 
 # Bring in the libfdt module
 sys.path.insert(2, 'scripts/dtc/pylibfdt')
@@ -44,7 +44,7 @@ sys.path.insert(2, os.path.join(srctree, 'build-sandbox_spl/scripts/dtc/pylibfdt
 
 from binman import cmdline
 from binman import control
-from patman import test_util
+from u_boot_pylib import test_util
 
 def RunTests(debug, verbosity, processes, test_preserve_dirs, args, toolpath):
     """Run the functional tests and any embedded doctests
@@ -95,7 +95,8 @@ def RunTestCoverage(toolpath):
         for path in toolpath:
             extra_args += ' --toolpath %s' % path
     test_util.run_test_coverage('tools/binman/binman', None,
-            ['*test*', '*main.py', 'tools/patman/*', 'tools/dtoc/*'],
+            ['*test*', '*main.py', 'tools/patman/*', 'tools/dtoc/*',
+             'tools/u_boot_pylib/*'],
             args.build_dir, all_set, extra_args or None)
 
 def RunBinman(args):

+ 2 - 2
tools/binman/state.py

@@ -13,8 +13,8 @@ import threading
 
 from dtoc import fdt
 import os
-from patman import tools
-from patman import tout
+from u_boot_pylib import tools
+from u_boot_pylib import tout
 
 OUR_PATH = os.path.dirname(os.path.realpath(__file__))
 

+ 3 - 3
tools/buildman/builder.py

@@ -19,10 +19,10 @@ import time
 
 from buildman import builderthread
 from buildman import toolchain
-from patman import command
 from patman import gitutil
-from patman import terminal
-from patman.terminal import tprint
+from u_boot_pylib import command
+from u_boot_pylib import terminal
+from u_boot_pylib.terminal import tprint
 
 # This indicates an new int or hex Kconfig property with no default
 # It hangs the build since the 'conf' tool cannot proceed without valid input.

+ 1 - 1
tools/buildman/builderthread.py

@@ -10,8 +10,8 @@ import sys
 import threading
 
 from buildman import cfgutil
-from patman import command
 from patman import gitutil
+from u_boot_pylib import command
 
 RETURN_CODE_RETRY = -1
 BASE_ELF_FILENAMES = ['u-boot', 'spl/u-boot-spl', 'tpl/u-boot-tpl']

+ 1 - 1
tools/buildman/cfgutil.py

@@ -7,7 +7,7 @@
 
 import re
 
-from patman import tools
+from u_boot_pylib import tools
 
 RE_LINE = re.compile(r'(# )?CONFIG_([A-Z0-9_]+)(=(.*)| is not set)')
 RE_CFG = re.compile(r'(~?)(CONFIG_)?([A-Z0-9_]+)(=.*)?')

+ 4 - 4
tools/buildman/control.py

@@ -13,12 +13,12 @@ from buildman import bsettings
 from buildman import cfgutil
 from buildman import toolchain
 from buildman.builder import Builder
-from patman import command
 from patman import gitutil
 from patman import patchstream
-from patman import terminal
-from patman import tools
-from patman.terminal import tprint
+from u_boot_pylib import command
+from u_boot_pylib import terminal
+from u_boot_pylib import tools
+from u_boot_pylib.terminal import tprint
 
 def GetPlural(count):
     """Returns a plural 's' if count is not 1"""

+ 4 - 4
tools/buildman/func_test.py

@@ -14,11 +14,11 @@ from buildman import bsettings
 from buildman import cmdline
 from buildman import control
 from buildman import toolchain
-from patman import command
 from patman import gitutil
-from patman import terminal
-from patman import test_util
-from patman import tools
+from u_boot_pylib import command
+from u_boot_pylib import terminal
+from u_boot_pylib import test_util
+from u_boot_pylib import tools
 
 settings_data = '''
 # Buildman settings file

+ 2 - 2
tools/buildman/main.py

@@ -25,8 +25,8 @@ from buildman import control
 from buildman import toolchain
 from patman import patchstream
 from patman import gitutil
-from patman import terminal
-from patman import test_util
+from u_boot_pylib import terminal
+from u_boot_pylib import test_util
 
 def RunTests(skip_net_tests, verboose, args):
     from buildman import func_test

+ 4 - 4
tools/buildman/test.py

@@ -17,10 +17,10 @@ from buildman import cfgutil
 from buildman import control
 from buildman import toolchain
 from patman import commit
-from patman import command
-from patman import terminal
-from patman import test_util
-from patman import tools
+from u_boot_pylib import command
+from u_boot_pylib import terminal
+from u_boot_pylib import test_util
+from u_boot_pylib import tools
 
 use_network = True
 

+ 3 - 3
tools/buildman/toolchain.py

@@ -11,9 +11,9 @@ import tempfile
 import urllib.request, urllib.error, urllib.parse
 
 from buildman import bsettings
-from patman import command
-from patman import terminal
-from patman import tools
+from u_boot_pylib import command
+from u_boot_pylib import terminal
+from u_boot_pylib import tools
 
 (PRIORITY_FULL_PREFIX, PRIORITY_PREFIX_GCC, PRIORITY_PREFIX_GCC_PATH,
     PRIORITY_CALC) = list(range(4))

+ 1 - 1
tools/dtoc/fdt.py

@@ -12,7 +12,7 @@ import sys
 from dtoc import fdt_util
 import libfdt
 from libfdt import QUIET_NOTFOUND
-from patman import tools
+from u_boot_pylib import tools
 
 # This deals with a device tree, presenting it as an assortment of Node and
 # Prop objects, representing nodes and properties, respectively. This file

+ 2 - 2
tools/dtoc/fdt_util.py

@@ -13,8 +13,8 @@ import struct
 import sys
 import tempfile
 
-from patman import command
-from patman import tools
+from u_boot_pylib import command
+from u_boot_pylib import tools
 
 def fdt32_to_cpu(val):
     """Convert a device tree cell to an integer

+ 3 - 2
tools/dtoc/main.py

@@ -35,7 +35,7 @@ sys.path.insert(0, os.path.join(our_path,
                 '../../build-sandbox_spl/scripts/dtc/pylibfdt'))
 
 from dtoc import dtb_platdata
-from patman import test_util
+from u_boot_pylib import test_util
 
 def run_tests(processes, args):
     """Run all the test we have for dtoc
@@ -65,7 +65,8 @@ def RunTestCoverage():
     """Run the tests and check that we get 100% coverage"""
     sys.argv = [sys.argv[0]]
     test_util.run_test_coverage('tools/dtoc/dtoc', '/main.py',
-            ['tools/patman/*.py', '*/fdt*', '*test*'], args.build_dir)
+            ['tools/patman/*.py', 'tools/u_boot_pylib/*','*/fdt*', '*test*'],
+            args.build_dir)
 
 
 if __name__ != '__main__':

+ 2 - 2
tools/dtoc/test_dtoc.py

@@ -25,8 +25,8 @@ from dtoc.dtb_platdata import get_value
 from dtoc.dtb_platdata import tab_to
 from dtoc.src_scan import conv_name_to_c
 from dtoc.src_scan import get_compat_name
-from patman import test_util
-from patman import tools
+from u_boot_pylib import test_util
+from u_boot_pylib import tools
 
 OUR_PATH = os.path.dirname(os.path.realpath(__file__))
 

+ 4 - 3
tools/dtoc/test_fdt.py

@@ -30,8 +30,8 @@ from dtoc import fdt_util
 from dtoc.fdt_util import fdt32_to_cpu, fdt64_to_cpu
 from dtoc.fdt import Type, BytesToValue
 import libfdt
-from patman import test_util
-from patman import tools
+from u_boot_pylib import test_util
+from u_boot_pylib import tools
 
 #pylint: disable=protected-access
 
@@ -814,7 +814,8 @@ def run_test_coverage(build_dir):
         build_dir (str): Directory containing the build output
     """
     test_util.run_test_coverage('tools/dtoc/test_fdt.py', None,
-            ['tools/patman/*.py', '*test_fdt.py'], build_dir)
+            ['tools/patman/*.py', 'tools/u_boot_pylib/*', '*test_fdt.py'],
+            build_dir)
 
 
 def run_tests(names, processes):

+ 2 - 2
tools/dtoc/test_src_scan.py

@@ -15,8 +15,8 @@ import unittest
 from unittest import mock
 
 from dtoc import src_scan
-from patman import test_util
-from patman import tools
+from u_boot_pylib import test_util
+from u_boot_pylib import tools
 
 OUR_PATH = os.path.dirname(os.path.realpath(__file__))
 

+ 3 - 4
tools/patman/__init__.py

@@ -1,6 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0+
 
-__all__ = ['checkpatch', 'command', 'commit', 'control', 'cros_subprocess',
-           'func_test', 'get_maintainer', 'gitutil', '__main__', 'patchstream',
-           'project', 'series', 'setup', 'settings', 'terminal',
-           'test_checkpatch', 'test_util', 'tools', 'tout']
+__all__ = ['checkpatch', 'commit', 'control', 'func_test', 'get_maintainer',
+           'gitutil', '__main__', 'patchstream', 'project', 'series',
+           'settings','setup', 'status', 'test_checkpatch', 'test_settings']

+ 4 - 4
tools/patman/__main__.py

@@ -24,10 +24,10 @@ from patman import func_test
 from patman import gitutil
 from patman import project
 from patman import settings
-from patman import terminal
-from patman import test_util
 from patman import test_checkpatch
-from patman import tools
+from u_boot_pylib import terminal
+from u_boot_pylib import test_util
+from u_boot_pylib import tools
 
 epilog = '''Create patches from commits in a branch, check them and email them
 as specified by tags you place in the commits. Use -n to do a dry run first.'''
@@ -150,7 +150,7 @@ if args.cmd == 'test':
     result = test_util.run_test_suites(
         'patman', False, False, False, None, None, None,
         [test_checkpatch.TestPatch, func_test.TestFunctional,
-         'gitutil', 'settings', 'terminal'])
+         'gitutil', 'settings'])
 
     sys.exit(0 if result.wasSuccessful() else 1)
 

+ 2 - 2
tools/patman/checkpatch.py

@@ -7,9 +7,9 @@ import os
 import re
 import sys
 
-from patman import command
 from patman import gitutil
-from patman import terminal
+from u_boot_pylib import command
+from u_boot_pylib import terminal
 
 EMACS_PREFIX = r'(?:[0-9]{4}.*\.patch:[0-9]+: )?'
 TYPE_NAME = r'([A-Z_]+:)?'

+ 1 - 1
tools/patman/control.py

@@ -14,7 +14,7 @@ import sys
 from patman import checkpatch
 from patman import gitutil
 from patman import patchstream
-from patman import terminal
+from u_boot_pylib import terminal
 
 def setup():
     """Do required setup before doing anything"""

+ 3 - 3
tools/patman/func_test.py

@@ -23,9 +23,9 @@ from patman import patchstream
 from patman.patchstream import PatchStream
 from patman.series import Series
 from patman import settings
-from patman import terminal
-from patman import tools
-from patman.test_util import capture_sys_output
+from u_boot_pylib import terminal
+from u_boot_pylib import tools
+from u_boot_pylib.test_util import capture_sys_output
 
 import pygit2
 from patman import status

+ 1 - 1
tools/patman/get_maintainer.py

@@ -7,8 +7,8 @@ import os
 import shlex
 import shutil
 
-from patman import command
 from patman import gitutil
+from u_boot_pylib import command
 
 
 def find_get_maintainer(script_file_name):

+ 2 - 2
tools/patman/gitutil.py

@@ -5,9 +5,9 @@
 import os
 import sys
 
-from patman import command
 from patman import settings
-from patman import terminal
+from u_boot_pylib import command
+from u_boot_pylib import terminal
 
 # True to use --no-decorate - we check this in setup()
 use_no_decorate = True

+ 1 - 1
tools/patman/patchstream.py

@@ -14,10 +14,10 @@ import queue
 import shutil
 import tempfile
 
-from patman import command
 from patman import commit
 from patman import gitutil
 from patman.series import Series
+from u_boot_pylib import command
 
 # Tags that we detect and remove
 RE_REMOVE = re.compile(r'^BUG=|^TEST=|^BRANCH=|^Review URL:'

+ 2 - 2
tools/patman/series.py

@@ -11,8 +11,8 @@ import os
 from patman import get_maintainer
 from patman import gitutil
 from patman import settings
-from patman import terminal
-from patman import tools
+from u_boot_pylib import terminal
+from u_boot_pylib import tools
 
 # Series-xxx tags that we understand
 valid_series = ['to', 'cc', 'version', 'changes', 'prefix', 'notes', 'name',

+ 2 - 2
tools/patman/status.py

@@ -18,8 +18,8 @@ import requests
 
 from patman import patchstream
 from patman.patchstream import PatchStream
-from patman import terminal
-from patman import tout
+from u_boot_pylib import terminal
+from u_boot_pylib import tout
 
 # Patches which are part of a multi-patch series are shown with a prefix like
 # [prefix, version, sequence], for example '[RFC, v2, 3/5]'. All but the last

+ 1 - 1
tools/patman/test_settings.py

@@ -10,7 +10,7 @@ import sys
 import tempfile
 
 from patman import settings
-from patman import tools
+from u_boot_pylib import tools
 
 
 @contextlib.contextmanager

+ 1 - 1
tools/rmboard.py

@@ -28,7 +28,7 @@ import os
 import re
 import sys
 
-from patman import command
+from u_boot_pylib import command
 
 def rm_kconfig_include(path):
     """Remove a path from Kconfig files

+ 4 - 0
tools/u_boot_pylib/__init__.py

@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+__all__ = ['command', 'cros_subprocess','terminal', 'test_util', 'tools',
+	   'tout']

+ 23 - 0
tools/u_boot_pylib/__main__.py

@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright 2023 Google LLC
+#
+
+import os
+import sys
+
+if __name__ == "__main__":
+    # Allow 'from u_boot_pylib import xxx to work'
+    our_path = os.path.dirname(os.path.realpath(__file__))
+    sys.path.append(os.path.join(our_path, '..'))
+
+    # Run tests
+    from u_boot_pylib import terminal
+    from u_boot_pylib import test_util
+
+    result = test_util.run_test_suites(
+        'u_boot_pylib', False, False, False, None, None, None,
+        ['terminal'])
+
+    sys.exit(0 if result.wasSuccessful() else 1)

+ 1 - 1
tools/patman/command.py → tools/u_boot_pylib/command.py

@@ -4,7 +4,7 @@
 
 import os
 
-from patman import cros_subprocess
+from u_boot_pylib import cros_subprocess
 
 """Shell command ease-ups for Python."""
 

+ 0 - 0
tools/patman/cros_subprocess.py → tools/u_boot_pylib/cros_subprocess.py


+ 0 - 0
tools/patman/terminal.py → tools/u_boot_pylib/terminal.py


+ 1 - 1
tools/patman/test_util.py → tools/u_boot_pylib/test_util.py

@@ -11,7 +11,7 @@ import os
 import sys
 import unittest
 
-from patman import command
+from u_boot_pylib import command
 
 from io import StringIO
 

+ 2 - 2
tools/patman/tools.py → tools/u_boot_pylib/tools.py

@@ -11,8 +11,8 @@ import sys
 import tempfile
 import urllib.request
 
-from patman import command
-from patman import tout
+from u_boot_pylib import command
+from u_boot_pylib import tout
 
 # Output directly (generally this is temporary)
 outdir = None

+ 1 - 1
tools/patman/tout.py → tools/u_boot_pylib/tout.py

@@ -6,7 +6,7 @@
 
 import sys
 
-from patman import terminal
+from u_boot_pylib import terminal
 
 # Output verbosity levels that we support
 ERROR, WARNING, NOTICE, INFO, DETAIL, DEBUG = range(6)

+ 1 - 0
tools/u_boot_pylib/u_boot_pylib

@@ -0,0 +1 @@
+__main__.py