[PATCH 4/6] build: Add support to make bootloader images

Chris Johns chrisj at rtems.org
Wed Feb 28 05:48:37 UTC 2024


Hi,

Is this to allow BSP ready output to be created from the build system?

If it is will the details be exported in the pkgconfig file and made available
for users building applications in a consistent and easy to use way?

Is this output created along side the ELF file?

Does this approach handle all BSPs that need this?

Will you be converting all BSPs that need this type of support?

Thanks
Chris

On 28/2/2024 2:15 am, Sebastian Huber wrote:
> Add a new build item type to provide optional BSP-specific tools to make
> bootloader images.  The tools are installed as Python scripts in:
> 
>   ${prefix}/bin/rtems-mkimage-${ARCH}-${BSP_NAME}.py
>
> Application build systems can query the tool using the RTEMS_MKIMAGE package
> configuration varible, for example:
> 
>   pkg-config --variable=RTEMS_MKIMAGE ${prefix}/lib/pkgconfig/${ARCH}-${BSP_NAME}.pc
> 
> If the BSP does not provide a tool, then the variable RTEMS_MKIMAGE is set to
> "false".
> 
> Update #4272.
> ---
>  spec/build/bsps/bspopts.yml              |  2 ++
>  spec/build/bsps/optpkgmkimage.yml        | 19 ++++++++++
>  spec/build/bsps/pkgconfig.yml            |  1 +
>  spec/build/cpukit/cpuopts.yml            |  4 +++
>  spec/build/cpukit/optbootimageext.yml    | 17 +++++++++
>  spec/build/cpukit/optbuildbootimages.yml | 16 +++++++++
>  wscript                                  | 45 ++++++++++++++++++++++--
>  7 files changed, 102 insertions(+), 2 deletions(-)
>  create mode 100644 spec/build/bsps/optpkgmkimage.yml
>  create mode 100644 spec/build/cpukit/optbootimageext.yml
>  create mode 100644 spec/build/cpukit/optbuildbootimages.yml
> 
> diff --git a/spec/build/bsps/bspopts.yml b/spec/build/bsps/bspopts.yml
> index 734292f421..74fe6d17f9 100644
> --- a/spec/build/bsps/bspopts.yml
> +++ b/spec/build/bsps/bspopts.yml
> @@ -33,6 +33,8 @@ links:
>    uid: optldflagsbsp
>  - role: build-dependency
>    uid: optmakelegacy
> +- role: build-dependency
> +  uid: optpkgmkimage
>  - role: build-dependency
>    uid: optprintexcpt
>  - role: build-dependency
> diff --git a/spec/build/bsps/optpkgmkimage.yml b/spec/build/bsps/optpkgmkimage.yml
> new file mode 100644
> index 0000000000..00d9a0171f
> --- /dev/null
> +++ b/spec/build/bsps/optpkgmkimage.yml
> @@ -0,0 +1,19 @@
> +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
> +actions:
> +- get-string: null
> +- substitute: null
> +- env-assign: null
> +build-type: option
> +copyrights:
> +- Copyright (C) 2024 embedded brains GmbH & Co. KG
> +default:
> +- enabled-by: HAVE_MKIMAGE
> +  value: $${prefix}/bin/rtems-mkimage-${ARCH}-${BSP_NAME}.py
> +- enabled-by: true
> +  value: 'false'
> +description: ''
> +enabled-by: true
> +format: '{}'
> +links: []
> +name: PKGCONFIG_MKIMAGE
> +type: build
> diff --git a/spec/build/bsps/pkgconfig.yml b/spec/build/bsps/pkgconfig.yml
> index afaffbbf0f..e1cdc9a70e 100644
> --- a/spec/build/bsps/pkgconfig.yml
> +++ b/spec/build/bsps/pkgconfig.yml
> @@ -20,6 +20,7 @@ content: |
>    RTEMS_MAJOR=${__RTEMS_MAJOR__}
>    RTEMS_MINOR=${__RTEMS_MINOR__}
>    RTEMS_REVISION=${__RTEMS_REVISION__}
> +  RTEMS_MKIMAGE=${PKGCONFIG_MKIMAGE}
>  
>    Name: ${ARCH}-rtems${__RTEMS_MAJOR__}-${BSP_NAME}
>    Version: ${RTEMS_VERSION}
> diff --git a/spec/build/cpukit/cpuopts.yml b/spec/build/cpukit/cpuopts.yml
> index 1d28ace552..bdf8fc2f66 100644
> --- a/spec/build/cpukit/cpuopts.yml
> +++ b/spec/build/cpukit/cpuopts.yml
> @@ -75,6 +75,10 @@ links:
>    uid: optcoverageldflags
>  - role: build-dependency
>    uid: optnocoverageldflags
> +- role: build-dependency
> +  uid: optbootimageext
> +- role: build-dependency
> +  uid: optbuildbootimages
>  - role: build-dependency
>    uid: optversion
>  target: cpukit/include/rtems/score/cpuopts.h
> diff --git a/spec/build/cpukit/optbootimageext.yml b/spec/build/cpukit/optbootimageext.yml
> new file mode 100644
> index 0000000000..c9347ffba8
> --- /dev/null
> +++ b/spec/build/cpukit/optbootimageext.yml
> @@ -0,0 +1,17 @@
> +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
> +actions:
> +- get-string: null
> +- env-assign: null
> +build-type: option
> +copyrights:
> +- Copyright (C) 2024 embedded brains GmbH & Co. KG
> +default:
> +- enabled-by: true
> +  value: .img
> +description: |
> +  Defines the file extension of boot images.
> +enabled-by: true
> +format: '{}'
> +links: []
> +name: BOOT_IMAGE_EXTENSION
> +type: build
> diff --git a/spec/build/cpukit/optbuildbootimages.yml b/spec/build/cpukit/optbuildbootimages.yml
> new file mode 100644
> index 0000000000..12328b006d
> --- /dev/null
> +++ b/spec/build/cpukit/optbuildbootimages.yml
> @@ -0,0 +1,16 @@
> +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
> +actions:
> +- get-boolean: null
> +- env-enable: null
> +build-type: option
> +copyrights:
> +- Copyright (C) 2024 embedded brains GmbH & Co. KG
> +default:
> +- enabled-by: true
> +  value: false
> +description: |
> +  If this option is enabled, then boot images for the test programs are built.
> +enabled-by: true
> +links: []
> +name: BUILD_BOOT_IMAGES
> +type: build
> diff --git a/wscript b/wscript
> index e43ae8ba3e..c6cfad147a 100755
> --- a/wscript
> +++ b/wscript
> @@ -197,6 +197,15 @@ def make_tar_info_reproducible(info):
>      return info
>  
>  
> +def make_image(bld, target):
> +    if not target.endswith(".norun.exe"):
> +        if bld.env.BUILD_TOOL_MKIMAGE:
> +            image = os.path.splitext(target)[0] + bld.env.BOOT_IMAGE_EXTENSION
> +            bld(rule="${BUILD_TOOL_MKIMAGE} ${SRC} ${TGT}",
> +                source=target,
> +                target=image)
> +
> +
>  class Item(object):
>  
>      def __init__(self, uid, data):
> @@ -590,6 +599,30 @@ class ConfigFileItem(Item):
>          self.install_target(bld)
>  
>  
> +class MakeImageItem(Item):
> +
> +    def __init__(self, uid, data):
> +        super(MakeImageItem, self).__init__(uid, data)
> +
> +    def do_configure(self, conf, cic):
> +        content = self.substitute(conf, self.data["content"])
> +        f = conf.bldnode.make_node(conf.env.VARIANT + "/bin/mkimage.py")
> +        f.parent.mkdir()
> +        f.write(content)
> +        # 493 == 0755
> +        f.chmod(493)
> +        file_path = f.abspath()
> +        conf.env.BUILD_TOOL_MKIMAGE = file_path
> +        conf.env.append_value("cfg_files", file_path)
> +        conf.env.append_value("ENABLE", "HAVE_MKIMAGE")
> +
> +    def do_build(self, bld, bic):
> +        bld.install_as("${PREFIX}/bin/rtems-mkimage-" + bld.env.ARCH + "-" +
> +                       bld.env.BSP_NAME + ".py",
> +                       "bin/mkimage.py",
> +                       chmod=493)
> +
> +
>  class ConfigHeaderItem(Item):
>  
>      def __init__(self, uid, data):
> @@ -745,6 +778,7 @@ class TestProgramItem(Item):
>          )
>  
>      def do_build(self, bld, bic):
> +        target = self.get(bld, "target")
>          bld(
>              cflags=bic.cflags,
>              cppflags=bic.cppflags,
> @@ -756,9 +790,10 @@ class TestProgramItem(Item):
>              source=self.data["source"],
>              start_files=True,
>              stlib=self.data["stlib"],
> -            target=self.get(bld, "target"),
> +            target=target,
>              use=bic.objects + bic.use,
>          )
> +        make_image(bld, target)
>  
>  
>  class AdaTestProgramItem(TestProgramItem):
> @@ -770,14 +805,16 @@ class AdaTestProgramItem(TestProgramItem):
>          objs = []
>          for s in self.data["source"]:
>              objs.append(self.cc(bld, bic, s))
> +        target = self.get(bld, "target")
>          self.gnatmake(
>              bld,
>              bic,
>              self.data["ada-object-directory"],
>              objs,
>              self.data["ada-main"],
> -            self.data["target"],
> +            target,
>          )
> +        make_image(bld, target)
>  
>  
>  class OptionItem(Item):
> @@ -1161,6 +1198,9 @@ class ScriptItem(Item):
>          script = self.data["do-build"]
>          if script:
>              exec(script)
> +        target = self.data.get("target", None)
> +        if target is not None:
> +            make_image(bld, self.substitute(bld, target))
>  
>  
>  class ConfigItemContext(object):
> @@ -1284,6 +1324,7 @@ def load_items(ctx, specs):
>          "test-program": TestProgramItem,
>          "group": GroupItem,
>          "library": LibraryItem,
> +        "mkimage": MakeImageItem,
>          "objects": ObjectsItem,
>          "option": OptionItem,
>          "script": ScriptItem,


More information about the devel mailing list