Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linuxboot builds #845

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,26 @@ jobs:
#If precedent fails. Restore cache for musl-cross module checksum validated to be exactly the same as in github current commit
- heads-cross-musl-{{ checksum "/tmp/musl-cross_module_and_patches.sha256sums" }}{{ .Environment.CACHE_VERSION }}

# linuxboot steps need something to pass in the kernel header path
# skipping for now
# - run:
# name: qemu-linuxboot-edk2
# command: |
# ./build/make-4.2.1/make \
# CROSS=/cross/bin/x86_64-linux-musl- \
# BOARD=qemu-linuxboot \
# `/bin/pwd`/build/linuxboot-git/build/qemu/.configured \
# # Run first to avoid too many processes
#
# - run:
# name: qemu-linuxboot
# command: |
# ./build/make-4.2.1/make \
# CROSS=/cross/bin/x86_64-linux-musl- \
# CPUS=4 \
# V=1 \
# BOARD=qemu-linuxboot \
#
# - store-artifacts:
# path: build/qemu-linuxboot/linuxboot.rom
# - store-artifacts:
# path: build/qemu-linuxboot/hashes.txt
- run:
name: qemu-linuxboot-edk2
command: |
make \
BOARD=qemu-linuxboot \
`/bin/pwd`/build/linuxboot-b5376a441e8e85cbf722e943bb8294958e87c784/build/qemu/.configured \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will break in future linuxboot version bump. Why static?
$(linuxboot_base_dir)/build/qemu/.configured ?

# Run first to avoid too many processes

- run:
name: qemu-linuxboot
command: |
make \
CPUS=4 \
V=1 \
BOARD=qemu-linuxboot \

- store-artifacts:
path: build/qemu-linuxboot/linuxboot.rom
- store-artifacts:
path: build/qemu-linuxboot/hashes.txt

- run:
name: librem_mini-NoTPM
Expand Down
2 changes: 1 addition & 1 deletion boards/winterfell/winterfell.config
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dxe_offset := 860000
dxe_size := 6a0000
flash-dxe: $(build)/$(BOARD)/linuxboot.rom
( echo u$(dxe_offset) $(dxe_size) ; \
pv $(build)/linuxboot-git/build/$(BOARD)/dxe.vol \
pv $(build)/linuxboot-b5376a441e8e85cbf722e943bb8294958e87c784/build/$(BOARD)/dxe.vol \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I get what you are doing here.
You can get the build directory by reusing Makefile included module.

In this case: $(linuxboot_base_dir)

) > /dev/ttyACM0

flash: $(build)/$(BOARD)/linuxboot.rom
Expand Down
4 changes: 3 additions & 1 deletion modules/coreboot
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
modules-$(CONFIG_COREBOOT) += coreboot

ifeq "$(CONFIG_COREBOOT)" "y"
ifeq "$(CONFIG_COREBOOT_VERSION)" "4.8.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation should shift

coreboot_version := 4.8.1
coreboot_hash := f0ddf4db0628c1fe1e8348c40084d9cbeb5771400c963fd419cda3995b69ad23
Expand All @@ -10,8 +11,9 @@ else ifeq "$(CONFIG_COREBOOT_VERSION)" "4.12"
coreboot-blobs_hash := 4735ee6850d55d1e65dee8b08cc9b28b8af00b42acf31365f5d9545406579104
coreboot_depends := $(if $(CONFIG_PURISM_BLOBS), purism-blobs)
else
$(error "$(BOARD): does not specify coreboot version under CONFIG_COREBOOT_VERSION")
$(error "$(BOARD): does not specify coreboot version under CONFIG_COREBOOT_VERSION")
endif
endif

#coreboot_version := git
#coreboot_repo := https://github.com/osresearch/coreboot
Expand Down
34 changes: 31 additions & 3 deletions modules/linuxboot
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
modules-$(CONFIG_LINUXBOOT) += linuxboot

linuxboot_version := git
linuxboot_repo := https://github.com/osresearch/linuxboot
#linuxboot_version := git
#linuxboot_repo := https://github.com/osresearch/linuxboot

linuxboot_version := b5376a441e8e85cbf722e943bb8294958e87c784
linuxboot_hash := ccbe2a1ce344dd5831a774a038ed619f988029cc123a87202d62f3d0ec7aad62
linuxboot_tar := linuxboot-$(linuxboot_version).tar.gz
linuxboot_url := https://github.com/osresearch/linuxboot/archive/$(linuxboot_version).tar.gz

linuxboot_base_dir := linuxboot-$(linuxboot_version)

