xref: /openbmc/u-boot/tools/binman/etype/fill.py (revision d24c1d0f4da3b081a4fedf7ae2a08790871f08d0)
1# SPDX-License-Identifier: GPL-2.0+
2# Copyright (c) 2018 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
5
6from entry import Entry
7import fdt_util
8
9
10class Entry_fill(Entry):
11    """An entry which is filled to a particular byte value
12
13    Properties / Entry arguments:
14        - fill-byte: Byte to use to fill the entry
15
16    Note that the size property must be set since otherwise this entry does not
17    know how large it should be.
18
19    You can often achieve the same effect using the pad-byte property of the
20    overall image, in that the space between entries will then be padded with
21    that byte. But this entry is sometimes useful for explicitly setting the
22    byte value of a region.
23    """
24    def __init__(self, section, etype, node):
25        Entry.__init__(self, section, etype, node)
26        if self.size is None:
27            self.Raise("'fill' entry must have a size property")
28        self.fill_value = fdt_util.GetByte(self._node, 'fill-byte', 0)
29
30    def ObtainContents(self):
31        self.SetContents(chr(self.fill_value) * self.size)
32        return True
33