提交 4f44304b 编写于 作者: S Simon Glass

binman: Add basic entry types for U-Boot

Add entries to support some standard U-Boot binaries, such as u-boot.bin,
u-boot.dtb, etc. Also add some tests for these.
Signed-off-by: NSimon Glass <sjg@chromium.org>
Tested-by: NBin Meng <bmeng.cn@gmail.com>
上级 bf7fd50b
#
# Copyright (c) 2016 Google, Inc
# Written by Simon Glass <sjg@chromium.org>
#
# SPDX-License-Identifier: GPL-2.0+
#
# Test for the Entry class
import collections
import unittest
import entry
class TestEntry(unittest.TestCase):
def testEntryContents(self):
"""Test the Entry bass class"""
base_entry = entry.Entry(None, None, None, read_node=False)
self.assertEqual(True, base_entry.ObtainContents())
def testUnknownEntry(self):
"""Test that unknown entry types are detected"""
Node = collections.namedtuple('Node', ['name', 'path'])
node = Node('invalid-name', 'invalid-path')
with self.assertRaises(ValueError) as e:
entry.Entry.Create(None, node, node.name)
self.assertIn("Unknown entry type 'invalid-name' in node "
"'invalid-path'", str(e.exception))
# Copyright (c) 2016 Google, Inc
# Written by Simon Glass <sjg@chromium.org>
#
# SPDX-License-Identifier: GPL-2.0+
#
# Entry-type module for testing purposes. Not used in real images.
#
from entry import Entry
import fdt_util
import tools
class Entry__testing(Entry):
def __init__(self, image, etype, node):
Entry.__init__(self, image, etype, node)
def ObtainContents(self):
self.data = 'a'
self.contents_size = len(self.data)
return True
def ReadContents(self):
return True
def GetPositions(self):
return {'invalid-entry': [1, 2]}
# Copyright (c) 2016 Google, Inc
# Written by Simon Glass <sjg@chromium.org>
#
# SPDX-License-Identifier: GPL-2.0+
#
# Entry-type module for blobs, which are binary objects read from files
#
from entry import Entry
import fdt_util
import tools
class Entry_blob(Entry):
def __init__(self, image, etype, node):
Entry.__init__(self, image, etype, node)
self._filename = fdt_util.GetString(self._node, "filename", self.etype)
def ObtainContents(self):
self._filename = self.GetDefaultFilename()
self._pathname = tools.GetInputFilename(self._filename)
self.ReadContents()
return True
def ReadContents(self):
with open(self._pathname) as fd:
# We assume the data is small enough to fit into memory. If this
# is used for large filesystem image that might not be true.
# In that case, Image.BuildImage() could be adjusted to use a
# new Entry method which can read in chunks. Then we could copy
# the data in chunks and avoid reading it all at once. For now
# this seems like an unnecessary complication.
self.data = fd.read()
self.contents_size = len(self.data)
return True
def GetDefaultFilename(self):
return self._filename
# Copyright (c) 2016 Google, Inc
# Written by Simon Glass <sjg@chromium.org>
#
# SPDX-License-Identifier: GPL-2.0+
#
# Entry-type module for U-Boot binary
#
from entry import Entry
from blob import Entry_blob
class Entry_u_boot(Entry_blob):
def __init__(self, image, etype, node):
Entry_blob.__init__(self, image, etype, node)
def GetDefaultFilename(self):
return 'u-boot.bin'
# Copyright (c) 2016 Google, Inc
# Written by Simon Glass <sjg@chromium.org>
#
# SPDX-License-Identifier: GPL-2.0+
#
# Entry-type module for U-Boot device tree
#
from entry import Entry
from blob import Entry_blob
class Entry_u_boot_dtb(Entry_blob):
def __init__(self, image, etype, node):
Entry_blob.__init__(self, image, etype, node)
def GetDefaultFilename(self):
return 'u-boot.dtb'
# Copyright (c) 2016 Google, Inc
# Written by Simon Glass <sjg@chromium.org>
#
# SPDX-License-Identifier: GPL-2.0+
#
# Entry-type module for 'u-boot-nodtb.bin'
#
from entry import Entry
from blob import Entry_blob
class Entry_u_boot_nodtb(Entry_blob):
def __init__(self, image, etype, node):
Entry_blob.__init__(self, image, etype, node)
def GetDefaultFilename(self):
return 'u-boot-nodtb.bin'
# Copyright (c) 2016 Google, Inc
# Written by Simon Glass <sjg@chromium.org>
#
# SPDX-License-Identifier: GPL-2.0+
#
# Entry-type module for spl/u-boot-spl.bin
#
from entry import Entry
from blob import Entry_blob
class Entry_u_boot_spl(Entry_blob):
def __init__(self, image, etype, node):
Entry_blob.__init__(self, image, etype, node)
def GetDefaultFilename(self):
return 'spl/u-boot-spl.bin'
此差异已折叠。
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
not-a-valid-type {
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
u-boot {
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
multiple-images;
image1 {
u-boot {
};
};
image2 {
pad-before = <3>;
pad-after = <5>;
u-boot {
};
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
u-boot {
align = <23>;
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
u-boot {
};
u-boot-align {
type = "u-boot";
align = <16>;
};
u-boot-size {
type = "u-boot";
size = <23>;
};
u-boot-next {
type = "u-boot";
};
u-boot-fixed {
type = "u-boot";
pos = <61>;
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
u-boot {
pad-before = <3>;
pad-after = <5>;
};
u-boot-align-size-nop {
type = "u-boot";
align-size = <4>;
};
u-boot-align-size {
type = "u-boot";
align = <16>;
align-size = <32>;
};
u-boot-align-end {
type = "u-boot";
align-end = <64>;
};
u-boot-align-both {
type = "u-boot";
align= <64>;
align-end = <128>;
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
u-boot {
align = <5>;
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
u-boot {
align-size = <55>;
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
u-boot {
pos = <5>;
align = <4>;
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
u-boot {
size = <5>;
align-size = <4>;
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
u-boot {
};
u-boot-align {
type = "u-boot";
pos = <3>;
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
u-boot {
size = <3>;
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
size = <3>;
u-boot {
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
size = <7>;
u-boot {
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
align-size = <16>;
u-boot {
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
size = <7>;
align-size = <8>;
u-boot {
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
align-size = <131>;
u-boot {
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
pad-byte = <0xff>;
u-boot-spl {
};
u-boot {
pos = <12>;
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
multiple-images;
image1 {
filename = "test-name";
u-boot {
};
};
image2 {
filename = "test-name.xx";
u-boot {
};
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
blob {
filename = "blobfile";
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
sort-by-pos;
u-boot {
pos = <10>;
};
u-boot-spl {
pos = <5>;
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
u-boot {
};
u-boot-spl {
pos = <0>;
};
};
};
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
binman {
u-boot-nodtb {
};
u-boot-dtb {
};
};
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册