diff mbox series

[U-Boot,20/53] binman: Allow state functions to fail to return data

Message ID 20190720182416.183626-21-sjg@chromium.org
State Accepted
Commit 6a3b5b54110980a42284beb05865436652113772
Delegated to: Simon Glass
Headers show
Series binman: Support replacing entries in an existing image | expand

Commit Message

Simon Glass July 20, 2019, 6:23 p.m. UTC
At present these state functions raise an exception if they cannot find
what is requested. But in some cases the information is optional (e.g. an
fdtmap in a coming patch) so it is better to return gracefully.

Update these two functions to return None when the data cannot be found.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/binman/state.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Simon Glass July 29, 2019, 9:22 p.m. UTC | #1
At present these state functions raise an exception if they cannot find
what is requested. But in some cases the information is optional (e.g. an
fdtmap in a coming patch) so it is better to return gracefully.

Update these two functions to return None when the data cannot be found.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/binman/state.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/tools/binman/state.py b/tools/binman/state.py
index 7c3a987723e..87674100665 100644
--- a/tools/binman/state.py
+++ b/tools/binman/state.py
@@ -49,7 +49,10 @@  def GetFdtForEtype(etype):
     Returns:
         Fdt object associated with the entry type
     """
-    return output_fdt_files[etype][0]
+    value = output_fdt_files.get(etype);
+    if not value:
+        return None
+    return value[0]
 
 def GetFdtPath(etype):
     """Get the full pathname of a particular Fdt object
@@ -80,7 +83,9 @@  def GetFdtContents(etype='u-boot-dtb'):
             pathname to Fdt
             Fdt data (as bytes)
     """
-    if etype in output_fdt_files and not use_fake_dtb:
+    if etype not in output_fdt_files:
+        return None, None
+    if not use_fake_dtb:
         pathname = GetFdtPath(etype)
         data = GetFdtForEtype(etype).GetContents()
     else: