xref: /openbmc/qemu/tests/uefi-test-tools/Makefile (revision ad8560fa)
177db55fcSLaszlo Ersek# Makefile for the test helper UEFI applications that run in guests.
277db55fcSLaszlo Ersek#
377db55fcSLaszlo Ersek# Copyright (C) 2019, Red Hat, Inc.
477db55fcSLaszlo Ersek#
577db55fcSLaszlo Ersek# This program and the accompanying materials are licensed and made available
677db55fcSLaszlo Ersek# under the terms and conditions of the BSD License that accompanies this
777db55fcSLaszlo Ersek# distribution. The full text of the license may be found at
877db55fcSLaszlo Ersek# <http://opensource.org/licenses/bsd-license.php>.
977db55fcSLaszlo Ersek#
1077db55fcSLaszlo Ersek# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
1177db55fcSLaszlo Ersek# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
1277db55fcSLaszlo Ersek
1377db55fcSLaszlo Ersekedk2_dir              := ../../roms/edk2
1477db55fcSLaszlo Ersekimages_dir            := ../data/uefi-boot-images
15*ad8560faSSunil V Lemulation_targets     := arm aarch64 i386 x86_64 riscv64
1677db55fcSLaszlo Ersekuefi_binaries         := bios-tables-test
1777db55fcSLaszlo Ersekintermediate_suffixes := .efi .fat .iso.raw
1877db55fcSLaszlo Ersek
1977db55fcSLaszlo Ersekimages: $(foreach binary,$(uefi_binaries), \
2077db55fcSLaszlo Ersek		$(foreach target,$(emulation_targets), \
2177db55fcSLaszlo Ersek			$(images_dir)/$(binary).$(target).iso.qcow2))
2277db55fcSLaszlo Ersek
2377db55fcSLaszlo Ersek# Preserve all intermediate targets if the build succeeds.
2477db55fcSLaszlo Ersek# - Intermediate targets help with development & debugging.
2577db55fcSLaszlo Ersek# - Preserving intermediate targets also keeps spurious changes out of the
2677db55fcSLaszlo Ersek#   final build products, in case the user re-runs "make" without any changes
2777db55fcSLaszlo Ersek#   to the UEFI source code. Normally, the intermediate files would have been
2877db55fcSLaszlo Ersek#   removed by the last "make" invocation, hence the re-run would rebuild them
2977db55fcSLaszlo Ersek#   from the unchanged UEFI sources. Unfortunately, the "mkdosfs" and
3077db55fcSLaszlo Ersek#   "genisoimage" utilities embed timestamp-based information in their outputs,
3177db55fcSLaszlo Ersek#   which causes git to report differences for the tracked qcow2 ISO images.
3277db55fcSLaszlo Ersek.SECONDARY: $(foreach binary,$(uefi_binaries), \
3377db55fcSLaszlo Ersek		$(foreach target,$(emulation_targets), \
3477db55fcSLaszlo Ersek			$(foreach suffix,$(intermediate_suffixes), \
3577db55fcSLaszlo Ersek				Build/$(binary).$(target)$(suffix))))
3677db55fcSLaszlo Ersek
3777db55fcSLaszlo Ersek# In the pattern rules below, the stem (%, $*) stands for
3877db55fcSLaszlo Ersek# "$(binary).$(target)".
3977db55fcSLaszlo Ersek
4077db55fcSLaszlo Ersek# Convert the raw ISO image to a qcow2 one, enabling compression, and using a
4177db55fcSLaszlo Ersek# small cluster size. This allows for small binary files under git control,
4277db55fcSLaszlo Ersek# hence for small binary patches.
4377db55fcSLaszlo Ersek$(images_dir)/%.iso.qcow2: Build/%.iso.raw
4477db55fcSLaszlo Ersek	mkdir -p -- $(images_dir)
4577db55fcSLaszlo Ersek	$${QTEST_QEMU_IMG:-qemu-img} convert -f raw -O qcow2 -c \
4677db55fcSLaszlo Ersek		-o cluster_size=512 -- $< $@
4777db55fcSLaszlo Ersek
4877db55fcSLaszlo Ersek# Embed the "UEFI system partition" into an ISO9660 file system as an ElTorito
4977db55fcSLaszlo Ersek# boot image.
5077db55fcSLaszlo ErsekBuild/%.iso.raw: Build/%.fat
5177db55fcSLaszlo Ersek	genisoimage -input-charset ASCII -efi-boot $(notdir $<) -no-emul-boot \
5277db55fcSLaszlo Ersek		-quiet -o $@ -- $<
5377db55fcSLaszlo Ersek
5477db55fcSLaszlo Ersek# Define chained macros in order to map QEMU system emulation targets to
5577db55fcSLaszlo Ersek# *short* UEFI architecture identifiers. Periods are allowed in, and ultimately
5677db55fcSLaszlo Ersek# stripped from, the argument.
5777db55fcSLaszlo Ersekmap_arm_to_uefi     = $(subst arm,ARM,$(1))
5877db55fcSLaszlo Ersekmap_aarch64_to_uefi = $(subst aarch64,AA64,$(call map_arm_to_uefi,$(1)))
59*ad8560faSSunil V Lmap_riscv64_to_uefi = $(subst riscv64,RISCV64,$(call map_aarch64_to_uefi,$(1)))
60*ad8560faSSunil V Lmap_i386_to_uefi    = $(subst i386,IA32,$(call map_riscv64_to_uefi,$(1)))
6177db55fcSLaszlo Ersekmap_x86_64_to_uefi  = $(subst x86_64,X64,$(call map_i386_to_uefi,$(1)))
6277db55fcSLaszlo Ersekmap_to_uefi         = $(subst .,,$(call map_x86_64_to_uefi,$(1)))
6377db55fcSLaszlo Ersek
6477db55fcSLaszlo Ersek# Format a "UEFI system partition", using the UEFI binary as the default boot
6577db55fcSLaszlo Ersek# loader. Add 10% size for filesystem metadata, round up to the next KB, and
6677db55fcSLaszlo Ersek# make sure the size is large enough for a FAT filesystem. Name the filesystem
6777db55fcSLaszlo Ersek# after the UEFI binary. (Excess characters are automatically dropped from the
6877db55fcSLaszlo Ersek# filesystem label.)
6977db55fcSLaszlo ErsekBuild/%.fat: Build/%.efi
7077db55fcSLaszlo Ersek	rm -f -- $@
7177db55fcSLaszlo Ersek	uefi_bin_b=$$(stat --format=%s -- $<) && \
7277db55fcSLaszlo Ersek		uefi_fat_kb=$$(( (uefi_bin_b * 11 / 10 + 1023) / 1024 )) && \
7377db55fcSLaszlo Ersek		uefi_fat_kb=$$(( uefi_fat_kb >= 64 ? uefi_fat_kb : 64 )) && \
74*ad8560faSSunil V L		mkdosfs -C $@ -n "bios-test" -- $$uefi_fat_kb
7577db55fcSLaszlo Ersek	MTOOLS_SKIP_CHECK=1 mmd -i $@ ::EFI
7677db55fcSLaszlo Ersek	MTOOLS_SKIP_CHECK=1 mmd -i $@ ::EFI/BOOT
7777db55fcSLaszlo Ersek	MTOOLS_SKIP_CHECK=1 mcopy -i $@ -- $< \
7877db55fcSLaszlo Ersek		::EFI/BOOT/BOOT$(call map_to_uefi,$(suffix $*)).EFI
7977db55fcSLaszlo Ersek
8077db55fcSLaszlo Ersek# In the pattern rules below, the stem (%, $*) stands for "$(target)" only. The
8177db55fcSLaszlo Ersek# association between the UEFI binary (such as "bios-tables-test") and the
8277db55fcSLaszlo Ersek# component name from the edk2 platform DSC file (such as "BiosTablesTest") is
8377db55fcSLaszlo Ersek# explicit in each rule.
8477db55fcSLaszlo Ersek
8577db55fcSLaszlo Ersek# "build.sh" invokes the "build" utility of edk2 BaseTools. In any given edk2
8677db55fcSLaszlo Ersek# workspace, at most one "build" instance may be operating at a time. Therefore
8777db55fcSLaszlo Ersek# we must serialize the rebuilding of targets in this Makefile.
8877db55fcSLaszlo Ersek.NOTPARALLEL:
8977db55fcSLaszlo Ersek
9077db55fcSLaszlo Ersek# In turn, the "build" utility of edk2 BaseTools invokes another "make".
9196420a30SMichael Tokarev# Although the outer "make" process advertises its job server to all child
9277db55fcSLaszlo Ersek# processes via MAKEFLAGS in the environment, the outer "make" closes the job
9377db55fcSLaszlo Ersek# server file descriptors (exposed in MAKEFLAGS) before executing a recipe --
9477db55fcSLaszlo Ersek# unless the recipe is recognized as a recursive "make" recipe. Recipes that
9577db55fcSLaszlo Ersek# call $(MAKE) are classified automatically as recursive; for "build.sh" below,
9677db55fcSLaszlo Ersek# we must mark the recipe manually as recursive, by using the "+" indicator.
9777db55fcSLaszlo Ersek# This way, when the inner "make" starts a parallel build of the target edk2
9877db55fcSLaszlo Ersek# module, it can communicate with the outer "make"'s job server.
99*ad8560faSSunil V LBuild/bios-tables-test.%.efi:
100*ad8560faSSunil V L	$(PYTHON) ../../roms/edk2-build.py --config uefi-test-build.config \
101*ad8560faSSunil V L		--match $*
10277db55fcSLaszlo Ersek
10377db55fcSLaszlo Ersekclean:
10477db55fcSLaszlo Ersek	rm -rf Build Conf log
10577db55fcSLaszlo Ersek	$(MAKE) -C $(edk2_dir)/BaseTools clean
106