text.py 1.8 KB

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