From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.32223.1623686364862034419 for ; Mon, 14 Jun 2021 08:59:25 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ross.burton@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9B69B1FB for ; Mon, 14 Jun 2021 08:59:21 -0700 (PDT) Received: from oss-tx204.lab.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 412363F70D for ; Mon, 14 Jun 2021 08:59:21 -0700 (PDT) From: "Ross Burton" To: meta-arm@lists.yoctoproject.org Subject: [PATCH] arm-bsp/boot-firmware: fix build race Date: Mon, 14 Jun 2021 16:59:19 +0100 Message-Id: <20210614155919.3265764-1-ross.burton@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable As boot-firmware is heavily based on SCP-firmware it has the same build race. Luckily, the patch in SCP-firmware[1] applies cleanly to boot-firmware. [1] https://github.com/ARM-software/SCP-firmware/commit/34e1c04534607f560= 5255f39fb46e26261fc9c4e Signed-off-by: Ross Burton Change-Id: Iaa2f1bb71fce66589db530ea378d4ce995a6bed9 --- .../boot-firmware/gen-module-race.patch | 66 +++++++++++++++++++ .../boot-firmware/boot-firmware_git.bb | 3 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 meta-arm-bsp/recipes-bsp/boot-firmware/boot-firmware/= gen-module-race.patch diff --git a/meta-arm-bsp/recipes-bsp/boot-firmware/boot-firmware/gen-mod= ule-race.patch b/meta-arm-bsp/recipes-bsp/boot-firmware/boot-firmware/gen= -module-race.patch new file mode 100644 index 0000000..c93e91a --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-firmware/boot-firmware/gen-module-rac= e.patch @@ -0,0 +1,66 @@ +Upstream-Status: Pending +Signed-off-by: Ross Burton + +From 34e1c04534607f5605255f39fb46e26261fc9c4e Mon Sep 17 00:00:00 2001 +From: Ross Burton +Date: Tue, 8 Sep 2020 11:49:08 +0100 +Subject: [PATCH] tools/gen_module_code: atomically rewrite the generated= files + +The gen_module rule in rules.mk is marked as .PHONY, so make will +execute it whenever it is mentioned. This results in gen_module_code +being executed 64 times for a Juno build. + +However in heavily parallel builds there's a good chance that +gen_module_code is writing a file whilst the compiler is reading it +because make also doesn't know what files are generated by +gen_module_code. + +The correct fix is to adjust the Makefiles so that the dependencies are +correct but this isn't trivial, so band-aid the problem by atomically +writing the generated files. + +Change-Id: I82d44f9ea6537a91002e1f80de8861d208571630 +Signed-off-by: Ross Burton +--- + tools/gen_module_code.py | 19 ++++++++++++++----- + 1 file changed, 14 insertions(+), 5 deletions(-) + +diff --git a/tools/gen_module_code.py b/tools/gen_module_code.py +index 7b3953845..ee099b713 100755 +--- a/tools/gen_module_code.py ++++ b/tools/gen_module_code.py +@@ -17,6 +17,7 @@ + import argparse + import os + import sys ++import tempfile +=20 + DEFAULT_PATH =3D 'build/' +=20 +@@ -53,13 +54,21 @@ +=20 + def generate_file(path, filename, content): + full_filename =3D os.path.join(path, filename) +- with open(full_filename, 'a+') as f: +- f.seek(0) +- if f.read() !=3D content: ++ ++ try: ++ with open(full_filename) as f: ++ rewrite =3D f.read() !=3D content ++ except FileNotFoundError: ++ rewrite =3D True ++ ++ if rewrite: ++ with tempfile.NamedTemporaryFile(prefix=3D"gen-module-code", ++ dir=3Dpath, ++ delete=3DFalse, ++ mode=3D"wt") as f: + print("[GEN] {}...".format(full_filename)) +- f.seek(0) +- f.truncate() + f.write(content) ++ os.replace(f.name, full_filename) +=20 +=20 + def generate_header(path, modules): diff --git a/meta-arm-bsp/recipes-bsp/boot-firmware/boot-firmware_git.bb = b/meta-arm-bsp/recipes-bsp/boot-firmware/boot-firmware_git.bb index c7242d1..c48e586 100644 --- a/meta-arm-bsp/recipes-bsp/boot-firmware/boot-firmware_git.bb +++ b/meta-arm-bsp/recipes-bsp/boot-firmware/boot-firmware_git.bb @@ -5,7 +5,8 @@ LICENSE =3D "BSD-3-Clause & Apache-2.0" LIC_FILES_CHKSUM =3D "file://license.md;md5=3De44b2531cd6ffe9dece394dbe9= 88d9a0 \ file://cmsis/LICENSE.txt;md5=3De3fc50a88d0a364313df4= b21ef20c29e" =20 -SRC_URI =3D "gitsm://git.linaro.org/landing-teams/working/arm/boot-firmw= are.git;protocol=3Dhttps" +SRC_URI =3D "gitsm://git.linaro.org/landing-teams/working/arm/boot-firmw= are.git;protocol=3Dhttps \ + file://gen-module-race.patch" SRCREV =3D "af7eeb1bb8c5a85a5e5a76d48acc6fe864d715a9" PV =3D "2020.02.10+git${SRCPV}" =20 --=20 2.25.1