Ejemplo n.º 1
0
def EnsureCompiled(fname):
    """Compile an fdt .dts source file into a .dtb binary blob if needed.

    Args:
        fname: Filename (if .dts it will be compiled). It not it will be
            left alone

    Returns:
        Filename of resulting .dtb file
    """
    _, ext = os.path.splitext(fname)
    if ext != '.dts':
        return fname

    dts_input = tools.GetOutputFilename('source.dts')
    dtb_output = tools.GetOutputFilename('source.dtb')

    search_paths = [os.path.join(os.getcwd(), 'include')]
    root, _ = os.path.splitext(fname)
    args = ['-E', '-P', '-x', 'assembler-with-cpp', '-D__ASSEMBLY__']
    args += ['-Ulinux']
    for path in search_paths:
        args.extend(['-I', path])
    args += ['-o', dts_input, fname]
    command.Run('cc', *args)

    # If we don't have a directory, put it in the tools tempdir
    search_list = []
    for path in search_paths:
        search_list.extend(['-i', path])
    args = ['-I', 'dts', '-o', dtb_output, '-O', 'dtb']
    args.extend(search_list)
    args.append(dts_input)
    command.Run('dtc', *args)
    return dtb_output
Ejemplo n.º 2
0
    def ObtainContents(self):
        # Join up the data files to be signed
        input_data = ''
        for entry_phandle in self.content:
            data = self.section.GetContentsByPhandle(entry_phandle, self)
            if data is None:
                # Data not available yet
                return False
            input_data += data

        uniq = self.GetUniqueName()
        output_fname = tools.GetOutputFilename('vblock.%s' % uniq)
        input_fname = tools.GetOutputFilename('input.%s' % uniq)
        tools.WriteFile(input_fname, input_data)
        prefix = self.keydir + '/'
        args = [
            'vbutil_firmware',
            '--vblock', output_fname,
            '--keyblock', prefix + self.keyblock,
            '--signprivate', prefix + self.signprivate,
            '--version', '%d' % self.version,
            '--fv', input_fname,
            '--kernelkey', prefix + self.kernelkey,
            '--flags', '%d' % self.preamble_flags,
        ]
        #out.Notice("Sign '%s' into %s" % (', '.join(self.value), self.label))
        stdout = tools.Run('futility', *args)
        self.SetContents(tools.ReadFile(output_fname))
        return True
Ejemplo n.º 3
0
    def testDual(self):
        """Test that we can handle creating two images

        This also tests image padding.
        """
        retcode = self._DoTestFile('06_dual_image.dts')
        self.assertEqual(0, retcode)

        image = control.images['image1']
        self.assertEqual(len(U_BOOT_DATA), image._size)
        fname = tools.GetOutputFilename('image1.bin')
        self.assertTrue(os.path.exists(fname))
        with open(fname) as fd:
            data = fd.read()
            self.assertEqual(U_BOOT_DATA, data)

        image = control.images['image2']
        self.assertEqual(3 + len(U_BOOT_DATA) + 5, image._size)
        fname = tools.GetOutputFilename('image2.bin')
        self.assertTrue(os.path.exists(fname))
        with open(fname) as fd:
            data = fd.read()
            self.assertEqual(U_BOOT_DATA, data[3:7])
            self.assertEqual(chr(0) * 3, data[:3])
            self.assertEqual(chr(0) * 5, data[7:])
Ejemplo n.º 4
0
    def _BuildIfwi(self):
        """Build the contents of the IFWI and write it to the 'data' property"""
        # Create the IFWI file if needed
        if self._convert_fit:
            inname = self._pathname
            outname = tools.GetOutputFilename('ifwi.bin')
            tools.RunIfwiTool(inname, tools.CMD_CREATE, outname)
            self._filename = 'ifwi.bin'
            self._pathname = outname
        else:
            # Provide a different code path here to ensure we have test coverage
            outname = self._pathname

        # Delete OBBP if it is there, then add the required new items.
        tools.RunIfwiTool(outname, tools.CMD_DELETE, subpart='OBBP')

        for entry in self._ifwi_entries.values():
            # First get the input data and put it in a file
            data = entry.GetData()
            uniq = self.GetUniqueName()
            input_fname = tools.GetOutputFilename('input.%s' % uniq)
            tools.WriteFile(input_fname, data)

            tools.RunIfwiTool(
                outname,
                tools.CMD_REPLACE if entry._ifwi_replace else tools.CMD_ADD,
                input_fname, entry._ifwi_subpart, entry._ifwi_entry_name)

        self.ReadBlobContents()
        return True
