Skip to contentSkip to conversation

elf: error out if pyelftools could not be found

PATCH Superseded Dmitrii Sharshakov 2 participants 2 messages Jan 9

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 elf: error out if pyelftools could not be found

It is not possible to validate an ELF file without pyelftools, make the error more clear and informative to the user:

Quoted 1 line

binman: Python: No module named 'elftools'

rather than:

Quoted 1 line

binman: name 'ELFError' is not defined

---
Make the error more informative and indicative of environment issue and not a code one

---
 tools/binman/elf.py | 2 ++
 1 file changed, 2 insertions(+)
tools/binman/elf.py +2 -0
index 6ac960e0419..899c84ad36d 100644
@@ -570,6 +570,8 @@ def is_valid(data):
     Returns:
         bool: True if a valid Elf file, False if not
     """
+    if not ELF_TOOLS:
+        raise ValueError("Python: No module named 'elftools'")
     try:
         DecodeElf(data, 0)
         return True

---
base-commit: 1bcb2fe324180d0a8cfbdb0511737eba1d5b8550
change-id: 20260109-pyelftools-warning-6df5f57ca5b8

Best regards,

Signature · 1 line
Dmitrii Sharshakov <[email protected]>
Reviewed-by Simon Glass on v1 1/1
#1 lore raw
Quoted 23 lines · Dmitrii Sharshakov

It is not possible to validate an ELF file without pyelftools, make the error more clear and informative to the user:

Quoted 1 line

binman: Python: No module named 'elftools'

rather than:

Quoted 1 line

binman: name 'ELFError' is not defined

---
Make the error more informative and indicative of environment issue and not a code one

---
 tools/binman/elf.py | 2 ++
 1 file changed, 2 insertions(+)
tools/binman/elf.py +0 -0
index 6ac960e0419..899c84ad36d 100644

tools/binman/elf.py def is_valid(data): · line 577

Quoted 8 lines
tools/binman/elf.py +2 -0
@@ -570,6 +570,8 @@ def is_valid(data):
     Returns:
         bool: True if a valid Elf file, False if not
     """
+    if not ELF_TOOLS:
+        raise ValueError("Python: No module named 'elftools'")
     try:
         DecodeElf(data, 0)
         return True

In that this is the common way the file checks for elftools, this is fine. But please re-word the commit message to be more akin to commit 43176ed86d9f120efb3e86084d83a714bf076d29

Author: Lukas Funke <[email protected]>
Date:   Tue Jul 18 13:53:09 2023 +0200

binman: elf: Check for ELF_TOOLS availability and remove extra semicolon

Check if elf tools are available when running DecodeElf(). Also remove superfuous semicolon at line ending.

Revert part of patch to make binman test pass

Thanks.

Signature · 1 line
Tom