# linuxboot builds are specialized on a per-target basis.
Expand All @@ -21,7 +27,7 @@ linuxboot_configure := \
if [ "$(linuxboot_board)" = "qemu" ]; then \
echo >&2 "Pre-building edk2 OVMF" ; \
( cd $(build)/$(linuxboot_base_dir)/edk2/OvmfPkg ; \
./build.sh -n $$CPUS \
./build.sh -n $(CPUS) \
Copy link
Contributor

@synackd synackd Dec 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tlaurion What do you say to making this change a separate PR and merging it in? I was about to make one addressing this before seeing this change in this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@synackd please do. Same should be made under coreboot module

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In hindsight, I probably could have combined #940 and #941 into one PR, though it does categorically separate the linuxboot and coreboot modules...

Copy link
Collaborator

@tlaurion tlaurion Dec 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested it? The idea here is to pass CPUS to command line
make BOARD= x230 CPUS=2

There is no such invocation as CPUS as a command.
@synackd?
EDIT: nevermind! Tested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes can be retracted since they are already merged as of #940.

) || exit 1 ; \
fi ; \
touch .config ; \
Expand Down Expand Up @@ -77,3 +83,25 @@ linuxboot.run: $(build)/$(BOARD)/linuxboot.rom
INITRD=$(build)/$(BOARD)/initrd.cpio.xz \
CUSTOM=$(CUSTOMPWD) \
run

# If we are not building from a git checkout,
# we must also download the linuxboot-edk2 tree
ifneq "$(linuxboot_version)" "git"

linuxboot_depends += linuxboot-edk2
modules-$(CONFIG_LINUXBOOT) += linuxboot-edk2

linuxboot-edk2_version := b7c299e4799012e8a20958a68693ab95b7626aa9
linuxboot-edk2_hash := 78f48f46414b019b5fcd2d7049fd79e955d25f2965123d0bbdf7226564db33e5

linuxboot-edk2_tar := linuxboot-edk2-$(linuxboot-edk2_version).tar.gz
linuxboot-edk2_url := https://github.com/linuxboot/edk2/archive/$(linuxboot-edk2_version).tar.gz
linuxboot-edk2_dir := $(linuxboot_base_dir)/edk2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so that is the env variable to reuse $linuxboot-edk2_dir


# We don't need to build edk2 ourselves
# It will be done as part of the linuxboot build process
linuxboot-edk2_output := .git
linuxboot-edk2_target := .git
linuxboot-edk2_configure := echo -e '\n.git:\n\ttouch .git' >> Makefile

endif
2 changes: 2 additions & 0 deletions modules/linuxboot-edk2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# empty placeholder file
# This submodule is defined in modules/linuxboot if necessary
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From d1a4d98a9ddf8e7e7f1e00ca2c143b5d5dc01afd Mon Sep 17 00:00:00 2001
From: Nathan Rennie-Waldock <[email protected]>
Date: Sun, 18 Oct 2020 23:58:29 +0100
Subject: [PATCH] Makefile: Rename configured stamp to avoid conflict with
heads build system

Signed-off-by: Nathan Rennie-Waldock <[email protected]>
---
Makefile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index 2c58529031..d400904442 100644
--- a/Makefile
+++ b/Makefile
@@ -26,16 +26,16 @@ $(EDK2_OUTPUTS): build-dxe
ia32:
build -a IA32

-build-dxe: .configured
+build-dxe: .edk2-configured
cd MdeModulePkg ; build

-build-cpu: .configured
+build-cpu: .edk2-configured
cd UefiCpuPkg ; build
-build-quark: .configured
+build-quark: .edk2-configured
cd QuarkPlatformPkg ; build
build: build-dxe

- .configured:
+ .edk2-configured:
$(MAKE) -C BaseTools
. ./edksetup.sh
touch $@
--
2.25.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
From 9de306701312f986c9638cb819d3f1f848d55cab Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <[email protected]>
Date: Fri, 2 Mar 2018 17:11:52 +0100
Subject: [PATCH] BaseTools/GenVtf: silence false "stringop-overflow" warning
with memcpy()

gcc-8 (which is part of Fedora 28) enables the new warning
"-Wstringop-overflow" in "-Wall". This warning is documented in detail at
<https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html>; the
introduction says

> Warn for calls to string manipulation functions such as memcpy and
> strcpy that are determined to overflow the destination buffer.

It breaks the BaseTools build with:

> GenVtf.c: In function 'ConvertVersionInfo':
> GenVtf.c:132:7: error: 'strncpy' specified bound depends on the length
> of the source argument [-Werror=stringop-overflow=]
> strncpy (TemStr + 4 - Length, Str, Length);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> GenVtf.c:130:14: note: length computed here
> Length = strlen(Str);
> ^~~~~~~~~~~