Ejemplo n.º 5
0
    def _DoReadFileDtb(self,
                       fname,
                       use_real_dtb=False,
                       map=False,
                       update_dtb=False):
        """Run binman and return the resulting image

        This runs binman with a given test file and then reads the resulting
        output file. It is a shortcut function since most tests need to do
        these steps.

        Raises an assertion failure if binman returns a non-zero exit code.

        Args:
            fname: Device-tree source filename to use (e.g. 05_simple.dts)
            use_real_dtb: True to use the test file as the contents of
                the u-boot-dtb entry. Normally this is not needed and the
                test contents (the U_BOOT_DTB_DATA string) can be used.
                But in some test we need the real contents.
            map: True to output map files for the images
            update_dtb: Update the position and size of each entry in the device
                tree before packing it into the image

        Returns:
            Tuple:
                Resulting image contents
                Device tree contents
                Map data showing contents of image (or None if none)
        """
        dtb_data = None
        # Use the compiled test file as the u-boot-dtb input
        if use_real_dtb:
            dtb_data = self._SetupDtb(fname)

        try:
            retcode = self._DoTestFile(fname, map=map, update_dtb=update_dtb)
            self.assertEqual(0, retcode)
            out_dtb_fname = control.GetFdtPath('u-boot.dtb')

            # Find the (only) image, read it and return its contents
            image = control.images['image']
            image_fname = tools.GetOutputFilename('image.bin')
            self.assertTrue(os.path.exists(image_fname))
            if map:
                map_fname = tools.GetOutputFilename('image.map')
                with open(map_fname) as fd:
                    map_data = fd.read()
            else:
                map_data = None
            with open(image_fname) as fd:
                return fd.read(), dtb_data, map_data, out_dtb_fname
        finally:
            # Put the test file back
            if use_real_dtb:
                TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA)
Ejemplo n.º 6
0
    def testImageName(self):
        """Test that image files can be named"""
        retcode = self._DoTestFile('22_image_name.dts')
        self.assertEqual(0, retcode)
        image = control.images['image1']
        fname = tools.GetOutputFilename('test-name')
        self.assertTrue(os.path.exists(fname))

        image = control.images['image2']
        fname = tools.GetOutputFilename('test-name.xx')
        self.assertTrue(os.path.exists(fname))
Ejemplo n.º 7
0
    def test_aliases(self):
        """Test output from a node with multiple compatible strings"""
        dtb_file = get_dtb_file('dtoc_test_aliases.dts')
        output = tools.GetOutputFilename('output')
        dtb_platdata.run_steps(['struct'], dtb_file, False, output)
        with open(output) as infile:
            data = infile.read()
        self.assertEqual(
            '''#include <stdbool.h>
#include <libfdt.h>
struct dtd_compat1 {
\tfdt32_t\t\tintval;
};
#define dtd_compat2_1_fred dtd_compat1
#define dtd_compat3 dtd_compat1
''', data)

        dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
        with open(output) as infile:
            data = infile.read()
        self.assertEqual(
            '''#include <common.h>
#include <dm.h>
#include <dt-structs.h>

static struct dtd_compat1 dtv_spl_test = {
\t.intval\t\t\t= 0x1,
};
U_BOOT_DEVICE(spl_test) = {
\t.name\t\t= "compat1",
\t.platdata\t= &dtv_spl_test,
\t.platdata_size\t= sizeof(dtv_spl_test),
};

''', data)
Ejemplo n.º 8
0
    def test_phandle_reorder(self):
        """Test that phandle targets are generated before their references"""
        dtb_file = get_dtb_file('dtoc_test_phandle_reorder.dts')
        output = tools.GetOutputFilename('output')
        dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
        with open(output) as infile:
            data = infile.read()
        self._CheckStrings(
            C_HEADER + '''
static struct dtd_target dtv_phandle_target = {
};
U_BOOT_DEVICE(phandle_target) = {
\t.name\t\t= "target",
\t.platdata\t= &dtv_phandle_target,
\t.platdata_size\t= sizeof(dtv_phandle_target),
};

static struct dtd_source dtv_phandle_source2 = {
\t.clocks\t\t\t= {
\t\t\t{&dtv_phandle_target, {}},},
};
U_BOOT_DEVICE(phandle_source2) = {
\t.name\t\t= "source",
\t.platdata\t= &dtv_phandle_source2,
\t.platdata_size\t= sizeof(dtv_phandle_source2),
};

''', data)
Ejemplo n.º 9
0
    def ObtainContents(self):
        # If the image does not need microcode, there is nothing to do
        ucode_dest_entry = self.image.FindEntryType('u-boot-with-ucode-ptr')
        ucode_dest_entry_spl = self.image.FindEntryType(
            'u-boot-spl-with-ucode-ptr')
        if ((not ucode_dest_entry or not ucode_dest_entry.target_pos) and
            (not ucode_dest_entry_spl or not ucode_dest_entry_spl.target_pos)):
            self.data = ''
            return True

        # Get the microcode from the device tree entry
        fdt_entry = self.image.FindEntryType('u-boot-dtb-with-ucode')
        if not fdt_entry or not fdt_entry.ucode_data:
            return False

        if not fdt_entry.collate:
            # This section can be empty
            self.data = ''
            return True

        # Write it out to a file
        dtb_name = 'u-boot-ucode.bin'
        fname = tools.GetOutputFilename(dtb_name)
        with open(fname, 'wb') as fd:
            fd.write(fdt_entry.ucode_data)

        self._pathname = fname
        self.ReadContents()

        return True
