u-boot-brain/tools/binman/etype/text.py
Simon Glass e16b7b6c49 binman: Update 'text' entry for Python 3
This code reads a binary value and then uses it as a string to look up
another value. Add conversions to make this work as expected on Python 3.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00

64 lines
1.9 KiB
Python

# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2018 Google, Inc
# Written by Simon Glass <sjg@chromium.org>
#
from collections import OrderedDict
from entry import Entry, EntryArg
import fdt_util
import tools
class Entry_text(Entry):
"""An entry which contains text
The text can be provided either in the node itself or by a command-line
argument. There is a level of indirection to allow multiple text strings
and sharing of text.
Properties / Entry arguments:
text-label: The value of this string indicates the property / entry-arg
that contains the string to place in the entry
<xxx> (actual name is the value of text-label): contains the string to
place in the entry.
Example node:
text {
size = <50>;
text-label = "message";
};
You can then use:
binman -amessage="this is my message"
and binman will insert that string into the entry.
It is also possible to put the string directly in the node:
text {
size = <8>;
text-label = "message";
message = "a message directly in the node"
};
The text is not itself nul-terminated. This can be achieved, if required,
by setting the size of the entry to something larger than the text.
"""
def __init__(self, section, etype, node):
Entry.__init__(self, section, etype, node)
label, = self.GetEntryArgsOrProps([EntryArg('text-label', str)])
self.text_label = tools.ToStr(label) if type(label) != str else label
value, = self.GetEntryArgsOrProps([EntryArg(self.text_label, str)])
value = tools.ToBytes(value) if value is not None else value
self.value = value
def ObtainContents(self):
if not self.value:
self.Raise("No value provided for text label '%s'" %
self.text_label)
self.SetContents(self.value)
return True