[elbe-devel] [PATCH 10/14] Debianize - More panels

Bastian Germann bage at linutronix.de
Thu Aug 1 15:44:54 CEST 2019


> From: Olivier Dion <dion at linutronix.de>
> 

Please add a useful commit message for such a massive change.

> Signed-off-by: Olivier Dion <dion at linutronix.de>
> ---
>  elbepack/debianize/panels/barebox.py | 61 +++++++++++++++++++++++++
>  elbepack/debianize/panels/kernel.py  | 86 ++++++++++++++++++++++++++++++++++++
>  elbepack/debianize/panels/uboot.py   | 86 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 233 insertions(+)
>  create mode 100644 elbepack/debianize/panels/barebox.py
>  create mode 100644 elbepack/debianize/panels/kernel.py
>  create mode 100644 elbepack/debianize/panels/uboot.py
> 
> diff --git a/elbepack/debianize/panels/barebox.py b/elbepack/debianize/panels/barebox.py
> new file mode 100644
> index 00000000..0405fbf5
> --- /dev/null
> +++ b/elbepack/debianize/panels/barebox.py
> @@ -0,0 +1,61 @@
> +# ELBE - Debian Based Embedded Rootfilesystem Builder
> +# Copyright (c) 2017 Torben Hohn <torben.hohn at linutronix.de>
> +# Copyright (c) 2017 Manuel Traut <manut at linutronix.de>
> +#
> +# SPDX-License-Identifier: GPL-3.0-or-later
> +
> +import os
> +
> +from shutil import copyfile
> +
> +from elbepack.debianize.base.tui import TUI
> +from elbepack.debianize.panels.base import Panel, StrEnum
> +from elbepack.debianize.widgets.edit import Edit
> +from elbepack.debianize.widgets.radio import RadioGroup
> +
> +from elbepack.directories import mako_template_dir
> +from elbepack.templates import template
> +from elbepack.shellhelper import system
> +
> +
> +class BareBox(Panel):
> +
> +    match_files = ['Kbuild', 'Kconfig', 'README', 'Documentation/barebox.svg']
> +
> +    def __init__(self):
> +
> +        imgname = Edit("Image name", "barebox-phytec-phycore-imx6dl-som-nand-256mb.img")
> +        defconfig = Edit("Def config", "imx_v7_defconfig")
> +        cross = Edit("CROSS_COMPILE", "arm-linux-gnueabihf-")
> +        k_version = Edit("BareBox Version", "2016.10")
> +
> +        grid_elements = [
> +            {"imgname":imgname, "defconfig":defconfig},
> +            {"cross":cross, "k_version":k_version}
> +        ]
> +
> +        super().__init__(grid_elements)
> +
> +    def debianize(self):
> +
> +        self.tmpl_dir = os.path.join(mako_template_dir, 'debianize/barebox')
> +        pkg_name = self.deb['p_name'] + '-' + self.deb['k_version']
> +
> +        for tmpl in ['control', 'rules']:
> +            with open(os.path.join('debian/', tmpl), 'w') as f:
> +                mako = os.path.join(self.tmpl_dir, tmpl + '.mako')
> +                f.write(template(mako, self.deb))
> +
> +        cmd = 'dch --package barebox-' + pkg_name + \
> +            ' -v ' + self.deb['p_version'] + \
> +            ' --create -M -D ' + self.deb['release'] + \
> +            ' "generated by elbe debianize"'
> +        system(cmd)
> +
> +        copyfile(os.path.join(self.tmpl_dir, 'barebox-image.install'),
> +                 'debian/barebox-image-' + pkg_name + '.install')
> +        copyfile(os.path.join(self.tmpl_dir, 'barebox-tools.install'),
> +                 'debian/barebox-tools-' + pkg_name + '.install')
> +
> +        self.hint = "use 'dpkg-buildpackage -a%s' to build the package" % (
> +                self.deb['p_arch'])
> diff --git a/elbepack/debianize/panels/kernel.py b/elbepack/debianize/panels/kernel.py
> new file mode 100644
> index 00000000..4b391516
> --- /dev/null
> +++ b/elbepack/debianize/panels/kernel.py
> @@ -0,0 +1,86 @@
> +# ELBE - Debian Based Embedded Rootfilesystem Builder
> +# Copyright (c) 2016-2017 John Ogness <john.ogness at linutronix.de>
> +# Copyright (c) 2016-2017 Manuel Traut <manut at linutronix.de>
> +# Copyright (c) 2017 Torben Hohn <torben.hohn at linutronix.de>
> +#
> +# SPDX-License-Identifier: GPL-3.0-or-later
> +
> +import os
> +
> +from shutil import copyfile
> +
> +from elbepack.debianize.base.tui import TUI
> +from elbepack.debianize.panels.base import Panel, StrEnum
> +from elbepack.debianize.widgets.edit import Edit
> +from elbepack.debianize.widgets.radio import RadioGroup
> +
> +from elbepack.directories import mako_template_dir
> +from elbepack.templates import template
> +from elbepack.shellhelper import system
> +
> +
> +class ImgType(StrEnum):
> +    BZ = "bzImage"
> +    ZI = "zImage"
> +    UI = "uImage"
> +    I = "Image"
> +
> +class Kernel(Panel):
> +
> +    match_files = ['Kbuild', 'Kconfig', 'MAINTAINERS', 'kernel/futex.c']
> +
> +    def __init__(self):
> +
> +        loadaddr = Edit("Load Addr", "0x800800")
> +        defconfig = Edit("defconfig", "omap2plus_defconfig")
> +        imgtype = RadioGroup("Image Format", ImgType, ImgType.BZ)
> +        cross = Edit("Cross compile", "arm-linux-gnueabihf-")
> +        k_version = Edit("Kernel version", "4.4")
> +
> +        grid_elements = [
> +            {"loadaddr":loadaddr, "defconfig":defconfig},
> +            {"imgtype":imgtype, "cross_compile":cross},
> +            {"k_version":k_version}
> +        ]
> +
> +        super().__init__(grid_elements)
> +
> +    @staticmethod
> +    def imgtype_to_install(imgtype):
> +        c = imgtype[0]
> +        if c == 'z':
> +            return "zinstall"
> +        if c == 'u':
> +            return "uinstall"
> +        return "install"
> +
> +    def debianize(self):
> +
> +        self.deb['imgtype_install'] = Kernel.imgtype_to_install(self.deb['imgtype'])
> +        self.tmpl_dir = os.path.join(mako_template_dir, 'debianize/kernel')
> +        pkg_name = self.deb['k_version'] + '-' + self.deb['p_name']
> +
> +        for tmpl in [
> +            'control',
> +            'rules',
> +            'preinst',
> +            'postinst',
> +            'prerm',
> +                'postrm']:
> +            with open(os.path.join('debian/', tmpl), 'w') as f:
> +                mako = os.path.join(self.tmpl_dir, tmpl + '.mako')
> +                f.write(template(mako, self.deb))
> +
> +        cmd = 'dch --package linux-' + pkg_name + \
> +            ' -v ' + self.deb['p_version'] + \
> +            ' --create -M -D ' + self.deb['release'] + \
> +            ' "generated by elbe debianize"'
> +        system(cmd)
> +
> +        copyfile(os.path.join(self.tmpl_dir, 'linux-image.install'),
> +                 'debian/linux-image-' + pkg_name + '.install')
> +        copyfile(os.path.join(self.tmpl_dir, 'linux-headers.install'),
> +                 'debian/linux-headers-' + pkg_name + '.install')
> +
> +        self.hint = "use 'dpkg-buildpackage -a%s' to build the package" % (
> +                self.deb['p_arch'])
> diff --git a/elbepack/debianize/panels/uboot.py b/elbepack/debianize/panels/uboot.py
> new file mode 100644
> index 00000000..eb8d6c05
> --- /dev/null
> +++ b/elbepack/debianize/panels/uboot.py
> @@ -0,0 +1,86 @@
> +# ELBE - Debian Based Embedded Rootfilesystem Builder
> +# Copyright (c) 2018 Philipp Rosenberger <p.rosenberger at linutronix.de>
> +# Copyright (c) 2018 Torben Hohn <torben.hohn at linutronix.de>
> +#
> +# SPDX-License-Identifier: GPL-3.0-or-later
> +
> +import os
> +
> +from time import sleep
> +from shutil import copyfile
> +
> +from pkg_resources import parse_version as V
> +
> +from elbepack.debianize.base.tui import TUI
> +from elbepack.debianize.panels.base import Panel
> +from elbepack.debianize.widgets.edit import Edit
> +
> +from elbepack.templates import template
> +from elbepack.directories import mako_template_dir
> +from elbepack.shellhelper import system
> +
> +
> +class UBoot(Panel):
> +
> +    copyright_fname = 'Licenses/README'
> +    match_files = ['Makefile', 'Kbuild', 'Kconfig', 'MAINTAINERS', 'config.mk']
> +
> +    def __init__(self):
> +
> +        defconfig = Edit("defconfig", "mx7dsabresd_defconfig")
> +        cross = Edit("Cross compile", "arm-linux-gnueabihf-")
> +        imgname = Edit("Image name", "u-boot-dtb.imx")
> +        k_version = Edit("U-Boot Version")
> +
> +        grid_elements = [
> +            {"defconfig": defconfig, "imgname": imgname},
> +            {"cross_compile": cross, "k_version": k_version},
> +        ]
> +
> +        super().__init__(grid_elements)
> +
> +        self.get_version()
> +        k_version.base_widget.set_edit_text(self.verstr)
> +
> +    def get_version(self):
> +        with open('Makefile', 'r') as f:
> +            for line in f:
> +                if line.startswith('VERSION = '):
> +                    version = line.split('=')[1].strip()
> +                elif line.startswith('PATCHLEVEL = '):
> +                    patchlevel = line.split('=')[1].strip()
> +                    break
> +
> +        self.verstr = version + '.' + patchlevel
> +        # With v2014.04 the u-boot Makefile knows the 'tools-only' target.
> +        if V(self.verstr) < V('2014.04'):
> +            TUI.printf("Only U-Boot >= 2014.04 is supported.\n"
> +                      "This is version '%s'" % self.verstr)
> +
> +        if V(self.verstr) >= V('2017.09'):
> +            self.deb['envtools'] = 'envtools'
> +        else:
> +            self.deb['envtools'] = 'env'
> +
> +    def debianize(self):
> +
> +        self.tmpl_dir = os.path.join(mako_template_dir, 'debianize/u-boot')
> +        pkg_name = self.deb['p_name'] + '-' + self.deb['k_version']
> +
> +        for tmpl in ['control', 'rules']:
> +            with open(os.path.join('debian/', tmpl), 'w') as f:
> +                mako = os.path.join(self.tmpl_dir, tmpl + '.mako')
> +                f.write(template(mako, self.deb))
> +
> +        cmd = 'dch --package u-boot-' + pkg_name + \
> +            ' -v ' + self.deb['p_version'] + \
> +            ' --create -M -D ' + self.deb['release'] + \
> +            ' "generated by elbe debianize"'
> +        system(cmd)
> +
> +        copyfile(os.path.join(self.tmpl_dir, 'u-boot-image.install'),
> +                 'debian/u-boot-image-' + pkg_name + '.install')
> +        copyfile(os.path.join(self.tmpl_dir, 'u-boot-tools.install'),
> +                 'debian/u-boot-tools-' + pkg_name + '.install')
> +
> +        TUI.printf("use 'dpkg-buildpackage -a%s' to build the package" % self.deb['p_arch'])
> 



More information about the elbe-devel mailing list