xref: /OK3568_Linux_fs/yocto/poky/meta/recipes-bsp/grub/grub-efi_2.06.bb (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1require grub2.inc
2
3require conf/image-uefi.conf
4
5GRUBPLATFORM = "efi"
6
7DEPENDS:append = " grub-native"
8RDEPENDS:${PN} = "grub-common virtual-grub-bootconf"
9
10SRC_URI += " \
11           file://cfg \
12          "
13
14S = "${WORKDIR}/grub-${PV}"
15
16# Determine the target arch for the grub modules
17python __anonymous () {
18    import re
19    target = d.getVar('TARGET_ARCH')
20    prefix = "" if d.getVar('EFI_PROVIDER') == "grub-efi" else "grub-efi-"
21    if target == "x86_64":
22        grubtarget = 'x86_64'
23    elif re.match('i.86', target):
24        grubtarget = 'i386'
25    elif re.match('aarch64', target):
26        grubtarget = 'arm64'
27    elif re.match('arm', target):
28        grubtarget = 'arm'
29    elif re.match('riscv64', target):
30        grubtarget = 'riscv64'
31    elif re.match('riscv32', target):
32        grubtarget = 'riscv32'
33    else:
34        raise bb.parse.SkipRecipe("grub-efi is incompatible with target %s" % target)
35    grubimage = prefix + d.getVar("EFI_BOOT_IMAGE")
36    d.setVar("GRUB_TARGET", grubtarget)
37    d.setVar("GRUB_IMAGE", grubimage)
38    prefix = "grub-efi-" if prefix == "" else ""
39    d.setVar("GRUB_IMAGE_PREFIX", prefix)
40}
41
42inherit deploy
43
44CACHED_CONFIGUREVARS += "ac_cv_path_HELP2MAN="
45EXTRA_OECONF += "--enable-efiemu=no"
46
47do_mkimage() {
48	cd ${B}
49
50	GRUB_MKIMAGE_MODULES="${GRUB_BUILDIN}"
51
52	# If 'all' is included in GRUB_BUILDIN we will include all available grub2 modules
53	if [ "${@ bb.utils.contains('GRUB_BUILDIN', 'all', 'True', 'False', d)}" = "True" ]; then
54		bbdebug 1 "Including all available modules"
55		# Get the list of all .mod files in grub-core build directory
56		GRUB_MKIMAGE_MODULES=$(find ${B}/grub-core/ -type f -name "*.mod" -exec basename {} .mod \;)
57	fi
58
59	# Search for the grub.cfg on the local boot media by using the
60	# built in cfg file provided via this recipe
61	grub-mkimage -v -c ../cfg -p ${EFIDIR} -d ./grub-core/ \
62	               -O ${GRUB_TARGET}-efi -o ./${GRUB_IMAGE_PREFIX}${GRUB_IMAGE} \
63	               ${GRUB_MKIMAGE_MODULES}
64}
65
66addtask mkimage before do_install after do_compile
67
68do_install() {
69    oe_runmake 'DESTDIR=${D}' -C grub-core install
70
71    # Remove build host references...
72    find "${D}" -name modinfo.sh -type f -exec \
73        sed -i \
74        -e 's,--sysroot=${STAGING_DIR_TARGET},,g' \
75        -e 's|${DEBUG_PREFIX_MAP}||g' \
76        -e 's:${RECIPE_SYSROOT_NATIVE}::g' \
77        {} +
78
79    install -d ${D}${EFI_FILES_PATH}
80    install -m 644 ${B}/${GRUB_IMAGE_PREFIX}${GRUB_IMAGE} ${D}${EFI_FILES_PATH}/${GRUB_IMAGE}
81}
82
83# To include all available modules, add 'all' to GRUB_BUILDIN
84GRUB_BUILDIN ?= "boot linux ext2 fat serial part_msdos part_gpt normal \
85                 efi_gop iso9660 configfile search loadenv test"
86
87# 'xen_boot' is a module valid only for aarch64
88GRUB_BUILDIN:append:aarch64 = "${@bb.utils.contains('DISTRO_FEATURES', 'xen', ' xen_boot', '', d)}"
89
90do_deploy() {
91	install -m 644 ${B}/${GRUB_IMAGE_PREFIX}${GRUB_IMAGE} ${DEPLOYDIR}
92}
93
94addtask deploy after do_install before do_build
95
96FILES:${PN} = "${libdir}/grub/${GRUB_TARGET}-efi \
97               ${datadir}/grub \
98               ${EFI_FILES_PATH}/${GRUB_IMAGE} \
99               "
100
101# 64-bit binaries are expected for the bootloader with an x32 userland
102INSANE_SKIP:${PN}:append:linux-gnux32 = " arch"
103INSANE_SKIP:${PN}-dbg:append:linux-gnux32 = " arch"
104INSANE_SKIP:${PN}:append:linux-muslx32 = " arch"
105INSANE_SKIP:${PN}-dbg:append:linux-muslx32 = " arch"
106