summaryrefslogtreecommitdiff
path: root/tools/binman/elf.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/binman/elf.py')
-rw-r--r--tools/binman/elf.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/binman/elf.py b/tools/binman/elf.py
index fe50bf542c3..73f318b81d2 100644
--- a/tools/binman/elf.py
+++ b/tools/binman/elf.py
@@ -518,3 +518,18 @@ def read_loadable_segments(data):
rend = start + segment['p_filesz']
segments.append((i, segment['p_paddr'], data[start:rend]))
return segments, entry
+
+def is_valid(data):
+ """Check if some binary data is a valid ELF file
+
+ Args:
+ data (bytes): Bytes to check
+
+ Returns:
+ bool: True if a valid Elf file, False if not
+ """
+ try:
+ DecodeElf(data, 0)
+ return True
+ except ELFError:
+ return False