Ejemplo n.º 10
0
 def WriteMap(self):
     """Write a map of the image to a .map file"""
     filename = '%s.map' % self._name
     fname = tools.GetOutputFilename(filename)
     with open(fname, 'w') as fd:
         print('%8s  %8s  %s' % ('Position', 'Size', 'Name'), file=fd)
         self._section.WriteMap(fd, 0)
Ejemplo n.º 11
0
    def test_aliases(self):
        """Test output from a node with multiple compatible strings"""
        dtb_file = get_dtb_file('dtoc_test_aliases.dts')
        output = tools.GetOutputFilename('output')
        dtb_platdata.run_steps(['struct'], dtb_file, False, output)
        with open(output) as infile:
            data = infile.read()
        self._CheckStrings(
            HEADER + '''
struct dtd_compat1 {
\tfdt32_t\t\tintval;
};
#define dtd_compat2_1_fred dtd_compat1
#define dtd_compat3 dtd_compat1
''', data)

        dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
        with open(output) as infile:
            data = infile.read()
        self._CheckStrings(
            C_HEADER + '''
static const struct dtd_compat1 dtv_spl_test = {
\t.intval\t\t\t= 0x1,
};
U_BOOT_DEVICE(spl_test) = {
\t.name\t\t= "compat1",
\t.platdata\t= &dtv_spl_test,
\t.platdata_size\t= sizeof(dtv_spl_test),
};

''', data)
Ejemplo n.º 12
0
    def ObtainContents(self):
        gbb = 'gbb.bin'
        fname = tools.GetOutputFilename(gbb)
        if not self.size:
            self.Raise('GBB must have a fixed size')
        gbb_size = self.size
        bmpfv_size = gbb_size - 0x2180
        if bmpfv_size < 0:
            self.Raise('GBB is too small (minimum 0x2180 bytes)')
        sizes = [0x100, 0x1000, bmpfv_size, 0x1000]
        sizes = ['%#x' % size for size in sizes]
        keydir = tools.GetInputFilename(self.keydir)
        gbb_set_command = [
            'gbb_utility', '-s',
            '--hwid=%s' % self.hardware_id,
            '--rootkey=%s/root_key.vbpubk' % keydir,
            '--recoverykey=%s/recovery_key.vbpubk' % keydir,
            '--flags=%d' % self.gbb_flags,
            '--bmpfv=%s' % tools.GetInputFilename(self.bmpblk), fname
        ]

        tools.Run('futility', 'gbb_utility', '-c', ','.join(sizes), fname)
        tools.Run('futility', *gbb_set_command)

        self.SetContents(tools.ReadFile(fname))
        return True
