Esempio n. 1
0
 def test_compare(self):
     prop1 = fdt.PropStrings('prop', ['test', 'test'])
     prop2 = fdt.PropStrings('prop', ['test', 'test', 'test'])
     self.assertEqual(prop1, prop1)
     self.assertNotEqual(prop1, prop2)
     prop1.append("test")
     self.assertEqual(prop1, prop2)
     prop1.name = 'prop1'
     self.assertNotEqual(prop1, prop2)
Esempio n. 2
0
 def setUp(self):
     self.node_a = fdt.Node('/')
     self.node_a.append(fdt.Property('prop'))
     self.node_a.append(fdt.PropStrings('prop_str', 'test', 'test'))
     self.node_a.append(fdt.PropWords('prop_word', 0x11111111, 0x55555555))
     self.node_a.append(fdt.PropBytes('prop_byte', [0x10, 0x50]))
     self.node_a.append(fdt.Node('sub_node'))
Esempio n. 3
0
 def test_init(self):
     prop = fdt.PropStrings('prop')
     prop.append("test")
     prop.append("test")
     self.assertIsInstance(prop, fdt.PropStrings)
     self.assertEqual(prop.name, 'prop')
     self.assertEqual(len(prop), 2)
     with self.assertRaises(ValueError):
         prop.append('test\0')
     with self.assertRaises(TypeError):
         prop.append(5)
Esempio n. 4
0
def test_strings_property():
    prop = fdt.PropStrings('prop', 'test', 'test')

    assert isinstance(prop, fdt.PropStrings)
    assert prop.name == 'prop'
    assert len(prop) == 2
    assert prop.data == ['test', 'test']

    with pytest.raises(AssertionError):
        prop.append('test\0')
    with pytest.raises(AssertionError):
        prop.append(5)

    prop1 = fdt.PropStrings('prop', 'test', 'test', 'test')
    assert prop1 != prop

    prop.append("test")
    assert len(prop) == 3
    assert prop1 == prop

    str_data = prop.to_dts()
    assert str_data == 'prop = "test", "test", "test";\n'
Esempio n. 5
0
    def to_its(self, rpath=None, tabsize=4):
        """ Export to ITS format

        :param rpath:
        :param tabsize:
        :return:
        """
        data = {}
        images = fdt.Node("images")
        for img in self.img_info:
            img_name = img.name.replace('@', '_') + '.bin'
            img_clone = img.copy()
            img_clone.append(fdt.PropIncBin("data", None, img_name, rpath))
            images.append(img_clone)
            data[img_name] = self.img_data[img.name]

        # Check default config
        if self.def_config is None:
            raise Exception("Default config not defined")
        if self.def_config not in [cnf.name for cnf in self.configs]:
            raise Exception("Default config \"{}\" doesn't exist".format(
                self.def_config))

        # Add images and configs
        root_node = fdt.Node('/')
        root_node.append(fdt.PropStrings("description", self.description))
        root_node.append(images)
        configs = fdt.Node("configurations", nodes=self.configs)
        configs.append(fdt.PropStrings("default", self.def_config))
        root_node.append(configs)

        # Crete ITS
        its = "/dts-v1/;\n"
        its += '\n'
        its += root_node.to_dts(tabsize)
        return its, data
Esempio n. 6
0
 def test_export(self):
     prop = fdt.PropStrings('prop', ['test', 'test'])
     str_data = prop.to_dts()
     self.assertEqual(str_data, 'prop = "test", "test";\n')
Esempio n. 7
0
def test_node():
    # create node object
    node = fdt.Node('/')
    node.append(fdt.Property('prop'))
    node.append(fdt.PropStrings('prop_str', 'test', 'test'))
    node.append(fdt.PropWords('prop_word', 0x11111111, 0x55555555))
    node.append(fdt.PropBytes('prop_byte', [0x10, 0x50]))
    subnode0 = fdt.Node('subnode0')
    subnode0.append(fdt.Property('prop0'))
    subnode0.append(fdt.PropStrings('prop_str0', 'test'))
    subnode1 = fdt.Node('subnode1')
    subnode1.append(fdt.Property('prop1'))
    subnode1.append(fdt.PropWords('prop_word1', 0x11111111))
    subnode0.append(subnode1)
    node.append(subnode0)

    assert isinstance(node, fdt.Node)
    assert node.name == '/'
    assert len(node.props) == 4
    assert len(node.nodes) == 1

    # Use only node constructor
    new_node = fdt.Node('/',
                        fdt.Property('prop'),
                        fdt.PropStrings('prop_str', 'test', 'test'),
                        fdt.PropWords('prop_word', 0x11111111, 0x55555555),
                        fdt.PropBytes('prop_byte', [0x10, 0x50]),
                        fdt.Node('subnode0',
                                 fdt.Property('prop0'),
                                 fdt.PropStrings('prop_str0', 'test'),
                                 fdt.Node('subnode1',
                                          fdt.Property('prop1'),
                                          fdt.PropWords('prop_word1', 0x11111111)
                                          )
                                 )
                        )

    assert node == new_node

    with pytest.raises(AssertionError):
        node.append('test')
    with pytest.raises(Exception):
        node.append(256)
    with pytest.raises(Exception):
        node.append(fdt.Property('prop'))

    copy_node = node.copy()
    assert copy_node == node

    copy_node.set_property('prop_word', [0x10, 0x50])
    assert copy_node != node

    # export to dts
    str_data = node.to_dts()
    out = "/ {\n"
    out += "    prop;\n"
    out += "    prop_str = \"test\", \"test\";\n"
    out += "    prop_word = <0x11111111 0x55555555>;\n"
    out += "    prop_byte = [10 50];\n"
    out += "    subnode0 {\n"
    out += "        prop0;\n"
    out += "        prop_str0 = \"test\";\n"
    out += "        subnode1 {\n"
    out += "            prop1;\n"
    out += "            prop_word1 = <0x11111111>;\n"
    out += "        };\n"
    out += "    };\n"
    out += "};\n"

    assert str_data == out
Esempio n. 8
0
    def to_itb(self, padding=0, align=None, size=None):
        """ Export to ITB format

        :param padding:
        :param align:
        :param size:
        :return:
        """
        img_blob = bytes()
        img_offset = padding

        fdt_obj = fdt.FDT()
        fdt_obj.add_item(
            fdt.PropWords(
                "timestamp",
                int(time.time())
                if self.time_stamp is None else self.time_stamp))
        fdt_obj.add_item(fdt.PropStrings("description", self.description))

        # Add images
        node = fdt.Node("images")
        for image in self.img_info:
            if image.name not in self.img_data:
                raise Exception("export: data is None")
            cimg = image.copy()
            data = self.img_data[image.name]
            if padding:
                img_blob += data
                img_offset += len(data)
                cimg.append(fdt.PropWords("data-size", len(data)))
                cimg.append(fdt.PropWords("data-position", img_offset))
            else:
                cimg.append(fdt.PropBytes("data", data=data))
            node.append(cimg)
        fdt_obj.add_item(node)

        # Check default config
        if self.def_config is None:
            raise Exception("Default config not defined")
        if self.def_config not in [cnf.name for cnf in self.configs]:
            raise Exception("Default config \"{}\" doesn't exist".format(
                self.def_config))

        # Add configs
        node = fdt.Node("configurations")
        node.append(fdt.PropStrings("default", self.def_config))
        for cfg in self.configs:
            node.append(cfg)
        fdt_obj.add_item(node)

        # Generate FDT blob
        itb = fdt_obj.to_dtb(17)

        # ...
        if padding:
            itb_align = padding - len(itb)
            if itb_align < 0:
                raise Exception()
            if itb_align > 0:
                itb += bytes([0] * itb_align)
            itb += img_blob

        return itb