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. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 15 | # UBOOT_EXTLINUX_FDT - Device tree file. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 16 | # UBOOT_EXTLINUX_INITRD - Indicates a list of filesystem images to |
| 17 | # concatenate and use as an initrd (optional). |
| 18 | # UBOOT_EXTLINUX_MENU_DESCRIPTION - Name to use as description. |
| 19 | # UBOOT_EXTLINUX_ROOT - Root kernel cmdline. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 20 | # UBOOT_EXTLINUX_TIMEOUT - Timeout before DEFAULT selection is made. |
| 21 | # Measured in 1/10 of a second. |
| 22 | # UBOOT_EXTLINUX_DEFAULT_LABEL - Target to be selected by default after |
| 23 | # the timeout period |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 24 | # |
| 25 | # If there's only one label system will boot automatically and menu won't be |
| 26 | # created. If you want to use more than one labels, e.g linux and alternate, |
| 27 | # use overrides to set menu description, console and others variables. |
| 28 | # |
| 29 | # Ex: |
| 30 | # |
| 31 | # UBOOT_EXTLINUX_LABELS ??= "default fallback" |
| 32 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 33 | # UBOOT_EXTLINUX_DEFAULT_LABEL ??= "Linux Default" |
| 34 | # UBOOT_EXTLINUX_TIMEOUT ??= "30" |
| 35 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 36 | # UBOOT_EXTLINUX_KERNEL_IMAGE_default ??= "../zImage" |
| 37 | # UBOOT_EXTLINUX_MENU_DESCRIPTION_default ??= "Linux Default" |
| 38 | # |
| 39 | # UBOOT_EXTLINUX_KERNEL_IMAGE_fallback ??= "../zImage-fallback" |
| 40 | # UBOOT_EXTLINUX_MENU_DESCRIPTION_fallback ??= "Linux Fallback" |
| 41 | # |
| 42 | # Results: |
| 43 | # |
| 44 | # menu title Select the boot mode |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 45 | # TIMEOUT 30 |
| 46 | # DEFAULT Linux Default |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 47 | # LABEL Linux Default |
| 48 | # KERNEL ../zImage |
| 49 | # FDTDIR ../ |
| 50 | # APPEND root=/dev/mmcblk2p2 rootwait rw console=${console} |
| 51 | # LABEL Linux Fallback |
| 52 | # KERNEL ../zImage-fallback |
| 53 | # FDTDIR ../ |
| 54 | # APPEND root=/dev/mmcblk2p2 rootwait rw console=${console} |
| 55 | # |
| 56 | # Copyright (C) 2016, O.S. Systems Software LTDA. All Rights Reserved |
| 57 | # Released under the MIT license (see packages/COPYING) |
| 58 | # |
| 59 | # The kernel has an internal default console, which you can override with |
| 60 | # a console=...some_tty... |
| 61 | UBOOT_EXTLINUX_CONSOLE ??= "console=${console}" |
| 62 | UBOOT_EXTLINUX_LABELS ??= "linux" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 63 | UBOOT_EXTLINUX_FDT ??= "" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 64 | UBOOT_EXTLINUX_FDTDIR ??= "../" |
| 65 | UBOOT_EXTLINUX_KERNEL_IMAGE ??= "../${KERNEL_IMAGETYPE}" |
| 66 | UBOOT_EXTLINUX_KERNEL_ARGS ??= "rootwait rw" |
| 67 | UBOOT_EXTLINUX_MENU_DESCRIPTION_linux ??= "${DISTRO_NAME}" |
| 68 | |
| 69 | UBOOT_EXTLINUX_CONFIG = "${B}/extlinux.conf" |
| 70 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 71 | python do_create_extlinux_config() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 72 | if d.getVar("UBOOT_EXTLINUX") != "1": |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 73 | return |
| 74 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 75 | if not d.getVar('WORKDIR'): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 76 | bb.error("WORKDIR not defined, unable to package") |
| 77 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 78 | labels = d.getVar('UBOOT_EXTLINUX_LABELS') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 79 | if not labels: |
| 80 | bb.fatal("UBOOT_EXTLINUX_LABELS not defined, nothing to do") |
| 81 | |
| 82 | if not labels.strip(): |
| 83 | bb.fatal("No labels, nothing to do") |
| 84 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 85 | cfile = d.getVar('UBOOT_EXTLINUX_CONFIG') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 86 | if not cfile: |
| 87 | bb.fatal('Unable to read UBOOT_EXTLINUX_CONFIG') |
| 88 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 89 | localdata = bb.data.createCopy(d) |
| 90 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 91 | try: |
| 92 | with open(cfile, 'w') as cfgfile: |
| 93 | cfgfile.write('# Generic Distro Configuration file generated by OpenEmbedded\n') |
| 94 | |
| 95 | if len(labels.split()) > 1: |
| 96 | cfgfile.write('menu title Select the boot mode\n') |
| 97 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 98 | timeout = localdata.getVar('UBOOT_EXTLINUX_TIMEOUT') |
| 99 | if timeout: |
| 100 | cfgfile.write('TIMEOUT %s\n' % (timeout)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 101 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 102 | if len(labels.split()) > 1: |
| 103 | default = localdata.getVar('UBOOT_EXTLINUX_DEFAULT_LABEL') |
| 104 | if default: |
| 105 | cfgfile.write('DEFAULT %s\n' % (default)) |
| 106 | |
| 107 | for label in labels.split(): |
| 108 | |
| 109 | overrides = localdata.getVar('OVERRIDES') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 110 | if not overrides: |
| 111 | bb.fatal('OVERRIDES not defined') |
| 112 | |
| 113 | localdata.setVar('OVERRIDES', label + ':' + overrides) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 114 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 115 | extlinux_console = localdata.getVar('UBOOT_EXTLINUX_CONSOLE') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 116 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 117 | menu_description = localdata.getVar('UBOOT_EXTLINUX_MENU_DESCRIPTION') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 118 | if not menu_description: |
| 119 | menu_description = label |
| 120 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 121 | root = localdata.getVar('UBOOT_EXTLINUX_ROOT') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 122 | if not root: |
| 123 | bb.fatal('UBOOT_EXTLINUX_ROOT not defined') |
| 124 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 125 | kernel_image = localdata.getVar('UBOOT_EXTLINUX_KERNEL_IMAGE') |
| 126 | fdtdir = localdata.getVar('UBOOT_EXTLINUX_FDTDIR') |
| 127 | |
| 128 | fdt = localdata.getVar('UBOOT_EXTLINUX_FDT') |
| 129 | |
| 130 | if fdt: |
| 131 | cfgfile.write('LABEL %s\n\tKERNEL %s\n\tFDT %s\n' % |
| 132 | (menu_description, kernel_image, fdt)) |
| 133 | elif fdtdir: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 134 | cfgfile.write('LABEL %s\n\tKERNEL %s\n\tFDTDIR %s\n' % |
| 135 | (menu_description, kernel_image, fdtdir)) |
| 136 | else: |
| 137 | cfgfile.write('LABEL %s\n\tKERNEL %s\n' % (menu_description, kernel_image)) |
| 138 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 139 | kernel_args = localdata.getVar('UBOOT_EXTLINUX_KERNEL_ARGS') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 140 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 141 | initrd = localdata.getVar('UBOOT_EXTLINUX_INITRD') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 142 | if initrd: |
| 143 | cfgfile.write('\tINITRD %s\n'% initrd) |
| 144 | |
| 145 | kernel_args = root + " " + kernel_args |
| 146 | cfgfile.write('\tAPPEND %s %s\n' % (kernel_args, extlinux_console)) |
| 147 | |
| 148 | except OSError: |
| 149 | bb.fatal('Unable to open %s' % (cfile)) |
| 150 | } |
| 151 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 152 | addtask create_extlinux_config before do_install do_deploy after do_compile |