From: Petr Hodina <[email protected]>

Reads the node's "compression" property while generating each fdt
node and actually compresses the data before writing it when the value
isn't "none". Only "lzma" is implemented for now.

Signed-off-by: Petr Hodina <[email protected]>
---
 tools/binman/etype/fit.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py
index f28b1e6b4cb..026a373ff79 100644
--- a/tools/binman/etype/fit.py
+++ b/tools/binman/etype/fit.py
@@ -13,6 +13,7 @@ import os
 
 from binman.entry import Entry, EntryArg
 from binman.etype.section import Entry_section
+from binman import bintool
 from binman import elf
 from dtoc import fdt_util
 from dtoc.fdt import Fdt
@@ -853,8 +854,11 @@ class Entry_fit(Entry_section):
                     else:
                         fname = tools.get_input_filename(fdt_fname + '.dtb')
                     fdt_phase = None
+                    compression = 'none'
                     with fsw.add_node(node_name):
                         for pname, prop in node.props.items():
+                            if pname == 'compression':
+                                compression = fdt_util.GetString(node, pname)
                             if pname == 'fit,firmware':
                                 if firmware:
                                     fsw.property_string('firmware', firmware)
@@ -892,6 +896,14 @@ class Entry_fit(Entry_section):
                                 data = tools.read_file(phase_fname)
                             else:
                                 data = tools.read_file(fname)
+                            if compression != 'none':
+                                if compression != 'lzma':
+                                    self.Raise(
+                                        "Unsupported fdt compression "
+                                        f"'{compression}' (only 'lzma' is "
+                                        "implemented)")
+                                comp = bintool.Bintool.create('lzma_alone')
+                                data = comp.compress(data)
                             fsw.property('data', data)
 
                         for subnode in node.subnodes:

-- 
2.55.0


Reply via email to