[PATCH v2 1/1] travis-ci: provide env__efi_fit_tftp_file

Cristian Ciocaltea cristian.ciocaltea at gmail.com
Tue Dec 31 12:32:42 CET 2019


On Tue, Dec 31, 2019 at 12:42:36PM +0200, Cristian Ciocaltea wrote:
> On Mon, Dec 30, 2019 at 09:03:38PM +0100, Heinrich Schuchardt wrote:
> > On 12/30/19 8:32 PM, Stephen Warren wrote:
> > > On 12/30/19 12:05 PM, Heinrich Schuchardt wrote:
> > > > On 12/30/19 5:38 PM, Stephen Warren wrote:
> > > > > On 12/30/19 3:52 AM, Heinrich Schuchardt wrote:
> > > > > > Provide dictionary env__efi_fit_tftp_file describing the file used for
> > > > > > the
> > > > > > UEFI FIT image test.
> > > > > 
> > > > > > diff --git a/py/travis-ci/travis_tftp.py b/py/travis-ci/travis_tftp.py
> > > > > 
> > > > > > +def efifit2env(addr=None):
> > > > > > +    """Create dictionary describing file for EFI fit image test
> > > > > > +
> > > > > > +    @addr:      address used for loading the file as int (e.g.
> > > > > > 0x40400000)
> > > > > > +    Return:     dictionary describing the file with entries
> > > > > > +                * fn    - filename
> > > > > > +                * addr  - loading address, optional
> > > > > > +                * dn    - tftp directory
> > > > > > +    """
> > > > > > +    tftp_dir = os.environ['UBOOT_TRAVIS_BUILD_DIR']
> > > > > > +
> > > > > > +    ret = {
> > > > > > +        "fn": "test-efi-fit.img",
> > > > > 
> > > > > If this function were to exist, then the filename shouldn't be
> > > > > hard-coded; it should be a parameter.
> > > > > 
> > > > 
> > > > Hello Stephen,
> > > > 
> > > > thanks for reviewing.
> > > > 
> > > > This is the name of a generated file. It does not depend on the board.
> > > 
> > > What generates the file and when/why?
> > > 
> > > Generated files should generally be put into
> > > u_boot_console.config.persistent_data_dir, and presumably the name
> > > hard-coded into the test that uses it.
> > > 
> > 
> > Hello Stephen,
> > 
> > this is the test case:
> > 
> > https://lists.denx.de/pipermail/u-boot/2019-December/394957.html
> > test/py: Create a test for launching UEFI binaries from FIT images
> > 
> > The test can be run in different styles:
> > 
> > * A complete FIT image can be supplied. In this case the dictionary
> >   must contain a "size" entry.
> > * The test can generate a FIT image from lib/efi_loader/helloworld.efi.
> >   In this case no "size" entry shall be supplied. The "fn" field
> >   provides the name of the generated file. The file is generated in
> >   cons.config.build_dir. The "dn" field" describes the tFTP root
> >   directory to which the generated file is copied.
> 
> A small correction here: if the "size" entry is not provided in the
> dictionary, the test generates a FIT image using a hardcoded file
> name (test-efi-fit-helloworld.fit), so any "fn" entry provided in the
> dictionary is ignored in this case.
>  
> > The tFTP directory "dn" is only known in uboot-test-hooks.git.
> 
> Yes, and this is actually the only mandatory information to be
> provided in the dictionary when the test is supposed to generate the
> FIT image. We could get rid of this, too, if we make the assumption
> that the tFTP root directory is u_boot_console.config.build_dir by
> default.
> 
> > test/py/README.md says --persistent-data-dir is used for data that may
> > be re-used across test runs. Currently the FIT file is generated in
> > every run. In principal it could be reused. So Christian could consider
> > adjusting his patch.
> 
> Actually the FIT image file can be generated multiple times per test
> run, with different content, which is determined by various combinations
> of flags. E.g. for sandbox we have: enable/disable GZIP compression,
> enable/disable FDT usage. Each combination is used in a subtest, that
> (re)generates the corresponding FIT image.
> 
> To re-use the generated data we need to introduce additional complexity
> to handle FIT image identification for each subtest and to invalidate
> those images when they become out of sync with the parametrized input 
> data samples (ITS, FDT) used to generate their content.
> 
> > Best regards
> > 
> > Heinrich

I would propose the following:

def efifit2env(file_name=None, addr=None):
    """Create dictionary describing file for EFI fit image test

    @filename:  name of an existing file, optional
    @addr:      address used for loading the file as int (e.g. 0x40400000)
    Return:     dictionary describing the file with entries
                * dn    - tftp directory
                * fn    - filename, optional
                * size  - file size in bytes, optional
                * crc32 - checksum using CRC-32 algorithm, optional
                * addr  - loading address, optional
    """
    tftp_dir = os.environ['UBOOT_TRAVIS_BUILD_DIR']

    ret = {
        'dn': tftp_dir,
    }

    if addr is not None:
        ret['addr'] = addr

    if file_name:
        file_full = tftp_dir + '/' + file_name
        if os.path.isfile(file_full):
            ret['fn'] = file_name
            ret['size'] = os.path.getsize(file_full)
            with open(file_full, 'rb') as f:
                ret['crc32'] = hex(binascii.crc32(f.read()) & 0xffffffff)[2:]

    return ret

This allows the test to run in both scenarios described by Heinrich:
* the FIT image is available outside the test -> efifit2env() is called
  with file_name pointing to an existing FIT image file, optionally
  pass also the addr
* the FIT image is generated by the test itself -> efifit2env() is
  called without arguments, or optionally pass only the addr


More information about the U-Boot mailing list