binman: Support an entry that holds text
[oweals/u-boot.git] / tools / binman / etype / text.py
1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2018 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
4 #
5
6 from collections import OrderedDict
7
8 from entry import Entry, EntryArg
9 import fdt_util
10
11
12 class Entry_text(Entry):
13     """An entry which contains text
14
15     The text can be provided either in the node itself or by a command-line
16     argument.
17
18     Example node:
19
20         text {
21             size = <50>;
22             text-label = "message";
23         };
24
25     You can then use:
26
27         binman -amessage="this is my message"
28
29     and binman will insert that string into the entry.
30
31     It is also possible to put the string directly in the node:
32
33         text {
34             size = <8>;
35             text-label = "message";
36             message = "a message directly in the node"
37         };
38
39     The text is not itself nul-terminated. This can be achieved, if required,
40     by setting the size of the entry to something larger than the text.
41     """
42     def __init__(self, section, etype, node):
43         Entry.__init__(self, section, etype, node)
44         self.text_label, = self.GetEntryArgsOrProps(
45             [EntryArg('text-label', str)])
46         self.value, = self.GetEntryArgsOrProps([EntryArg(self.text_label, str)])
47
48     def ObtainContents(self):
49         self.SetContents(self.value)
50         return True