1*77db55fcSLaszlo Ersek# Makefile for the test helper UEFI applications that run in guests. 2*77db55fcSLaszlo Ersek# 3*77db55fcSLaszlo Ersek# Copyright (C) 2019, Red Hat, Inc. 4*77db55fcSLaszlo Ersek# 5*77db55fcSLaszlo Ersek# This program and the accompanying materials are licensed and made available 6*77db55fcSLaszlo Ersek# under the terms and conditions of the BSD License that accompanies this 7*77db55fcSLaszlo Ersek# distribution. The full text of the license may be found at 8*77db55fcSLaszlo Ersek# <http://opensource.org/licenses/bsd-license.php>. 9*77db55fcSLaszlo Ersek# 10*77db55fcSLaszlo Ersek# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT 11*77db55fcSLaszlo Ersek# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12*77db55fcSLaszlo Ersek 13*77db55fcSLaszlo Ersekedk2_dir := ../../roms/edk2 14*77db55fcSLaszlo Ersekimages_dir := ../data/uefi-boot-images 15*77db55fcSLaszlo Ersekemulation_targets := arm aarch64 i386 x86_64 16*77db55fcSLaszlo Ersekuefi_binaries := bios-tables-test 17*77db55fcSLaszlo Ersekintermediate_suffixes := .efi .fat .iso.raw 18*77db55fcSLaszlo Ersek 19*77db55fcSLaszlo Ersekimages: $(foreach binary,$(uefi_binaries), \ 20*77db55fcSLaszlo Ersek $(foreach target,$(emulation_targets), \ 21*77db55fcSLaszlo Ersek $(images_dir)/$(binary).$(target).iso.qcow2)) 22*77db55fcSLaszlo Ersek 23*77db55fcSLaszlo Ersek# Preserve all intermediate targets if the build succeeds. 24*77db55fcSLaszlo Ersek# - Intermediate targets help with development & debugging. 25*77db55fcSLaszlo Ersek# - Preserving intermediate targets also keeps spurious changes out of the 26*77db55fcSLaszlo Ersek# final build products, in case the user re-runs "make" without any changes 27*77db55fcSLaszlo Ersek# to the UEFI source code. Normally, the intermediate files would have been 28*77db55fcSLaszlo Ersek# removed by the last "make" invocation, hence the re-run would rebuild them 29*77db55fcSLaszlo Ersek# from the unchanged UEFI sources. Unfortunately, the "mkdosfs" and 30*77db55fcSLaszlo Ersek# "genisoimage" utilities embed timestamp-based information in their outputs, 31*77db55fcSLaszlo Ersek# which causes git to report differences for the tracked qcow2 ISO images. 32*77db55fcSLaszlo Ersek.SECONDARY: $(foreach binary,$(uefi_binaries), \ 33*77db55fcSLaszlo Ersek $(foreach target,$(emulation_targets), \ 34*77db55fcSLaszlo Ersek $(foreach suffix,$(intermediate_suffixes), \ 35*77db55fcSLaszlo Ersek Build/$(binary).$(target)$(suffix)))) 36*77db55fcSLaszlo Ersek 37*77db55fcSLaszlo Ersek# In the pattern rules below, the stem (%, $*) stands for 38*77db55fcSLaszlo Ersek# "$(binary).$(target)". 39*77db55fcSLaszlo Ersek 40*77db55fcSLaszlo Ersek# Convert the raw ISO image to a qcow2 one, enabling compression, and using a 41*77db55fcSLaszlo Ersek# small cluster size. This allows for small binary files under git control, 42*77db55fcSLaszlo Ersek# hence for small binary patches. 43*77db55fcSLaszlo Ersek$(images_dir)/%.iso.qcow2: Build/%.iso.raw 44*77db55fcSLaszlo Ersek mkdir -p -- $(images_dir) 45*77db55fcSLaszlo Ersek $${QTEST_QEMU_IMG:-qemu-img} convert -f raw -O qcow2 -c \ 46*77db55fcSLaszlo Ersek -o cluster_size=512 -- $< $@ 47*77db55fcSLaszlo Ersek 48*77db55fcSLaszlo Ersek# Embed the "UEFI system partition" into an ISO9660 file system as an ElTorito 49*77db55fcSLaszlo Ersek# boot image. 50*77db55fcSLaszlo ErsekBuild/%.iso.raw: Build/%.fat 51*77db55fcSLaszlo Ersek genisoimage -input-charset ASCII -efi-boot $(notdir $<) -no-emul-boot \ 52*77db55fcSLaszlo Ersek -quiet -o $@ -- $< 53*77db55fcSLaszlo Ersek 54*77db55fcSLaszlo Ersek# Define chained macros in order to map QEMU system emulation targets to 55*77db55fcSLaszlo Ersek# *short* UEFI architecture identifiers. Periods are allowed in, and ultimately 56*77db55fcSLaszlo Ersek# stripped from, the argument. 57*77db55fcSLaszlo Ersekmap_arm_to_uefi = $(subst arm,ARM,$(1)) 58*77db55fcSLaszlo Ersekmap_aarch64_to_uefi = $(subst aarch64,AA64,$(call map_arm_to_uefi,$(1))) 59*77db55fcSLaszlo Ersekmap_i386_to_uefi = $(subst i386,IA32,$(call map_aarch64_to_uefi,$(1))) 60*77db55fcSLaszlo Ersekmap_x86_64_to_uefi = $(subst x86_64,X64,$(call map_i386_to_uefi,$(1))) 61*77db55fcSLaszlo Ersekmap_to_uefi = $(subst .,,$(call map_x86_64_to_uefi,$(1))) 62*77db55fcSLaszlo Ersek 63*77db55fcSLaszlo Ersek# Format a "UEFI system partition", using the UEFI binary as the default boot 64*77db55fcSLaszlo Ersek# loader. Add 10% size for filesystem metadata, round up to the next KB, and 65*77db55fcSLaszlo Ersek# make sure the size is large enough for a FAT filesystem. Name the filesystem 66*77db55fcSLaszlo Ersek# after the UEFI binary. (Excess characters are automatically dropped from the 67*77db55fcSLaszlo Ersek# filesystem label.) 68*77db55fcSLaszlo ErsekBuild/%.fat: Build/%.efi 69*77db55fcSLaszlo Ersek rm -f -- $@ 70*77db55fcSLaszlo Ersek uefi_bin_b=$$(stat --format=%s -- $<) && \ 71*77db55fcSLaszlo Ersek uefi_fat_kb=$$(( (uefi_bin_b * 11 / 10 + 1023) / 1024 )) && \ 72*77db55fcSLaszlo Ersek uefi_fat_kb=$$(( uefi_fat_kb >= 64 ? uefi_fat_kb : 64 )) && \ 73*77db55fcSLaszlo Ersek mkdosfs -C $@ -n $(basename $(@F)) -- $$uefi_fat_kb 74*77db55fcSLaszlo Ersek MTOOLS_SKIP_CHECK=1 mmd -i $@ ::EFI 75*77db55fcSLaszlo Ersek MTOOLS_SKIP_CHECK=1 mmd -i $@ ::EFI/BOOT 76*77db55fcSLaszlo Ersek MTOOLS_SKIP_CHECK=1 mcopy -i $@ -- $< \ 77*77db55fcSLaszlo Ersek ::EFI/BOOT/BOOT$(call map_to_uefi,$(suffix $*)).EFI 78*77db55fcSLaszlo Ersek 79*77db55fcSLaszlo Ersek# In the pattern rules below, the stem (%, $*) stands for "$(target)" only. The 80*77db55fcSLaszlo Ersek# association between the UEFI binary (such as "bios-tables-test") and the 81*77db55fcSLaszlo Ersek# component name from the edk2 platform DSC file (such as "BiosTablesTest") is 82*77db55fcSLaszlo Ersek# explicit in each rule. 83*77db55fcSLaszlo Ersek 84*77db55fcSLaszlo Ersek# "build.sh" invokes the "build" utility of edk2 BaseTools. In any given edk2 85*77db55fcSLaszlo Ersek# workspace, at most one "build" instance may be operating at a time. Therefore 86*77db55fcSLaszlo Ersek# we must serialize the rebuilding of targets in this Makefile. 87*77db55fcSLaszlo Ersek.NOTPARALLEL: 88*77db55fcSLaszlo Ersek 89*77db55fcSLaszlo Ersek# In turn, the "build" utility of edk2 BaseTools invokes another "make". 90*77db55fcSLaszlo Ersek# Although the outer "make" process advertizes its job server to all child 91*77db55fcSLaszlo Ersek# processes via MAKEFLAGS in the environment, the outer "make" closes the job 92*77db55fcSLaszlo Ersek# server file descriptors (exposed in MAKEFLAGS) before executing a recipe -- 93*77db55fcSLaszlo Ersek# unless the recipe is recognized as a recursive "make" recipe. Recipes that 94*77db55fcSLaszlo Ersek# call $(MAKE) are classified automatically as recursive; for "build.sh" below, 95*77db55fcSLaszlo Ersek# we must mark the recipe manually as recursive, by using the "+" indicator. 96*77db55fcSLaszlo Ersek# This way, when the inner "make" starts a parallel build of the target edk2 97*77db55fcSLaszlo Ersek# module, it can communicate with the outer "make"'s job server. 98*77db55fcSLaszlo ErsekBuild/bios-tables-test.%.efi: build-edk2-tools 99*77db55fcSLaszlo Ersek +./build.sh $(edk2_dir) BiosTablesTest $* $@ 100*77db55fcSLaszlo Ersek 101*77db55fcSLaszlo Ersekbuild-edk2-tools: 102*77db55fcSLaszlo Ersek $(MAKE) -C $(edk2_dir)/BaseTools 103*77db55fcSLaszlo Ersek 104*77db55fcSLaszlo Ersekclean: 105*77db55fcSLaszlo Ersek rm -rf Build Conf log 106*77db55fcSLaszlo Ersek $(MAKE) -C $(edk2_dir)/BaseTools clean 107