feat(fvp): improve ROMlib's jump table index file management
fvp_romlib_runtime() does the following steps:
1. Save the original jump table index file used to build the ROMlib.
2. Patch it.
3. Rebuild the ROMlib (with the patched jump table index file).
Then the run config is expected to call fvp_romlib_cleanup() in the
post_tf_archive() hook to restore the original jump table index file.
If any command fails in between step 2 and fvp_romlib_cleanup(), or if
the run config does not call fvp_romlib_cleanup() as expected, then
the jump table index file is left as is. This is particulary
problematic when running the CI scripts on a developer's local
machine because it directly modifies their local repository.
This patch solves this issue by:
- moving steps 1-2-3 to a sub-shell.
- attaching fvp_romlib_cleanup() as a trap handler for this sub-shell.
This way, as soon as the sub-shell exits - either normally or abruptly
due to an error, the index file is restored as expected. As a result,
run configurations no longer need to do this explicitly.
Change-Id: I8fd8be008108f1e624a0b2d646af358df1b3fdc6
Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
diff --git a/fvp_utils.sh b/fvp_utils.sh
index 5365d3d..9fc4e68 100644
--- a/fvp_utils.sh
+++ b/fvp_utils.sh
@@ -243,8 +243,6 @@
popd
}
-fvp_romlib_jmptbl_backup="$(mktempdir)/jmptbl.i"
-
fvp_romlib_runtime() {
local tmpdir="$(mktempdir)"
@@ -253,24 +251,32 @@
mv "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin" "$tmpdir/bl1.bin"
# Patch index file
- cp "${tf_root:?}/plat/arm/board/fvp/jmptbl.i" "$fvp_romlib_jmptbl_backup"
- sed -i '/fdt/ s/.$/&\ patch/' ${tf_root:?}/plat/arm/board/fvp/jmptbl.i
+ (
+ fvp_romlib_jmptbl="${tf_root:?}/plat/arm/board/fvp/jmptbl.i"
+ fvp_romlib_jmptbl_backup="$(mktempdir)/jmptbl.i"
- # Rebuild with patched file
- echo "Building patched romlib:"
- build_tf
+ function __restore() {
+ mv "$fvp_romlib_jmptbl_backup" "$fvp_romlib_jmptbl";
+ }
+
+ # Make sure the original index file is restored.
+ # This will be done either when the current sub-shell exits or
+ # when one of the sub-shell's commands fails.
+ trap __restore EXIT HUP QUIT INT TERM
+
+ cp "$fvp_romlib_jmptbl" "$fvp_romlib_jmptbl_backup"
+ sed -i '/fdt/ s/.$/&\ patch/' "$fvp_romlib_jmptbl"
+
+ # Rebuild with patched file
+ echo "Building patched romlib:"
+ build_tf
+ )
# Retrieve original BL1 and romlib binaries
mv "$tmpdir/romlib.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/romlib/romlib.bin"
mv "$tmpdir/bl1.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin"
}
-fvp_romlib_cleanup() {
- # Restore original index
- mv "$fvp_romlib_jmptbl_backup" "${tf_root:?}/plat/arm/board/fvp/jmptbl.i"
-}
-
-
fvp_gen_bin_url() {
local bin_mode="${bin_mode:?}"
local bin="${1:?}"
diff --git a/run_config/fvp-romlib b/run_config/fvp-romlib
index 6ae4bd4..b58a512 100644
--- a/run_config/fvp-romlib
+++ b/run_config/fvp-romlib
@@ -8,7 +8,3 @@
post_tf_build() {
fvp_romlib_runtime
}
-
-post_tf_archive() {
- fvp_romlib_cleanup
-}
diff --git a/run_config/fvp-spm+romlib b/run_config/fvp-spm+romlib
index 22a62f6..c6a8394 100644
--- a/run_config/fvp-spm+romlib
+++ b/run_config/fvp-spm+romlib
@@ -36,7 +36,3 @@
model="$model" gen_fvp_yaml
}
-
-post_tf_archive() {
- fvp_romlib_cleanup
-}