<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">Hi Ulf,<br><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">Thanks for review. <br><br>I agree and I&#39;ll change code and use bb.fatal() instead of FuncFailed and send a v2.<br><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">Fabio<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 30, 2016 at 8:07 PM, Ulf Magnusson <span dir="ltr">&lt;<a href="mailto:ulfalizer@gmail.com" target="_blank">ulfalizer@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Sat, Oct 1, 2016 at 12:54 AM, Ulf Magnusson &lt;<a href="mailto:ulfalizer@gmail.com">ulfalizer@gmail.com</a>&gt; wrote:<br>
&gt; On Fri, Sep 30, 2016 at 10:33 PM, Fabio Berton<br>
&gt; &lt;<a href="mailto:fabio.berton@ossystems.com.br">fabio.berton@ossystems.com.br</a><wbr>&gt; wrote:<br>
&gt;&gt; This class allow the extlinux.conf generation for U-Boot use.<br>
&gt;&gt; The U-Boot support for it is given to allow the Generic Distribution<br>
&gt;&gt; Configuration specification use by OpenEmbedded-based products.<br>
&gt;&gt;<br>
&gt;&gt; This class can be inherited by u-boot recipes to create extlinux.conf<br>
&gt;&gt; and boot using menu options.<br>
&gt;&gt;<br>
&gt;&gt; U-boot with extlinux support is machine dependent, so to use this class<br>
&gt;&gt; you need to set UBOOT_EXTLINUX to 1 in machine configuration file and<br>
&gt;&gt; also set root= kernel cmdline UBOOT_EXTLINUX_ROOT. This variable is used<br>
&gt;&gt; to pass root kernel cmdline, e.g:<br>
&gt;&gt;<br>
&gt;&gt; UBOOT_EXTLINUX_ROOT = &quot;root=/dev/mmcblk2p2&quot;<br>
&gt;&gt;<br>
&gt;&gt; Signed-off-by: Fabio Berton &lt;<a href="mailto:fabio.berton@ossystems.com.br">fabio.berton@ossystems.com.br</a><wbr>&gt;<br>
&gt;&gt; Signed-off-by: Otavio Salvador &lt;<a href="mailto:otavio@ossystems.com.br">otavio@ossystems.com.br</a>&gt;<br>
&gt;&gt; ---<br>
&gt;&gt;  meta/classes/uboot-extlinux-<wbr>config.bbclass | 130 +++++++++++++++++++++++++++++<br>
&gt;&gt;  1 file changed, 130 insertions(+)<br>
&gt;&gt;  create mode 100644 meta/classes/uboot-extlinux-<wbr>config.bbclass<br>
&gt;&gt;<br>
&gt;&gt; diff --git a/meta/classes/uboot-extlinux-<wbr>config.bbclass b/meta/classes/uboot-extlinux-<wbr>config.bbclass<br>
&gt;&gt; new file mode 100644<br>
&gt;&gt; index 0000000..3480dd6<br>
&gt;&gt; --- /dev/null<br>
&gt;&gt; +++ b/meta/classes/uboot-extlinux-<wbr>config.bbclass<br>
&gt;&gt; @@ -0,0 +1,130 @@<br>
&gt;&gt; +# uboot-extlinux-config.bbclass<br>
&gt;&gt; +#<br>
&gt;&gt; +# This class allow the extlinux.conf generation for U-Boot use. The<br>
&gt;&gt; +# U-Boot support for it is given to allow the Generic Distribution<br>
&gt;&gt; +# Configuration specification use by OpenEmbedded-based products.<br>
&gt;&gt; +#<br>
&gt;&gt; +# External variables:<br>
&gt;&gt; +#<br>
&gt;&gt; +# UBOOT_EXTLINUX_CONFIG            - Configuration file default set to source dir.<br>
&gt;&gt; +# UBOOT_EXTLINUX_CONSOLE           - Set to &quot;console=ttyX&quot; to change kernel boot<br>
&gt;&gt; +#                                    default console.<br>
&gt;&gt; +# UBOOT_EXTLINUX_LABELS            - A list of targets for the automatic config.<br>
&gt;&gt; +# UBOOT_EXTLINUX_KERNEL_ARGS       - Add additional kernel arguments.<br>
&gt;&gt; +# UBOOT_EXTLINUX_KERNEL_IMAGE      - Kernel image name.<br>
&gt;&gt; +# UBOOT_EXTLINUX_FDTDIR            - Device tree directory.<br>
&gt;&gt; +# UBOOT_EXTLINUX_INITRD            - Indicates a list of filesystem images to<br>
&gt;&gt; +#                                    concatenate and use as an initrd (optional).<br>
&gt;&gt; +# UBOOT_EXTLINUX_MENU_<wbr>DESCRIPTION  - Name to use as description.<br>
&gt;&gt; +# UBOOT_EXTLINUX_ROOT              - Root kernel cmdline.<br>
&gt;&gt; +#<br>
&gt;&gt; +# If there&#39;s only one label system will boot automatically and menu won&#39;t be<br>
&gt;&gt; +# created. If you want to use more than one labels, e.g linux and alternate,<br>
&gt;&gt; +# use overrides to set menu description, console and others variables.<br>
&gt;&gt; +#<br>
&gt;&gt; +# Ex:<br>
&gt;&gt; +#<br>
&gt;&gt; +# UBOOT_EXTLINUX_LABELS ??= &quot;default fallback&quot;<br>
&gt;&gt; +#<br>
&gt;&gt; +# UBOOT_EXTLINUX_KERNEL_IMAGE_<wbr>default ??= &quot;../zImage&quot;<br>
&gt;&gt; +# UBOOT_EXTLINUX_MENU_<wbr>DESCRIPTION_default ??= &quot;Linux Default&quot;<br>
&gt;&gt; +#<br>
&gt;&gt; +# UBOOT_EXTLINUX_KERNEL_IMAGE_<wbr>fallback ??= &quot;../zImage-fallback&quot;<br>
&gt;&gt; +# UBOOT_EXTLINUX_MENU_<wbr>DESCRIPTION_fallback ??= &quot;Linux Fallback&quot;<br>
&gt;&gt; +#<br>
&gt;&gt; +# Results:<br>
&gt;&gt; +#<br>
&gt;&gt; +# menu title Select the boot mode<br>
&gt;&gt; +# LABEL Linux Default<br>
&gt;&gt; +#   KERNEL ../zImage<br>
&gt;&gt; +#   FDTDIR ../<br>
&gt;&gt; +#   APPEND root=/dev/mmcblk2p2 rootwait rw console=${console}<br>
&gt;&gt; +# LABEL Linux Fallback<br>
&gt;&gt; +#   KERNEL ../zImage-fallback<br>
&gt;&gt; +#   FDTDIR ../<br>
&gt;&gt; +#   APPEND root=/dev/mmcblk2p2 rootwait rw console=${console}<br>
&gt;&gt; +#<br>
&gt;&gt; +# Copyright (C) 2016, O.S. Systems Software LTDA.  All Rights Reserved<br>
&gt;&gt; +# Released under the MIT license (see packages/COPYING)<br>
&gt;&gt; +#<br>
&gt;&gt; +# The kernel has an internal default console, which you can override with<br>
&gt;&gt; +# a console=...some_tty...<br>
&gt;&gt; +UBOOT_EXTLINUX_CONSOLE ??= &quot;console=${console}&quot;<br>
&gt;&gt; +UBOOT_EXTLINUX_CONFIG ??= &quot;${S}/extlinux.conf&quot;<br>
&gt;&gt; +UBOOT_EXTLINUX_LABELS ??= &quot;linux&quot;<br>
&gt;&gt; +UBOOT_EXTLINUX_FDTDIR ??= &quot;../&quot;<br>
&gt;&gt; +UBOOT_EXTLINUX_KERNEL_IMAGE ??= &quot;../${KERNEL_IMAGETYPE}&quot;<br>
&gt;&gt; +UBOOT_EXTLINUX_KERNEL_ARGS ??= &quot;rootwait rw&quot;<br>
&gt;&gt; +UBOOT_EXTLINUX_MENU_<wbr>DESCRIPTION_linux ??= &quot;${DISTRO_NAME}&quot;<br>
&gt;&gt; +<br>
&gt;&gt; +python create_extlinux_config() {<br>
&gt;&gt; +    if d.getVar(&quot;UBOOT_EXTLINUX&quot;, False) == &quot;1&quot;:<br>
&gt;&gt; +        workdir = d.getVar(&#39;WORKDIR&#39;, True)<br>
&gt;&gt; +        if not workdir:<br>
&gt;&gt; +            bb.error(&quot;WORKDIR not defined, unable to package&quot;)<br>
&gt;&gt; +            return<br>
&gt;&gt; +<br>
&gt;&gt; +        labels = d.getVar(&#39;UBOOT_EXTLINUX_<wbr>LABELS&#39;, True)<br>
&gt;&gt; +        if not labels:<br>
&gt;&gt; +            bb.debug(1, &quot;UBOOT_EXTLINUX_LABELS not defined, nothing to do&quot;)<br>
&gt;&gt; +            return<br>
&gt;&gt; +<br>
&gt;&gt; +        if labels == []:<br>
&gt;&gt; +            bb.debug(1, &quot;No labels, nothing to do&quot;)<br>
&gt;&gt; +            return<br>
&gt;&gt; +<br>
&gt;&gt; +        cfile = d.getVar(&#39;UBOOT_EXTLINUX_<wbr>CONFIG&#39;, True)<br>
&gt;&gt; +        if not cfile:<br>
&gt;&gt; +            raise bb.build.FuncFailed(&#39;Unable to read UBOOT_EXTLINUX_CONFIG&#39;)<br>
&gt;&gt; +<br>
&gt;&gt; +        try:<br>
&gt;&gt; +            cfgfile = open(cfile, &#39;w&#39;)<br>
&gt;&gt; +        except OSError:<br>
&gt;&gt; +            raise bb.build.FuncFailed(&#39;Unable to open %s&#39; % (cfile))<br>
&gt;&gt; +<br>
&gt;&gt; +        cfgfile.write(&#39;# Generic Distro Configuration file generated by OpenEmbedded\n&#39;)<br>
&gt;&gt; +<br>
&gt;&gt; +        if len(labels.split()) &gt; 1:<br>
&gt;&gt; +            cfgfile.write(&#39;menu title Select the boot mode\n&#39;)<br>
&gt;&gt; +<br>
&gt;&gt; +        for label in labels.split():<br>
&gt;&gt; +            localdata = bb.data.createCopy(d)<br>
&gt;&gt; +<br>
&gt;&gt; +            overrides = localdata.getVar(&#39;OVERRIDES&#39;, True)<br>
&gt;&gt; +            if not overrides:<br>
&gt;&gt; +                raise bb.build.FuncFailed(&#39;OVERRIDES not defined&#39;)<br>
&gt;&gt; +<br>
&gt;&gt; +            localdata.setVar(&#39;OVERRIDES&#39;, label + &#39;:&#39; + overrides)<br>
&gt;&gt; +            bb.data.update_data(localdata)<br>
&gt;&gt; +<br>
&gt;&gt; +            extlinux_console = localdata.getVar(&#39;UBOOT_<wbr>EXTLINUX_CONSOLE&#39;, True)<br>
&gt;&gt; +<br>
&gt;&gt; +            menu_description = localdata.getVar(&#39;UBOOT_<wbr>EXTLINUX_MENU_DESCRIPTION&#39;, True)<br>
&gt;&gt; +            if not menu_description:<br>
&gt;&gt; +                menu_description = label<br>
&gt;&gt; +<br>
&gt;&gt; +            root = localdata.getVar(&#39;UBOOT_<wbr>EXTLINUX_ROOT&#39;, True)<br>
&gt;&gt; +            if not root:<br>
&gt;&gt; +                raise bb.build.FuncFailed(&#39;UBOOT_<wbr>EXTLINUX_ROOT not defined&#39;)<br>
&gt;&gt; +<br>
&gt;&gt; +            kernel_image = localdata.getVar(&#39;UBOOT_<wbr>EXTLINUX_KERNEL_IMAGE&#39;, True)<br>
&gt;&gt; +            fdtdir = localdata.getVar(&#39;UBOOT_<wbr>EXTLINUX_FDTDIR&#39;, True)<br>
&gt;&gt; +            if fdtdir:<br>
&gt;&gt; +                cfgfile.write(&#39;LABEL %s\n\tKERNEL %s\n\tFDTDIR %s\n&#39; %<br>
&gt;&gt; +                             (menu_description, kernel_image, fdtdir))<br>
&gt;&gt; +            else:<br>
&gt;&gt; +                cfgfile.write(&#39;LABEL %s\n\tKERNEL %s\n&#39; % (menu_description, kernel_image))<br>
&gt;&gt; +<br>
&gt;&gt; +            kernel_args = localdata.getVar(&#39;UBOOT_<wbr>EXTLINUX_KERNEL_ARGS&#39;, True)<br>
&gt;&gt; +<br>
&gt;&gt; +            initrd = localdata.getVar(&#39;UBOOT_<wbr>EXTLINUX_INITRD&#39;, True)<br>
&gt;&gt; +            if initrd:<br>
&gt;&gt; +                cfgfile.write(&#39;\tINITRD %s\n&#39;% initrd)<br>
&gt;&gt; +<br>
&gt;&gt; +            kernel_args = root + &quot; &quot; + kernel_args<br>
&gt;&gt; +            cfgfile.write(&#39;\tAPPEND %s %s\n&#39; % (kernel_args, extlinux_console))<br>
&gt;&gt; +<br>
&gt;&gt; +        cfgfile.close()<br>
&gt;&gt; +}<br>
&gt;&gt; +<br>
&gt;&gt; +do_install[prefuncs] += &quot;create_extlinux_config&quot;<br>
&gt;&gt; --<br>
&gt;&gt; 2.1.4<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;<br>
&gt; Out of personal curiosity, when would &#39;raise bb.build.FuncFailed(msg)&#39;<br>
&gt; be preferred over bb.fatal(msg)?<br>
&gt;<br>
&gt; Looking at the FuncFailed() constructor, it seems the argument was<br>
&gt; originally meant to be the name of the function, though no one seems<br>
&gt; to use it like that. It&#39;s still called &#39;name&#39;.<br>
<br>
</div></div>Looks like bitbake/lib/bb/build.py raises a FuncFailed with the<br>
function name. That one&#39;s raised as a side effect of calling<br>
bb.fatal() too, after bb.fatal() logs the message and raises<br>
BBHandledException.<br>
<br>
Got the following on IRC, so seems bb.fatal() might be more appropriate:<br>
<br>
&lt; kergoth&gt; the *original* intent was for the function/task to error<br>
via whatever appropriate means, bb.fatal, whatever, and funcfailed was<br>
what you&#39;d catch if you were calling exec_func/exec_task. that is,<br>
it&#39;s what those functions raise, not what metadata functions should be<br>
raising<br>
&lt; kergoth&gt; it didn&#39;t end up being used that way<br>
&lt; kergoth&gt; but there&#39;s really never a reason to raise it yourself<br>
<br>
Cheers,<br>
Ulf<br>
</blockquote></div><br></div>