Ejemplo n.º 13
0
    def _RunMicrocodeTest(self, dts_fname, nodtb_data):
        data = self._DoReadFile(dts_fname, True)

        # Now check the device tree has no microcode
        second = data[len(nodtb_data):]
        fname = tools.GetOutputFilename('test.dtb')
        with open(fname, 'wb') as fd:
            fd.write(second)
        dtb = fdt.FdtScan(fname)
        ucode = dtb.GetNode('/microcode')
        self.assertTrue(ucode)
        for node in ucode.subnodes:
            self.assertFalse(node.props.get('data'))

        fdt_len = self.GetFdtLen(second)
        third = second[fdt_len:]

        # Check that the microcode appears immediately after the Fdt
        # This matches the concatenation of the data properties in
        # the /microcode/update@xxx nodes in 34_x86_ucode.dts.
        ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000,
                                 0x78235609)
        self.assertEqual(ucode_data, third[:len(ucode_data)])
        ucode_pos = len(nodtb_data) + fdt_len

        # Check that the microcode pointer was inserted. It should match the
        # expected position and size
        pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos,
                                   len(ucode_data))
        first = data[:len(nodtb_data)]
        return first, pos_and_size
Ejemplo n.º 14
0
    def ObtainContents(self):
        # If the section does not need microcode, there is nothing to do
        ucode_dest_entry = self.section.FindEntryType('u-boot-with-ucode-ptr')
        ucode_dest_entry_spl = self.section.FindEntryType(
            'u-boot-spl-with-ucode-ptr')
        if ((not ucode_dest_entry or not ucode_dest_entry.target_pos) and
            (not ucode_dest_entry_spl or not ucode_dest_entry_spl.target_pos)):
            self.data = ''
            return True

        # Get the microcode from the device tree entry. If it is not available
        # yet, return False so we will be called later. If the section simply
        # doesn't exist, then we may as well return True, since we are going to
        # get an error anyway.
        fdt_entry = self.section.FindEntryType('u-boot-dtb-with-ucode')
        if not fdt_entry:
            return True
        if not fdt_entry.ready:
            return False

        if not fdt_entry.collate:
            # This binary can be empty
            self.data = ''
            return True

        # Write it out to a file
        dtb_name = 'u-boot-ucode.bin'
        fname = tools.GetOutputFilename(dtb_name)
        with open(fname, 'wb') as fd:
            fd.write(fdt_entry.ucode_data)

        self._pathname = fname
        self.ReadContents()

        return True
Ejemplo n.º 15
0
    def ObtainContents(self):
        """Get the contects for the IFWI

        Unfortunately we cannot create anything from scratch here, as Intel has
        tools which create precursor binaries with lots of data and settings,
        and these are not incorporated into binman.

        The first step is to get a file in the IFWI format. This is either
        supplied directly or is extracted from a fitimage using the 'create'
        subcommand.

        After that we delete the OBBP sub-partition and add each of the files
        that we want in the IFWI file, one for each sub-entry of the IWFI node.
        """
        self._pathname = tools.GetInputFilename(self._filename)

        # Create the IFWI file if needed
        if self._convert_fit:
            inname = self._pathname
            outname = tools.GetOutputFilename('ifwi.bin')
            tools.RunIfwiTool(inname, tools.CMD_CREATE, outname)
            self._filename = 'ifwi.bin'
            self._pathname = outname
        else:
            # Provide a different code path here to ensure we have test coverage
            inname = self._pathname

        # Delete OBBP if it is there, then add the required new items.
        tools.RunIfwiTool(inname, tools.CMD_DELETE, subpart='OBBP')

        for entry in self._ifwi_entries.values():
            # First get the input data and put it in a file
            if not entry.ObtainContents():
                return False
            data = entry.GetData()
            uniq = self.GetUniqueName()
            input_fname = tools.GetOutputFilename('input.%s' % uniq)
            tools.WriteFile(input_fname, data)

            tools.RunIfwiTool(
                inname,
                tools.CMD_REPLACE if entry._ifwi_replace else tools.CMD_ADD,
                input_fname, entry._ifwi_subpart, entry._ifwi_entry_name)

        self.ReadBlobContents()
        return True
Ejemplo n.º 16
0
 def test_phandle_bad2(self):
     """Test a phandle target missing its #*-cells property"""
     dtb_file = get_dtb_file('dtoc_test_phandle_bad2.dts')
     output = tools.GetOutputFilename('output')
     with self.assertRaises(ValueError) as e:
         dtb_platdata.run_steps(['struct'], dtb_file, False, output)
     self.assertIn("Node 'phandle-target' has no '#clock-cells' property",
                   str(e.exception))
