2018-05-07 06:58:06 +09:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2016-11-26 12:15:52 +09:00
|
|
|
# Copyright (c) 2016 Google, Inc
|
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
|
|
#
|
|
|
|
# Entry-type module for testing purposes. Not used in real images.
|
|
|
|
#
|
|
|
|
|
2018-07-18 04:25:32 +09:00
|
|
|
from collections import OrderedDict
|
|
|
|
|
2020-04-18 09:09:03 +09:00
|
|
|
from binman.entry import Entry, EntryArg
|
|
|
|
from dtoc import fdt_util
|
2020-04-18 09:09:04 +09:00
|
|
|
from patman import tools
|
2016-11-26 12:15:52 +09:00
|
|
|
|
2018-07-07 01:27:17 +09:00
|
|
|
|
2016-11-26 12:15:52 +09:00
|
|
|
class Entry__testing(Entry):
|
2018-07-07 01:27:15 +09:00
|
|
|
"""A fake entry used for testing
|
|
|
|
|
2018-07-18 04:25:35 +09:00
|
|
|
This entry should not be used in normal images. It is a special entry with
|
|
|
|
strange features used for testing.
|
|
|
|
|
|
|
|
Properties / Entry arguments
|
|
|
|
test-str-fdt: Test string, normally in the node
|
|
|
|
test-int-fdt: Test integer, normally in the node
|
|
|
|
test-str-arg: Test string, normally in the entry arguments
|
|
|
|
test-int-arg: Test integer, normally in the entry arguments
|
|
|
|
|
|
|
|
The entry has a single 'a' byte as its contents. Operation is controlled by
|
|
|
|
a number of properties in the node, as follows:
|
|
|
|
|
2018-07-07 01:27:15 +09:00
|
|
|
Properties:
|
2018-07-18 04:25:35 +09:00
|
|
|
return-invalid-entry: Return an invalid entry from GetOffsets()
|
|
|
|
return-unknown-contents: Refuse to provide any contents (to cause a
|
|
|
|
failure)
|
2019-07-21 03:23:57 +09:00
|
|
|
bad-update-contents: Return a larger size in ProcessContents
|
|
|
|
bad-shrink-contents: Return a larger size in ProcessContents
|
2018-07-18 04:25:35 +09:00
|
|
|
never-complete-process-fdt: Refund to process the FDT (to cause a
|
|
|
|
failure)
|
|
|
|
require-args: Require that all used args are present (generating an
|
|
|
|
error if not)
|
|
|
|
force-bad-datatype: Force a call to GetEntryArgsOrProps() with a bad
|
|
|
|
data type (generating an error)
|
2018-07-07 01:27:15 +09:00
|
|
|
"""
|
2018-06-02 00:38:14 +09:00
|
|
|
def __init__(self, section, etype, node):
|
|
|
|
Entry.__init__(self, section, etype, node)
|
2019-07-21 03:23:45 +09:00
|
|
|
|
|
|
|
def ReadNode(self):
|
|
|
|
Entry.ReadNode(self)
|
2018-07-07 01:27:15 +09:00
|
|
|
self.return_invalid_entry = fdt_util.GetBool(self._node,
|
|
|
|
'return-invalid-entry')
|
2018-07-07 01:27:17 +09:00
|
|
|
self.return_unknown_contents = fdt_util.GetBool(self._node,
|
|
|
|
'return-unknown-contents')
|
2018-07-07 01:27:19 +09:00
|
|
|
self.bad_update_contents = fdt_util.GetBool(self._node,
|
|
|
|
'bad-update-contents')
|
2019-07-21 03:23:57 +09:00
|
|
|
self.bad_shrink_contents = fdt_util.GetBool(self._node,
|
|
|
|
'bad-shrink-contents')
|
2018-09-14 19:57:29 +09:00
|
|
|
self.return_contents_once = fdt_util.GetBool(self._node,
|
|
|
|
'return-contents-once')
|
2019-07-09 05:25:37 +09:00
|
|
|
self.bad_update_contents_twice = fdt_util.GetBool(self._node,
|
|
|
|
'bad-update-contents-twice')
|
2020-07-10 09:39:31 +09:00
|
|
|
self.return_contents_later = fdt_util.GetBool(self._node,
|
|
|
|
'return-contents-later')
|
2018-07-18 04:25:35 +09:00
|
|
|
|
|
|
|
# Set to True when the entry is ready to process the FDT.
|
2018-07-07 01:27:42 +09:00
|
|
|
self.process_fdt_ready = False
|
|
|
|
self.never_complete_process_fdt = fdt_util.GetBool(self._node,
|
|
|
|
'never-complete-process-fdt')
|
2018-07-18 04:25:32 +09:00
|
|
|
self.require_args = fdt_util.GetBool(self._node, 'require-args')
|
|
|
|
|
|
|
|
# This should be picked up by GetEntryArgsOrProps()
|
|
|
|
self.test_existing_prop = 'existing'
|
|
|
|
self.force_bad_datatype = fdt_util.GetBool(self._node,
|
|
|
|
'force-bad-datatype')
|
|
|
|
(self.test_str_fdt, self.test_str_arg, self.test_int_fdt,
|
|
|
|
self.test_int_arg, existing) = self.GetEntryArgsOrProps([
|
|
|
|
EntryArg('test-str-fdt', str),
|
|
|
|
EntryArg('test-str-arg', str),
|
|
|
|
EntryArg('test-int-fdt', int),
|
|
|
|
EntryArg('test-int-arg', int),
|
|
|
|
EntryArg('test-existing-prop', str)], self.require_args)
|
|
|
|
if self.force_bad_datatype:
|
|
|
|
self.GetEntryArgsOrProps([EntryArg('test-bad-datatype-arg', bool)])
|
2018-09-14 19:57:29 +09:00
|
|
|
self.return_contents = True
|
2019-07-21 03:23:57 +09:00
|
|
|
self.contents = b'aa'
|
2016-11-26 12:15:52 +09:00
|
|
|
|
|
|
|
def ObtainContents(self):
|
2018-09-14 19:57:29 +09:00
|
|
|
if self.return_unknown_contents or not self.return_contents:
|
2018-07-07 01:27:17 +09:00
|
|
|
return False
|
2020-07-10 09:39:31 +09:00
|
|
|
if self.return_contents_later:
|
|
|
|
self.return_contents_later = False
|
|
|
|
return False
|
2019-07-09 05:25:37 +09:00
|
|
|
self.data = self.contents
|
2016-11-26 12:15:52 +09:00
|
|
|
self.contents_size = len(self.data)
|
2018-09-14 19:57:29 +09:00
|
|
|
if self.return_contents_once:
|
|
|
|
self.return_contents = False
|
2016-11-26 12:15:52 +09:00
|
|
|
return True
|
|
|
|
|
2018-08-02 06:22:37 +09:00
|
|
|
def GetOffsets(self):
|
2018-07-07 01:27:15 +09:00
|
|
|
if self.return_invalid_entry :
|
|
|
|
return {'invalid-entry': [1, 2]}
|
|
|
|
return {}
|
2018-07-07 01:27:19 +09:00
|
|
|
|
|
|
|
def ProcessContents(self):
|
2019-07-21 03:23:57 +09:00
|
|
|
data = self.contents
|
2018-07-07 01:27:19 +09:00
|
|
|
if self.bad_update_contents:
|
2019-07-09 05:25:35 +09:00
|
|
|
# Request to update the contents with something larger, to cause a
|
2018-07-07 01:27:19 +09:00
|
|
|
# failure.
|
2019-07-09 05:25:37 +09:00
|
|
|
if self.bad_update_contents_twice:
|
2019-07-21 03:23:57 +09:00
|
|
|
data = self.data + b'a'
|
2019-07-09 05:25:37 +09:00
|
|
|
else:
|
2019-07-21 03:23:57 +09:00
|
|
|
data = b'aaa'
|
|
|
|
return self.ProcessContentsUpdate(data)
|
|
|
|
if self.bad_shrink_contents:
|
|
|
|
# Request to update the contents with something smaller, to cause a
|
|
|
|
# failure.
|
|
|
|
data = b'a'
|
|
|
|
return self.ProcessContentsUpdate(data)
|
|
|
|
if self.bad_shrink_contents:
|
|
|
|
# Request to update the contents with something smaller, to cause a
|
|
|
|
# failure.
|
|
|
|
data = b'a'
|
|
|
|
return self.ProcessContentsUpdate(data)
|
2019-07-09 05:25:35 +09:00
|
|
|
return True
|
2018-07-07 01:27:42 +09:00
|
|
|
|
|
|
|
def ProcessFdt(self, fdt):
|
|
|
|
"""Force reprocessing the first time"""
|
|
|
|
ready = self.process_fdt_ready
|
|
|
|
if not self.never_complete_process_fdt:
|
|
|
|
self.process_fdt_ready = True
|
|
|
|
return ready
|