Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | # uboot-extlinux-config.bbclass |
| 2 | # |
| 3 | # This class allow the extlinux.conf generation for U-Boot use. The |
| 4 | # U-Boot support for it is given to allow the Generic Distribution |
| 5 | # Configuration specification use by OpenEmbedded-based products. |
| 6 | # |
| 7 | # External variables: |
| 8 | # |
| 9 | # UBOOT_EXTLINUX_CONSOLE - Set to "console=ttyX" to change kernel boot |
| 10 | # default console. |
| 11 | # UBOOT_EXTLINUX_LABELS - A list of targets for the automatic config. |
| 12 | # UBOOT_EXTLINUX_KERNEL_ARGS - Add additional kernel arguments. |
| 13 | # UBOOT_EXTLINUX_KERNEL_IMAGE - Kernel image name. |
| 14 | # UBOOT_EXTLINUX_FDTDIR - Device tree directory. |
| 15 | # UBOOT_EXTLINUX_INITRD - Indicates a list of filesystem images to |
| 16 | # concatenate and use as an initrd (optional). |
| 17 | # UBOOT_EXTLINUX_MENU_DESCRIPTION - Name to use as description. |
| 18 | # UBOOT_EXTLINUX_ROOT - Root kernel cmdline. |
| 19 | # |
| 20 | # If there's only one label system will boot automatically and menu won't be |
| 21 | # created. If you want to use more than one labels, e.g linux and alternate, |
| 22 | # use overrides to set menu description, console and others variables. |
| 23 | # |
| 24 | # Ex: |
| 25 | # |
| 26 | # UBOOT_EXTLINUX_LABELS ??= "default fallback" |
| 27 | # |
| 28 | # UBOOT_EXTLINUX_KERNEL_IMAGE_default ??= "../zImage" |
| 29 | # UBOOT_EXTLINUX_MENU_DESCRIPTION_default ??= "Linux Default" |
| 30 | # |
| 31 | # UBOOT_EXTLINUX_KERNEL_IMAGE_fallback ??= "../zImage-fallback" |
| 32 | # UBOOT_EXTLINUX_MENU_DESCRIPTION_fallback ??= "Linux Fallback" |
| 33 | # |
| 34 | # Results: |
| 35 | # |
| 36 | # menu title Select the boot mode |
| 37 | # LABEL Linux Default |
| 38 | # KERNEL ../zImage |
| 39 | # FDTDIR ../ |
| 40 | # APPEND root=/dev/mmcblk2p2 rootwait rw console=${console} |
| 41 | # LABEL Linux Fallback |
| 42 | # KERNEL ../zImage-fallback |
| 43 | # FDTDIR ../ |
| 44 | # APPEND root=/dev/mmcblk2p2 rootwait rw console=${console} |
| 45 | # |
| 46 | # Copyright (C) 2016, O.S. Systems Software LTDA. All Rights Reserved |
| 47 | # Released under the MIT license (see packages/COPYING) |
| 48 | # |
| 49 | # The kernel has an internal default console, which you can override with |
| 50 | # a console=...some_tty... |
| 51 | UBOOT_EXTLINUX_CONSOLE ??= "console=${console}" |
| 52 | UBOOT_EXTLINUX_LABELS ??= "linux" |
| 53 | UBOOT_EXTLINUX_FDTDIR ??= "../" |
| 54 | UBOOT_EXTLINUX_KERNEL_IMAGE ??= "../${KERNEL_IMAGETYPE}" |
| 55 | UBOOT_EXTLINUX_KERNEL_ARGS ??= "rootwait rw" |
| 56 | UBOOT_EXTLINUX_MENU_DESCRIPTION_linux ??= "${DISTRO_NAME}" |
| 57 | |
| 58 | UBOOT_EXTLINUX_CONFIG = "${B}/extlinux.conf" |
| 59 | |
| 60 | python create_extlinux_config() { |
| 61 | if d.getVar("UBOOT_EXTLINUX", True) != "1": |
| 62 | return |
| 63 | |
| 64 | if not d.getVar('WORKDIR', True): |
| 65 | bb.error("WORKDIR not defined, unable to package") |
| 66 | |
| 67 | labels = d.getVar('UBOOT_EXTLINUX_LABELS', True) |
| 68 | if not labels: |
| 69 | bb.fatal("UBOOT_EXTLINUX_LABELS not defined, nothing to do") |
| 70 | |
| 71 | if not labels.strip(): |
| 72 | bb.fatal("No labels, nothing to do") |
| 73 | |
| 74 | cfile = d.getVar('UBOOT_EXTLINUX_CONFIG', True) |
| 75 | if not cfile: |
| 76 | bb.fatal('Unable to read UBOOT_EXTLINUX_CONFIG') |
| 77 | |
| 78 | try: |
| 79 | with open(cfile, 'w') as cfgfile: |
| 80 | cfgfile.write('# Generic Distro Configuration file generated by OpenEmbedded\n') |
| 81 | |
| 82 | if len(labels.split()) > 1: |
| 83 | cfgfile.write('menu title Select the boot mode\n') |
| 84 | |
| 85 | for label in labels.split(): |
| 86 | localdata = bb.data.createCopy(d) |
| 87 | |
| 88 | overrides = localdata.getVar('OVERRIDES', True) |
| 89 | if not overrides: |
| 90 | bb.fatal('OVERRIDES not defined') |
| 91 | |
| 92 | localdata.setVar('OVERRIDES', label + ':' + overrides) |
| 93 | bb.data.update_data(localdata) |
| 94 | |
| 95 | extlinux_console = localdata.getVar('UBOOT_EXTLINUX_CONSOLE', True) |
| 96 | |
| 97 | menu_description = localdata.getVar('UBOOT_EXTLINUX_MENU_DESCRIPTION', True) |
| 98 | if not menu_description: |
| 99 | menu_description = label |
| 100 | |
| 101 | root = localdata.getVar('UBOOT_EXTLINUX_ROOT', True) |
| 102 | if not root: |
| 103 | bb.fatal('UBOOT_EXTLINUX_ROOT not defined') |
| 104 | |
| 105 | kernel_image = localdata.getVar('UBOOT_EXTLINUX_KERNEL_IMAGE', True) |
| 106 | fdtdir = localdata.getVar('UBOOT_EXTLINUX_FDTDIR', True) |
| 107 | if fdtdir: |
| 108 | cfgfile.write('LABEL %s\n\tKERNEL %s\n\tFDTDIR %s\n' % |
| 109 | (menu_description, kernel_image, fdtdir)) |
| 110 | else: |
| 111 | cfgfile.write('LABEL %s\n\tKERNEL %s\n' % (menu_description, kernel_image)) |
| 112 | |
| 113 | kernel_args = localdata.getVar('UBOOT_EXTLINUX_KERNEL_ARGS', True) |
| 114 | |
| 115 | initrd = localdata.getVar('UBOOT_EXTLINUX_INITRD', True) |
| 116 | if initrd: |
| 117 | cfgfile.write('\tINITRD %s\n'% initrd) |
| 118 | |
| 119 | kernel_args = root + " " + kernel_args |
| 120 | cfgfile.write('\tAPPEND %s %s\n' % (kernel_args, extlinux_console)) |
| 121 | |
| 122 | except OSError: |
| 123 | bb.fatal('Unable to open %s' % (cfile)) |
| 124 | } |
| 125 | |
| 126 | do_install[prefuncs] += "create_extlinux_config" |