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