Ejemplo n.º 17
0
 def test_phandle_bad(self):
     """Test a node containing an invalid phandle fails"""
     dtb_file = get_dtb_file('dtoc_test_phandle_bad.dts')
     output = tools.GetOutputFilename('output')
     with self.assertRaises(ValueError) as e:
         dtb_platdata.run_steps(['struct'], dtb_file, False, output)
     self.assertIn("Cannot parse 'clocks' in node 'phandle-source'",
                   str(e.exception))
Ejemplo n.º 18
0
 def BuildImage(self):
     """Write the image to a file"""
     fname = tools.GetOutputFilename(self._filename)
     tout.Info("Writing image to '%s'" % fname)
     with open(fname, 'wb') as fd:
         data = self.GetData()
         fd.write(data)
     tout.Info("Wrote %#x bytes" % len(data))
Ejemplo n.º 19
0
 def testBadCommand(self):
     """Test running dtoc with an invalid command"""
     dtb_file = get_dtb_file('dtoc_test_simple.dts')
     output = tools.GetOutputFilename('output')
     with self.assertRaises(ValueError) as e:
         dtb_platdata.run_steps(['invalid-cmd'], dtb_file, False, output)
     self.assertIn("Unknown command 'invalid-cmd': (use: struct, platdata)",
                   str(e.exception))
Ejemplo n.º 20
0
    def test_addresses32_64(self):
        """Test output from a node with a 'reg' property with na=1, ns=2"""
        dtb_file = get_dtb_file('dtoc_test_addr32_64.dts')
        output = tools.GetOutputFilename('output')
        dtb_platdata.run_steps(['struct'], dtb_file, False, output)
        with open(output) as infile:
            data = infile.read()
        self.assertEqual(
            '''#include <stdbool.h>
#include <libfdt.h>
struct dtd_test1 {
\tfdt64_t\t\treg[2];
};
struct dtd_test2 {
\tfdt64_t\t\treg[2];
};
struct dtd_test3 {
\tfdt64_t\t\treg[4];
};
''', data)

        dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
        with open(output) as infile:
            data = infile.read()
        self.assertEqual(
            '''#include <common.h>
#include <dm.h>
#include <dt-structs.h>

static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x1234, 0x567800000000},
};
U_BOOT_DEVICE(test1) = {
\t.name\t\t= "test1",
\t.platdata\t= &dtv_test1,
\t.platdata_size\t= sizeof(dtv_test1),
};

static struct dtd_test2 dtv_test2 = {
\t.reg\t\t\t= {0x12345678, 0x9876543210987654},
};
U_BOOT_DEVICE(test2) = {
\t.name\t\t= "test2",
\t.platdata\t= &dtv_test2,
\t.platdata_size\t= sizeof(dtv_test2),
};

static struct dtd_test3 dtv_test3 = {
\t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3},
};
U_BOOT_DEVICE(test3) = {
\t.name\t\t= "test3",
\t.platdata\t= &dtv_test3,
\t.platdata_size\t= sizeof(dtv_test3),
};

''', data)
Ejemplo n.º 21
0
 def ReadBlobContents(self):
     if self._strip:
         uniq = self.GetUniqueName()
         out_fname = tools.GetOutputFilename('%s.stripped' % uniq)
         tools.WriteFile(out_fname, tools.ReadFile(self._pathname))
         tools.Run('strip', out_fname)
         self._pathname = out_fname
     Entry_blob.ReadBlobContents(self)
     return True
Ejemplo n.º 22
0
 def test_bad_reg2(self):
     """Test that a reg property with an invalid cell count is detected"""
     # Capture stderr since dtc will emit warnings for this file
     dtb_file = get_dtb_file('dtoc_test_bad_reg2.dts', capture_stderr=True)
     output = tools.GetOutputFilename('output')
     with self.assertRaises(ValueError) as e:
         dtb_platdata.run_steps(['struct'], dtb_file, False, output)
     self.assertIn("Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)",
                   str(e.exception))
Ejemplo n.º 23
0
 def test_bad_reg(self):
     """Test that a reg property with an invalid type generates an error"""
     # Capture stderr since dtc will emit warnings for this file
     dtb_file = get_dtb_file('dtoc_test_bad_reg.dts', capture_stderr=True)
     output = tools.GetOutputFilename('output')
     with self.assertRaises(ValueError) as e:
         dtb_platdata.run_steps(['struct'], dtb_file, False, output)
     self.assertIn("Node 'spl-test' reg property is not an int",
                   str(e.exception))
