summaryrefslogtreecommitdiffstats
path: root/classes/bootspec.bbclass
blob: 67a5a8f54b1fcd210da2bca934ff32dfd864200d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Adds boot spec entry for first FSTYPE found
inherit linux-kernel-base

KERNEL_VERSION = "${@get_kernelversion_file("${STAGING_KERNEL_BUILDDIR}")}"

BOOTSPEC_TITLE ?= "${SUMMARY}"
BOOTSPEC_TITLE[doc] = "Content of the boot spec entry 'title' line"

BOOTSPEC_OPTIONS_ext4 = "rootfstype=ext4 rootwait"
BOOTSPEC_OPTIONS_ubi = "rootfstype=ubifs"
BOOTSPEC_OPTIONS_squashfs = "rootfstype=squashfs"
BOOTSPEC_OPTIONS_squashfs-lzo = "rootfstype=squashfs"
BOOTSPEC_OPTIONS_squashfs-xz = "rootfstype=squashfs"

BOOTSPEC_VERSION ?= "${KERNEL_VERSION}"
BOOTSPEC_VERSION[doc] ?= "Content of the bootspec version entry"

BOOTSPEC_OPTIONS_DEFAULT = ""

python () {
    option = ""

    for type in (d.getVar('IMAGE_FSTYPES', True) or "").split():
        option = d.getVar('BOOTSPEC_OPTIONS_%s' % type, True)
        if option:
            d.setVar('BOOTSPEC_OPTIONS_DEFAULT', option)
            break;
}

BOOTSPEC_OPTIONS ?= "${BOOTSPEC_OPTIONS_DEFAULT}"
BOOTSPEC_OPTIONS[doc] = "Content of the boot spec entry 'options' line"

BOOTSPEC_EXTRALINE ?= ""
BOOTSPEC_OPTIONS[doc] = "Allows to add extra content to bootspec entries, lines must be terminated with a newline"

python create_bootspec() {
    dtb = d.getVar('KERNEL_DEVICETREE', True).replace('.dtb', '').split()
    bb.utils.mkdirhier(d.expand("${IMAGE_ROOTFS}/loader/entries/"))

    for x in dtb:
        bb.note("Creating boot spec entry /loader/entries/" + x + ".conf ...")

        try:
            bootspecfile = open(d.expand("${IMAGE_ROOTFS}/loader/entries/" + x + ".conf"), 'w')
        except OSError:
            raise bb.build.FuncFailed('Unable to open boot spec file for writing')

        bootspecfile.write('title      %s\n' % d.getVar('BOOTSPEC_TITLE', True))
        bootspecfile.write('version    %s\n' % d.getVar('BOOTSPEC_VERSION', True))
        bootspecfile.write('options    %s\n' % d.expand('${BOOTSPEC_OPTIONS}'))
        bootspecfile.write(d.getVar('BOOTSPEC_EXTRALINE', True).replace(r'\n', '\n'))
        bootspecfile.write('linux      %s\n' % d.expand('/boot/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}'))
        bootspecfile.write('devicetree %s\n' % d.expand('/boot/devicetree-${KERNEL_IMAGETYPE}-' + x + '.dtb\n'))

        bootspecfile.close()
}

ROOTFS_POSTPROCESS_COMMAND += " create_bootspec; "

IMAGE_INSTALL_append = " kernel-image kernel-devicetree"