It is a false positive because, while the bound equals the length of the
source argument, the destination pointer is moved back towards the
beginning of the destination buffer by the same amount (and this amount is
range-checked first, so we can't precede the start of the dest buffer).

Replace both strncpy() calls with memcpy().

Cc: Ard Biesheuvel <[email protected]>
Cc: Cole Robinson <[email protected]>
Cc: Liming Gao <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Yonghong Zhu <[email protected]>
Reported-by: Cole Robinson <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <[email protected]>
Reviewed-by: Liming Gao <[email protected]>
---
BaseTools/Source/C/GenVtf/GenVtf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/C/GenVtf/GenVtf.c b/BaseTools/Source/C/GenVtf/GenVtf.c
index 65ae08eece..fc7ae02203 100644
--- a/BaseTools/Source/C/GenVtf/GenVtf.c
+++ b/BaseTools/Source/C/GenVtf/GenVtf.c
@@ -129,9 +129,9 @@ Returns:
} else {
Length = strlen(Str);
if (Length < 4) {
- strncpy (TemStr + 4 - Length, Str, Length);
+ memcpy (TemStr + 4 - Length, Str, Length);
} else {
- strncpy (TemStr, Str + Length - 4, 4);
+ memcpy (TemStr, Str + Length - 4, 4);
}

sscanf (
--
2.25.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
From 1d212a83df0eaf32a6f5d4159beb2d77832e0231 Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <[email protected]>
Date: Fri, 2 Mar 2018 17:11:52 +0100
Subject: [PATCH 01/11] BaseTools/header.makefile: add
"-Wno-stringop-truncation"

gcc-8 (which is part of Fedora 28) enables the new warning
"-Wstringop-truncation" in "-Wall". This warning is documented in detail
at <https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html>; the
introduction says

> Warn for calls to bounded string manipulation functions such as strncat,
> strncpy, and stpncpy that may either truncate the copied string or leave
> the destination unchanged.

It breaks the BaseTools build with:

> EfiUtilityMsgs.c: In function 'PrintMessage':
> EfiUtilityMsgs.c:484:9: error: 'strncat' output may be truncated copying
> between 0 and 511 bytes from a string of length 511
> [-Werror=stringop-truncation]
> strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> EfiUtilityMsgs.c:469:9: error: 'strncat' output may be truncated copying
> between 0 and 511 bytes from a string of length 511
> [-Werror=stringop-truncation]
> strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> EfiUtilityMsgs.c:511:5: error: 'strncat' output may be truncated copying
> between 0 and 511 bytes from a string of length 511
> [-Werror=stringop-truncation]
> strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The right way to fix the warning would be to implement string concat with
snprintf(). However, Microsoft does not appear to support snprintf()
before VS2015
<https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010>,
so we just have to shut up the warning. The strncat() calls flagged above
are valid BTW.

Cc: Ard Biesheuvel <[email protected]>
Cc: Cole Robinson <[email protected]>
Cc: Liming Gao <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Yonghong Zhu <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <[email protected]>
Reviewed-by: Liming Gao <[email protected]>
---
BaseTools/Source/C/Makefiles/header.makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Source/C/Makefiles/header.makefile
index 0976973bdd..550f8b35bc 100644
--- a/BaseTools/Source/C/Makefiles/header.makefile
+++ b/BaseTools/Source/C/Makefiles/header.makefile
@@ -71,9 +71,9 @@ INCLUDE = $(TOOL_INCLUDE) -I $(MAKEROOT) -I $(MAKEROOT)/Include/Common -I $(MAKE
BUILD_CPPFLAGS = $(INCLUDE) -O2
ifeq ($(DARWIN),Darwin)
# assume clang or clang compatible flags on OS X
-BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -c -g
+BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-self-assign -Wno-unused-result -nostdlib -c -g
else
-BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-unused-result -nostdlib -c -g
+BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-unused-result -nostdlib -c -g
endif
BUILD_LFLAGS =
BUILD_CXXFLAGS = -Wno-unused-result
--
2.25.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From 88e8498f8a72cff1f7af6852ec8166772913399e Mon Sep 17 00:00:00 2001
From: Liming Gao <[email protected]>
Date: Thu, 1 Nov 2018 22:35:29 +0800
Subject: [PATCH] BaseTools tools_def.template: Add GCC link script option in
ASLDLINK_FLAGS

GCC link script is used to discard the unused section data from ELF image.
ASLDLINK_FLAGS requires it to remove the unnecessary section data, then
GenFw can be used to retrieve the correct data section from ELF image.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <[email protected]>
Cc: Yonghong Zhu <[email protected]>
Reviewed-by: Yonghong Zhu <[email protected]>
---
BaseTools/Conf/tools_def.template | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index a22b96c0b8..e0e68fd7fb 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -4253,7 +4253,7 @@ DEFINE GCC48_AARCH64_ASLDLINK_FLAGS = DEF(GCC47_AARCH64_ASLDLINK_FLAGS)
DEFINE GCC49_IA32_CC_FLAGS = DEF(GCC48_IA32_CC_FLAGS)
DEFINE GCC49_X64_CC_FLAGS = DEF(GCC48_X64_CC_FLAGS)
DEFINE GCC49_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x40
-DEFINE GCC49_IA32_X64_ASLDLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable
+DEFINE GCC49_IA32_X64_ASLDLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_COMMON) -Wl,--defsym=PECOFF_HEADER_SIZE=0 DEF(GCC_DLINK2_FLAGS_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable
DEFINE GCC49_IA32_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive
DEFINE GCC49_IA32_DLINK2_FLAGS = DEF(GCC48_IA32_DLINK2_FLAGS)
DEFINE GCC49_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_FLAGS) -Wl,-melf_x86_64,--oformat=elf64-x86-64,-pie
--
2.25.1