Ejemplo n.º 24
0
def EnsureCompiled(fname, tmpdir=None, capture_stderr=False):
    """Compile an fdt .dts source file into a .dtb binary blob if needed.

    Args:
        fname: Filename (if .dts it will be compiled). It not it will be
            left alone
        tmpdir: Temporary directory for output files, or None to use the
            tools-module output directory

    Returns:
        Filename of resulting .dtb file
    """
    _, ext = os.path.splitext(fname)
    if ext != '.dts':
        return fname

    if tmpdir:
        dts_input = os.path.join(tmpdir, 'source.dts')
        dtb_output = os.path.join(tmpdir, 'source.dtb')
    else:
        dts_input = tools.GetOutputFilename('source.dts')
        dtb_output = tools.GetOutputFilename('source.dtb')

    search_paths = [os.path.join(os.getcwd(), 'include')]
    root, _ = os.path.splitext(fname)
    args = ['-E', '-P', '-x', 'assembler-with-cpp', '-D__ASSEMBLY__']
    args += ['-Ulinux']
    for path in search_paths:
        args.extend(['-I', path])
    args += ['-o', dts_input, fname]
    command.Run('cc', *args)

    # If we don't have a directory, put it in the tools tempdir
    search_list = []
    for path in search_paths:
        search_list.extend(['-i', path])
    args = ['-I', 'dts', '-o', dtb_output, '-O', 'dtb',
            '-W', 'no-unit_address_vs_reg']
    args.extend(search_list)
    args.append(dts_input)
    dtc = os.environ.get('DTC') or 'dtc'
    command.Run(dtc, *args, capture_stderr=capture_stderr)
    return dtb_output
Ejemplo n.º 25
0
    def BuildImage(self):
        """Write the image to a file"""
        fname = tools.GetOutputFilename(self._filename)
        with open(fname, 'wb') as fd:
            fd.write(chr(self._pad_byte) * self._size)

            for entry in self._entries.values():
                data = entry.GetData()
                fd.seek(self._pad_before + entry.pos - self._skip_at_start)
                fd.write(data)
Ejemplo n.º 26
0
    def test_addresses64_32(self):
        """Test output from a node with a 'reg' property with na=2, ns=1"""
        dtb_file = get_dtb_file('dtoc_test_addr64_32.dts')
        output = tools.GetOutputFilename('output')
        dtb_platdata.run_steps(['struct'], dtb_file, False, output)
        with open(output) as infile:
            data = infile.read()
        self._CheckStrings(
            HEADER + '''
struct dtd_test1 {
\tfdt64_t\t\treg[2];
};
struct dtd_test2 {
\tfdt64_t\t\treg[2];
};
struct dtd_test3 {
\tfdt64_t\t\treg[4];
};
''', data)

        dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
        with open(output) as infile:
            data = infile.read()
        self._CheckStrings(
            C_HEADER + '''
static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x123400000000, 0x5678},
};
U_BOOT_DEVICE(test1) = {
\t.name\t\t= "test1",
\t.platdata\t= &dtv_test1,
\t.platdata_size\t= sizeof(dtv_test1),
};

static struct dtd_test2 dtv_test2 = {
\t.reg\t\t\t= {0x1234567890123456, 0x98765432},
};
U_BOOT_DEVICE(test2) = {
\t.name\t\t= "test2",
\t.platdata\t= &dtv_test2,
\t.platdata_size\t= sizeof(dtv_test2),
};

static struct dtd_test3 dtv_test3 = {
\t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3},
};
U_BOOT_DEVICE(test3) = {
\t.name\t\t= "test3",
\t.platdata\t= &dtv_test3,
\t.platdata_size\t= sizeof(dtv_test3),
};

''', data)
Ejemplo n.º 27
0
    def test_empty_file(self):
        """Test output from a device tree file with no nodes"""
        dtb_file = get_dtb_file('dtoc_test_empty.dts')
        output = tools.GetOutputFilename('output')
        dtb_platdata.run_steps(['struct'], dtb_file, False, output)
        with open(output) as infile:
            lines = infile.read().splitlines()
        self.assertEqual(HEADER.splitlines(), lines)

        dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
        with open(output) as infile:
            lines = infile.read().splitlines()
        self.assertEqual(C_HEADER.splitlines() + [''], lines)
