[PATCH v2 04/24] patman: Move library functions into a library directory

Simon Glass sjg at chromium.org
Fri Feb 24 02:18:04 CET 2023


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 at chromium.org>
---

(no changes since v1)

 scripts/event_dump.py                         |  2 +-
 test/run                                      |  1 +
 tools/binman/bintool.py                       |  8 +++----
 tools/binman/bintool_test.py                  |  8 +++----
 tools/binman/btool/lz4.py                     |  2 +-
 tools/binman/btool/lzma_alone.py              |  2 +-
 tools/binman/cbfs_util.py                     |  4 ++--
 tools/binman/cbfs_util_test.py                |  4 ++--
 tools/binman/control.py                       |  6 ++---
 tools/binman/elf.py                           |  6 ++---
 tools/binman/elf_test.py                      |  8 +++----
 tools/binman/entry.py                         |  6 ++---
 tools/binman/entry_test.py                    |  2 +-
 tools/binman/etype/_testing.py                |  2 +-
 tools/binman/etype/atf_fip.py                 |  2 +-
 tools/binman/etype/blob.py                    |  4 ++--
 tools/binman/etype/blob_ext.py                |  4 ++--
 tools/binman/etype/blob_ext_list.py           |  4 ++--
 tools/binman/etype/fdtmap.py                  |  4 ++--
 tools/binman/etype/files.py                   |  2 +-
 tools/binman/etype/fill.py                    |  2 +-
 tools/binman/etype/fit.py                     |  2 +-
 tools/binman/etype/fmap.py                    |  6 ++---
 tools/binman/etype/gbb.py                     |  4 ++--
 tools/binman/etype/intel_ifwi.py              |  2 +-
 tools/binman/etype/mkimage.py                 |  2 +-
 tools/binman/etype/null.py                    |  2 +-
 tools/binman/etype/pre_load.py                |  2 +-
 tools/binman/etype/section.py                 |  6 ++---
 tools/binman/etype/text.py                    |  2 +-
 tools/binman/etype/u_boot_dtb_with_ucode.py   |  2 +-
 tools/binman/etype/u_boot_elf.py              |  2 +-
 tools/binman/etype/u_boot_env.py              |  2 +-
 tools/binman/etype/u_boot_spl_bss_pad.py      |  2 +-
 tools/binman/etype/u_boot_spl_expanded.py     |  2 +-
 tools/binman/etype/u_boot_tpl_bss_pad.py      |  2 +-
 tools/binman/etype/u_boot_tpl_expanded.py     |  2 +-
 .../binman/etype/u_boot_tpl_with_ucode_ptr.py |  4 ++--
 tools/binman/etype/u_boot_ucode.py            |  2 +-
 tools/binman/etype/u_boot_vpl_bss_pad.py      |  2 +-
 tools/binman/etype/u_boot_vpl_expanded.py     |  2 +-
 tools/binman/etype/u_boot_with_ucode_ptr.py   |  4 ++--
 tools/binman/etype/vblock.py                  |  2 +-
 tools/binman/fdt_test.py                      |  2 +-
 tools/binman/fip_util.py                      |  4 ++--
 tools/binman/fip_util_test.py                 |  4 ++--
 tools/binman/fmap_util.py                     |  2 +-
 tools/binman/ftest.py                         |  8 +++----
 tools/binman/image.py                         |  4 ++--
 tools/binman/image_test.py                    |  2 +-
 tools/binman/main.py                          |  7 +++---
 tools/binman/state.py                         |  4 ++--
 tools/buildman/builder.py                     |  6 ++---
 tools/buildman/builderthread.py               |  2 +-
 tools/buildman/cfgutil.py                     |  2 +-
 tools/buildman/control.py                     |  8 +++----
 tools/buildman/func_test.py                   |  8 +++----
 tools/buildman/main.py                        |  4 ++--
 tools/buildman/test.py                        |  8 +++----
 tools/buildman/toolchain.py                   |  6 ++---
 tools/dtoc/fdt.py                             |  2 +-
 tools/dtoc/fdt_util.py                        |  4 ++--
 tools/dtoc/main.py                            |  5 ++--
 tools/dtoc/test_dtoc.py                       |  4 ++--
 tools/dtoc/test_fdt.py                        |  7 +++---
 tools/dtoc/test_src_scan.py                   |  4 ++--
 tools/patman/__init__.py                      |  7 +++---
 tools/patman/__main__.py                      |  8 +++----
 tools/patman/checkpatch.py                    |  4 ++--
 tools/patman/control.py                       |  2 +-
 tools/patman/func_test.py                     |  6 ++---
 tools/patman/get_maintainer.py                |  2 +-
 tools/patman/gitutil.py                       |  4 ++--
 tools/patman/patchstream.py                   |  2 +-
 tools/patman/series.py                        |  4 ++--
 tools/patman/status.py                        |  4 ++--
 tools/patman/test_settings.py                 |  2 +-
 tools/rmboard.py                              |  2 +-
 tools/u_boot_pylib/__init__.py                |  4 ++++
 tools/u_boot_pylib/__main__.py                | 23 +++++++++++++++++++
 tools/{patman => u_boot_pylib}/command.py     |  2 +-
 .../cros_subprocess.py                        |  0
 tools/{patman => u_boot_pylib}/terminal.py    |  0
 tools/{patman => u_boot_pylib}/test_util.py   |  2 +-
 tools/{patman => u_boot_pylib}/tools.py       |  4 ++--
 tools/{patman => u_boot_pylib}/tout.py        |  2 +-
 tools/u_boot_pylib/u_boot_pylib               |  1 +
 87 files changed, 182 insertions(+), 151 deletions(-)
 create mode 100644 tools/u_boot_pylib/__init__.py
 create mode 100755 tools/u_boot_pylib/__main__.py
 rename tools/{patman => u_boot_pylib}/command.py (99%)
 rename tools/{patman => u_boot_pylib}/cros_subprocess.py (100%)
 rename tools/{patman => u_boot_pylib}/terminal.py (100%)
 rename tools/{patman => u_boot_pylib}/test_util.py (99%)
 rename tools/{patman => u_boot_pylib}/tools.py (99%)
 rename tools/{patman => u_boot_pylib}/tout.py (99%)
 create mode 120000 tools/u_boot_pylib/u_boot_pylib

