1# SPDX-License-Identifier: GPL-2.0+
2# Copyright (c) 2018 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
5
6from binman.entry import Entry
7from dtoc import fdt_util
8from u_boot_pylib import tools
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        super().__init__(section, etype, node)
26        self.required_props = ['size']
27
28    def ReadNode(self):
29        super().ReadNode()
30        self.fill_value = fdt_util.GetByte(self._node, 'fill-byte', 0)
31
32    def ObtainContents(self):
33        self.SetContents(tools.get_bytes(self.fill_value, self.size))
34        return True
35