Ejemplo n.º 28
0
    def WriteMap(self):
        """Write a map of the image to a .map file

        Returns:
            Filename of map file written
        """
        filename = '%s.map' % self.image_name
        fname = tools.GetOutputFilename(filename)
        with open(fname, 'w') as fd:
            print('%8s  %8s  %8s  %s' % ('ImagePos', 'Offset', 'Size', 'Name'),
                  file=fd)
            section.Entry_section.WriteMap(self, fd, 0)
        return fname
    def ObtainContents(self):
        Entry_blob.ObtainContents(self)

        # If the image does not need microcode, there is nothing to do
        ucode_dest_entry = self.image.FindEntryType(
            'u-boot-spl-with-ucode-ptr')
        if not ucode_dest_entry or not ucode_dest_entry.target_pos:
            ucode_dest_entry = self.image.FindEntryType(
                'u-boot-with-ucode-ptr')
        if not ucode_dest_entry or not ucode_dest_entry.target_pos:
            return True

        # Create a new file to hold the copied device tree
        dtb_name = 'u-boot-dtb-with-ucode.dtb'
        fname = tools.GetOutputFilename(dtb_name)
        with open(fname, 'wb') as fd:
            fd.write(self.data)

        # Remove the microcode
        fdt = fdt_select.FdtScan(fname)
        fdt.Scan()
        ucode = fdt.GetNode('/microcode')
        if not ucode:
            raise self.Raise("No /microcode node found in '%s'" % fname)

        # There's no need to collate it (move all microcode into one place)
        # if we only have one chunk of microcode.
        self.collate = len(ucode.subnodes) > 1
        for node in ucode.subnodes:
            data_prop = node.props.get('data')
            if data_prop:
                self.ucode_data += ''.join(data_prop.bytes)
                if not self.collate:
                    poffset = data_prop.GetOffset()
                    if poffset is None:
                        # We cannot obtain a property offset. Collate instead.
                        self.collate = True
                    else:
                        # Find the offset in the device tree of the ucode data
                        self.ucode_offset = poffset + 12
                        self.ucode_size = len(data_prop.bytes)
                if self.collate:
                    prop = node.DeleteProp('data')
        if self.collate:
            fdt.Pack()
            fdt.Flush()

            # Make this file the contents of this entry
            self._pathname = fname
            self.ReadContents()
        return True
Ejemplo n.º 30
0
    def _RunMicrocodeTest(self, dts_fname, nodtb_data, ucode_second=False):
        """Handle running a test for insertion of microcode

        Args:
            dts_fname: Name of test .dts file
            nodtb_data: Data that we expect in the first section
            ucode_second: True if the microsecond entry is second instead of
                third

        Returns:
            Tuple:
                Contents of first region (U-Boot or SPL)
                Position and size components of microcode pointer, as inserted
                    in the above (two 4-byte words)
        """
        data = self._DoReadFile(dts_fname, True)

        # Now check the device tree has no microcode
        if ucode_second:
            ucode_content = data[len(nodtb_data):]
            ucode_pos = len(nodtb_data)
            dtb_with_ucode = ucode_content[16:]
            fdt_len = self.GetFdtLen(dtb_with_ucode)
        else:
            dtb_with_ucode = data[len(nodtb_data):]
            fdt_len = self.GetFdtLen(dtb_with_ucode)
            ucode_content = dtb_with_ucode[fdt_len:]
            ucode_pos = len(nodtb_data) + fdt_len
        fname = tools.GetOutputFilename('test.dtb')
        with open(fname, 'wb') as fd:
            fd.write(dtb_with_ucode)
        dtb = fdt.FdtScan(fname)
        ucode = dtb.GetNode('/microcode')
        self.assertTrue(ucode)
        for node in ucode.subnodes:
            self.assertFalse(node.props.get('data'))

        # Check that the microcode appears immediately after the Fdt
        # This matches the concatenation of the data properties in
        # the /microcode/update@xxx nodes in 34_x86_ucode.dts.
        ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000,
                                 0x78235609)
        self.assertEqual(ucode_data, ucode_content[:len(ucode_data)])

        # Check that the microcode pointer was inserted. It should match the
        # expected position and size
        pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos,
                                   len(ucode_data))
        u_boot = data[:len(nodtb_data)]
        return u_boot, pos_and_size