diff --git a/scripts/event_dump.py b/scripts/event_dump.py
index d87823f3749..0117457526e 100755
--- a/scripts/event_dump.py
+++ b/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
diff --git a/test/run b/test/run
index c4ab046ce8f..93b556f6cff 100755
--- a/test/run
+++ b/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
diff --git a/tools/binman/bintool.py b/tools/binman/bintool.py
index 8fda13ff012..745b62b5a20 100644
--- a/tools/binman/bintool.py
+++ b/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__))
 
diff --git a/tools/binman/bintool_test.py b/tools/binman/bintool_test.py
index 7efb8391db2..87a6b11e676 100644
--- a/tools/binman/bintool_test.py
+++ b/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):
diff --git a/tools/binman/btool/lz4.py b/tools/binman/btool/lz4.py
index dc9e37921a6..fd520d13a56 100644
--- a/tools/binman/btool/lz4.py
+++ b/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):
diff --git a/tools/binman/btool/lzma_alone.py b/tools/binman/btool/lzma_alone.py
index 52a960fd2fa..1fda2f68c7b 100644
--- a/tools/binman/btool/lzma_alone.py
+++ b/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):
diff --git a/tools/binman/cbfs_util.py b/tools/binman/cbfs_util.py
index 7bd3d897981..fc56b40b753 100644
--- a/tools/binman/cbfs_util.py
+++ b/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
diff --git a/tools/binman/cbfs_util_test.py b/tools/binman/cbfs_util_test.py
index e0f792fd344..ee951d10cf3 100755
--- a/tools/binman/cbfs_util_test.py
+++ b/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'
diff --git a/tools/binman/control.py b/tools/binman/control.py
index e64740094f6..3e27b72f881 100644
--- a/tools/binman/control.py
+++ b/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
diff --git a/tools/binman/elf.py b/tools/binman/elf.py
index 3cc8a384495..5816284c32a 100644
--- a/tools/binman/elf.py
+++ b/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:
diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py
index 8cb55ebb815..c98083961b5 100644
--- a/tools/binman/elf_test.py
+++ b/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]))
 
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 5eacc5fa6c4..13224523978 100644
--- a/tools/binman/entry.py
+++ b/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 = {}
 
diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py
index a6fbf62731f..ac6582cf86a 100644
--- a/tools/binman/entry_test.py
+++ b/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):
diff --git a/tools/binman/etype/_testing.py b/tools/binman/etype/_testing.py
index 1c1efb21a44..e092d98ce15 100644
--- a/tools/binman/etype/_testing.py
+++ b/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):
diff --git a/tools/binman/etype/atf_fip.py b/tools/binman/etype/atf_fip.py
index 6ecd95b71f9..d5b862040b4 100644
--- a/tools/binman/etype/atf_fip.py
+++ b/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)
diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index c7ddcedffb8..f9c4e33b110 100644
--- a/tools/binman/etype/blob.py
+++ b/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
diff --git a/tools/binman/etype/blob_ext.py b/tools/binman/etype/blob_ext.py
index fba6271de2b..9eb762b0a23 100644
--- a/tools/binman/etype/blob_ext.py
+++ b/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
diff --git a/tools/binman/etype/blob_ext_list.py b/tools/binman/etype/blob_ext_list.py
index f00202e9ebc..1bfcf6733a7 100644
--- a/tools/binman/etype/blob_ext_list.py
+++ b/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
diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py
index 33c9d039a91..f1f6217940f 100644
--- a/tools/binman/etype/fdtmap.py
+++ b/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
diff --git a/tools/binman/etype/files.py b/tools/binman/etype/files.py
index 2081bc727b9..c8757eafab1 100644
--- a/tools/binman/etype/files.py
+++ b/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
diff --git a/tools/binman/etype/fill.py b/tools/binman/etype/fill.py
index c91d0152a8a..7c93d4e2689 100644
--- a/tools/binman/etype/fill.py
+++ b/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
diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py
index cd2943533ce..9d34aabd19a 100644
--- a/tools/binman/etype/fit.py
+++ b/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)
diff --git a/tools/binman/etype/fmap.py b/tools/binman/etype/fmap.py
index 0c576202a48..dacdafd8f6f 100644
--- a/tools/binman/etype/fmap.py
+++ b/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):
diff --git a/tools/binman/etype/gbb.py b/tools/binman/etype/gbb.py
index ba2a362bb59..cca18af6e2f 100644
--- a/tools/binman/etype/gbb.py
+++ b/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)
diff --git a/tools/binman/etype/intel_ifwi.py b/tools/binman/etype/intel_ifwi.py
index 04fad401eee..6513b97c3e5 100644
--- a/tools/binman/etype/intel_ifwi.py
+++ b/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
diff --git a/tools/binman/etype/mkimage.py b/tools/binman/etype/mkimage.py
index cb264c3cad0..27a0c4bd7c6 100644
--- a/tools/binman/etype/mkimage.py
+++ b/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
diff --git a/tools/binman/etype/null.py b/tools/binman/etype/null.py
index c10d4824472..263fb5244df 100644
--- a/tools/binman/etype/null.py
+++ b/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
diff --git a/tools/binman/etype/pre_load.py b/tools/binman/etype/pre_load.py
index b6222811592..bd3545bffc0 100644
--- a/tools/binman/etype/pre_load.py
+++ b/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
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 57b91ff726c..1f0bbd7f2ce 100644
--- a/tools/binman/etype/section.py
+++ b/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):
diff --git a/tools/binman/etype/text.py b/tools/binman/etype/text.py
index c55e0233b1e..e4deb4abacc 100644
--- a/tools/binman/etype/text.py
+++ b/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):
diff --git a/tools/binman/etype/u_boot_dtb_with_ucode.py b/tools/binman/etype/u_boot_dtb_with_ucode.py
index 047d310cdf4..f7225cecc16 100644
--- a/tools/binman/etype/u_boot_dtb_with_ucode.py
+++ b/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
diff --git a/tools/binman/etype/u_boot_elf.py b/tools/binman/etype/u_boot_elf.py
index 3ec774f38ad..f4d86aa176a 100644
--- a/tools/binman/etype/u_boot_elf.py
+++ b/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
diff --git a/tools/binman/etype/u_boot_env.py b/tools/binman/etype/u_boot_env.py
index c38340b256e..c027e93d42c 100644
--- a/tools/binman/etype/u_boot_env.py
+++ b/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
diff --git a/tools/binman/etype/u_boot_spl_bss_pad.py b/tools/binman/etype/u_boot_spl_bss_pad.py
index 680d1983056..1ffeb3911fd 100644
--- a/tools/binman/etype/u_boot_spl_bss_pad.py
+++ b/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
diff --git a/tools/binman/etype/u_boot_spl_expanded.py b/tools/binman/etype/u_boot_spl_expanded.py
index 319f6708fe6..fcd0dd19ac4 100644
--- a/tools/binman/etype/u_boot_spl_expanded.py
+++ b/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
diff --git a/tools/binman/etype/u_boot_tpl_bss_pad.py b/tools/binman/etype/u_boot_tpl_bss_pad.py
index 47f4b23f357..29c6a954129 100644
--- a/tools/binman/etype/u_boot_tpl_bss_pad.py
+++ b/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
diff --git a/tools/binman/etype/u_boot_tpl_expanded.py b/tools/binman/etype/u_boot_tpl_expanded.py
index 55fde3c8e66..58db4f37556 100644
--- a/tools/binman/etype/u_boot_tpl_expanded.py
+++ b/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
diff --git a/tools/binman/etype/u_boot_tpl_with_ucode_ptr.py b/tools/binman/etype/u_boot_tpl_with_ucode_ptr.py
index c7f3f9dedb5..86f9578b714 100644
--- a/tools/binman/etype/u_boot_tpl_with_ucode_ptr.py
+++ b/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
diff --git a/tools/binman/etype/u_boot_ucode.py b/tools/binman/etype/u_boot_ucode.py
index 6945411cf90..97ed7d7eb14 100644
--- a/tools/binman/etype/u_boot_ucode.py
+++ b/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
diff --git a/tools/binman/etype/u_boot_vpl_bss_pad.py b/tools/binman/etype/u_boot_vpl_bss_pad.py
index b2ce2a31352..bba38ccf9e9 100644
--- a/tools/binman/etype/u_boot_vpl_bss_pad.py
+++ b/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
diff --git a/tools/binman/etype/u_boot_vpl_expanded.py b/tools/binman/etype/u_boot_vpl_expanded.py
index 92c64f0a65e..deff5a3f8c2 100644
--- a/tools/binman/etype/u_boot_vpl_expanded.py
+++ b/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
diff --git a/tools/binman/etype/u_boot_with_ucode_ptr.py b/tools/binman/etype/u_boot_with_ucode_ptr.py
index e275698cebe..41731fd0e13 100644
--- a/tools/binman/etype/u_boot_with_ucode_ptr.py
+++ b/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
diff --git a/tools/binman/etype/vblock.py b/tools/binman/etype/vblock.py
index 04cb7228aa0..4adb9a4e9bf 100644
--- a/tools/binman/etype/vblock.py
+++ b/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
diff --git a/tools/binman/fdt_test.py b/tools/binman/fdt_test.py
index 94347b1a1e2..7ef87295463 100644
--- a/tools/binman/fdt_test.py
+++ b/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
diff --git a/tools/binman/fip_util.py b/tools/binman/fip_util.py
index 95eee32bc00..b5caab2d37a 100755
--- a/tools/binman/fip_util.py
+++ b/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'
diff --git a/tools/binman/fip_util_test.py b/tools/binman/fip_util_test.py
index cf6d0002ec6..56aa56f4643 100755
--- a/tools/binman/fip_util_test.py
+++ b/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()
diff --git a/tools/binman/fmap_util.py b/tools/binman/fmap_util.py
index 1ce63d1a832..ea8d6a45008 100644
--- a/tools/binman/fmap_util.py
+++ b/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__'
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index d469928b256..3cb17b6dec8 100644
--- a/tools/binman/ftest.py
+++ b/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'
diff --git a/tools/binman/image.py b/tools/binman/image.py
index 941596320c1..8ebf71d61a8 100644
--- a/tools/binman/image.py
+++ b/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
diff --git a/tools/binman/image_test.py b/tools/binman/image_test.py
index e351fa84ab3..bd51c1e55d1 100644
--- a/tools/binman/image_test.py
+++ b/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):
diff --git a/tools/binman/main.py b/tools/binman/main.py
index 14432a8d0dc..eef17b7b55f 100755
--- a/tools/binman/main.py
+++ b/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):
diff --git a/tools/binman/state.py b/tools/binman/state.py
index 56e5bf8bc10..87748d4ea36 100644
--- a/tools/binman/state.py
+++ b/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__))
 
diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index c2a69027f88..cbfffe191eb 100644
--- a/tools/buildman/builder.py
+++ b/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.
diff --git a/tools/buildman/builderthread.py b/tools/buildman/builderthread.py
index 680efae02d7..b8274addb4a 100644
--- a/tools/buildman/builderthread.py
+++ b/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']
diff --git a/tools/buildman/cfgutil.py b/tools/buildman/cfgutil.py
index ab74a8ef062..a340e01cb6b 100644
--- a/tools/buildman/cfgutil.py
+++ b/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_]+)(=.*)?')
diff --git a/tools/buildman/control.py b/tools/buildman/control.py
index 87e7d0e2012..76e4e2709ac 100644
--- a/tools/buildman/control.py
+++ b/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"""
diff --git a/tools/buildman/func_test.py b/tools/buildman/func_test.py
index 559e4edf74b..3885b9f083b 100644
--- a/tools/buildman/func_test.py
+++ b/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
diff --git a/tools/buildman/main.py b/tools/buildman/main.py
index 67c560c48d3..6076ba5d63d 100755
--- a/tools/buildman/main.py
+++ b/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
diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index daf5467503e..9fa6445b798 100644
--- a/tools/buildman/test.py
+++ b/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
 
diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py
index ea1ad1bcb83..688f2e26872 100644
--- a/tools/buildman/toolchain.py
+++ b/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))
diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index d933972918b..a8e05349a72 100644
--- a/tools/dtoc/fdt.py
+++ b/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
diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py
index f34316632a7..f1f70568cfe 100644
--- a/tools/dtoc/fdt_util.py
+++ b/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
diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py
index 5508759d4d5..fc9207d1b63 100755
--- a/tools/dtoc/main.py
+++ b/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__':
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index c62fcbac83f..0f544f9f54a 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/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__))
 
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index dffa86fc190..32fa69cbb01 100755
--- a/tools/dtoc/test_fdt.py
+++ b/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):
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index f93cd7f5a3a..64b740841ca 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/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__))
 
diff --git a/tools/patman/__init__.py b/tools/patman/__init__.py
index 1b98ec7feee..08eeffdf6d2 100644
--- a/tools/patman/__init__.py
+++ b/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']
diff --git a/tools/patman/__main__.py b/tools/patman/__main__.py
index 749e6348b66..30632559bb6 100755
--- a/tools/patman/__main__.py
+++ b/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)
 
diff --git a/tools/patman/checkpatch.py b/tools/patman/checkpatch.py
index d1b902dd962..c1dec323f36 100644
--- a/tools/patman/checkpatch.py
+++ b/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_]+:)?'
diff --git a/tools/patman/control.py b/tools/patman/control.py
index 38e98dab84d..d1bcea0c9a7 100644
--- a/tools/patman/control.py
+++ b/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"""
diff --git a/tools/patman/func_test.py b/tools/patman/func_test.py
index c25a47bdeb2..8c2dfbe4528 100644
--- a/tools/patman/func_test.py
+++ b/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
diff --git a/tools/patman/get_maintainer.py b/tools/patman/get_maintainer.py
index f7011be1e49..8df3d124bac 100644
--- a/tools/patman/get_maintainer.py
+++ b/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):
diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py
index 5e742102c21..6700057359f 100644
--- a/tools/patman/gitutil.py
+++ b/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
diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py
index fb6a6036f3b..f91669a9404 100644
--- a/tools/patman/patchstream.py
+++ b/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:'
diff --git a/tools/patman/series.py b/tools/patman/series.py
index 2eeeef71dc6..88417acb434 100644
--- a/tools/patman/series.py
+++ b/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',
diff --git a/tools/patman/status.py b/tools/patman/status.py
index 47ed6d61d4d..5fb436e08ff 100644
--- a/tools/patman/status.py
+++ b/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
diff --git a/tools/patman/test_settings.py b/tools/patman/test_settings.py
index c768a2fc641..06b7cbc3ab6 100644
--- a/tools/patman/test_settings.py
+++ b/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
diff --git a/tools/rmboard.py b/tools/rmboard.py
index ae256321270..0c56b149e0f 100755
--- a/tools/rmboard.py
+++ b/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
diff --git a/tools/u_boot_pylib/__init__.py b/tools/u_boot_pylib/__init__.py
new file mode 100644
index 00000000000..63c88e85ec0
--- /dev/null
+++ b/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']
diff --git a/tools/u_boot_pylib/__main__.py b/tools/u_boot_pylib/__main__.py
new file mode 100755
index 00000000000..8f98d7bd9f8
--- /dev/null
+++ b/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)
diff --git a/tools/patman/command.py b/tools/u_boot_pylib/command.py
similarity index 99%
rename from tools/patman/command.py
rename to tools/u_boot_pylib/command.py
index 92c453b5c13..9bbfc5bdd83 100644
--- a/tools/patman/command.py
+++ b/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."""
 
diff --git a/tools/patman/cros_subprocess.py b/tools/u_boot_pylib/cros_subprocess.py
similarity index 100%
rename from tools/patman/cros_subprocess.py
rename to tools/u_boot_pylib/cros_subprocess.py
diff --git a/tools/patman/terminal.py b/tools/u_boot_pylib/terminal.py
similarity index 100%
rename from tools/patman/terminal.py
rename to tools/u_boot_pylib/terminal.py
diff --git a/tools/patman/test_util.py b/tools/u_boot_pylib/test_util.py
similarity index 99%
rename from tools/patman/test_util.py
rename to tools/u_boot_pylib/test_util.py
index 9e0811b61a2..e7564e10c99 100644
--- a/tools/patman/test_util.py
+++ b/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
 
diff --git a/tools/patman/tools.py b/tools/u_boot_pylib/tools.py
similarity index 99%
rename from tools/patman/tools.py
rename to tools/u_boot_pylib/tools.py
index 2ac814d476f..187725b5015 100644
--- a/tools/patman/tools.py
+++ b/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
diff --git a/tools/patman/tout.py b/tools/u_boot_pylib/tout.py
similarity index 99%
rename from tools/patman/tout.py
rename to tools/u_boot_pylib/tout.py
index ff0fd92afcc..6bd2806f88f 100644
--- a/tools/patman/tout.py
+++ b/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)
diff --git a/tools/u_boot_pylib/u_boot_pylib b/tools/u_boot_pylib/u_boot_pylib
new file mode 120000
index 00000000000..5a427d19424
--- /dev/null
+++ b/tools/u_boot_pylib/u_boot_pylib
@@ -0,0 +1 @@
+__main__.py
\ No newline at end of file
-- 
2.39.2.637.g21b0678d19-goog



More information about the U-Boot mailing list