1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2018 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
6 from collections import OrderedDict
8 from binman.entry import Entry, EntryArg
9 from dtoc import fdt_util
13 class Entry_text(Entry):
14 """An entry which contains text
16 The text can be provided either in the node itself or by a command-line
17 argument. There is a level of indirection to allow multiple text strings
20 Properties / Entry arguments:
21 text-label: The value of this string indicates the property / entry-arg
22 that contains the string to place in the entry
23 <xxx> (actual name is the value of text-label): contains the string to
25 <text>: The text to place in the entry (overrides the above mechanism).
26 This is useful when the text is constant.
32 text-label = "message";
37 binman -amessage="this is my message"
39 and binman will insert that string into the entry.
41 It is also possible to put the string directly in the node:
45 text-label = "message";
46 message = "a message directly in the node"
53 text = "some text directly in the node"
56 The text is not itself nul-terminated. This can be achieved, if required,
57 by setting the size of the entry to something larger than the text.
59 def __init__(self, section, etype, node):
60 Entry.__init__(self, section, etype, node)
61 value = fdt_util.GetString(self._node, 'text')
63 value = tools.ToBytes(value)
65 label, = self.GetEntryArgsOrProps([EntryArg('text-label', str)])
66 self.text_label = label
68 value, = self.GetEntryArgsOrProps([EntryArg(self.text_label,
70 value = tools.ToBytes(value) if value is not None else value
73 def ObtainContents(self):
75 self.Raise("No value provided for text label '%s'" %
77 self.SetContents(self.value)