@@ -400,47 +400,51 @@ define define_module =
400
400
# module-specific cleanup action to get rid of it.
401
401
$(build ) /$($1_base_dir ) /.canary: FORCE
402
402
if [ ! -e "$$@ " ]; then \
403
- echo "INFO: .canary file not found. Cloning repository $($1_repo ) into $(build ) /$($1_base_dir ) "; \
404
- git clone $($1_repo ) "$(build ) /$($1_base_dir ) "; \
405
- echo "INFO: Resetting repository to commit $($1_commit_hash ) "; \
406
- git -C "$(build ) /$($1_base_dir ) " reset --hard $($1_commit_hash ) ; \
407
- echo "INFO: Creating .canary file with repo and commit hash"; \
408
- echo -n '$($1_repo ) |$($1_commit_hash ) ' > "$$@ "; \
403
+ echo "INFO: .canary file not found. Cloning repository $($1_repo ) into $(build ) /$($1_base_dir ) " && \
404
+ git clone $($1_repo ) "$(build ) /$($1_base_dir ) " && \
405
+ echo "INFO: Resetting repository to commit $($1_commit_hash ) " && \
406
+ git -C "$(build ) /$($1_base_dir ) " reset --hard $($1_commit_hash ) && \
407
+ echo "INFO: Creating .canary file with repo and commit hash" && \
408
+ echo -n '$($1_repo ) |$($1_commit_hash ) ' > "$$@ " ; \
409
409
elif [ "$$$$(cat "$$@ " ) " != '$($1_repo ) |$($1_commit_hash ) ' ]; then \
410
- echo "INFO: Canary file differs. Switching $1 to $($1_repo ) at $($1_commit_hash ) "; \
410
+ echo "INFO: Canary file differs. Switching $1 to $($1_repo ) at $($1_commit_hash ) " && \
411
411
git -C "$(build ) /$($1_base_dir ) " reset --hard HEAD^ && \
412
- echo "INFO: Fetching commit $($1_commit_hash ) from $($1_repo ) (without recursing submodules)"; \
412
+ echo "INFO: Fetching commit $($1_commit_hash ) from $($1_repo ) (without recursing submodules)" && \
413
413
git -C "$(build ) /$($1_base_dir ) " fetch $($1_repo ) $($1_commit_hash ) --recurse-submodules=no && \
414
- echo "INFO: Resetting repository to commit $($1_commit_hash ) "; \
415
- git -C "$(build ) /$($1_base_dir ) " reset --hard $($1_commit_hash ) ; \
416
- echo "INFO: Cleaning repository directory (including payloads and util/cbmem)"; \
414
+ echo "INFO: Resetting repository to commit $($1_commit_hash ) " && \
415
+ git -C "$(build ) /$($1_base_dir ) " reset --hard $($1_commit_hash ) && \
416
+ echo "INFO: Cleaning repository directory (including payloads and util/cbmem)" && \
417
417
git -C "$(build ) /$($1_base_dir ) " clean -df && \
418
418
git -C "$(build ) /$($1_base_dir ) " clean -dffx payloads util/cbmem && \
419
- echo "INFO: Synchronizing submodules"; \
419
+ echo "INFO: Synchronizing submodules" && \
420
420
git -C "$(build ) /$($1_base_dir ) " submodule sync && \
421
- echo "INFO: Updating submodules (init and checkout)"; \
421
+ echo "INFO: Updating submodules (init and checkout)" && \
422
422
git -C "$(build ) /$($1_base_dir ) " submodule update --init --checkout && \
423
- echo "INFO: Updating .canary file with new repo info"; \
424
- echo -n '$($1_repo ) |$($1_commit_hash ) ' > "$$@ "; \
423
+ echo "INFO: Updating .canary file with new repo info" && \
424
+ echo -n '$($1_repo ) |$($1_commit_hash ) ' > "$$@ " ; \
425
425
fi
426
426
if [ ! -e "$(build ) /$($1_base_dir ) /.patched" ]; then \
427
- echo "INFO: .patched file not found. Beginning patch application for $1"; \
427
+ echo "INFO: .patched file not found. Beginning patch application for $1" && \
428
428
if [ -r patches/$($1_patch_name ) .patch ]; then \
429
- echo "INFO: Found patch file patches/$($1_patch_name ) .patch. Applying patch..."; \
430
- ( git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) ) \
431
- < patches/$($1_patch_name ) .patch \
432
- || exit 1 ; \
433
- fi && \
434
- if [ -d patches/$($1_patch_name ) ] && \
435
- [ -r patches/$($1_patch_name ) ] ; then \
436
- for patch in patches/$($1_patch_name ) /*.patch ; do \
437
- echo "Applying patch file : $$$$patch " ; \
438
- ( git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) ) \
439
- < $$$$patch \
440
- || exit 1 ; \
441
- done ; \
442
- fi && \
443
- echo "INFO: Patches applied successfully. Creating .patched file"; \
429
+ echo "INFO: Applying single patch file: patches/$($1_patch_name ) .patch" && \
430
+ if ! git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < patches/$($1_patch_name ) .patch; then \
431
+ echo "ERROR: Failed to apply patch: patches/$($1_patch_name ) .patch. Reversing and reapplying." && \
432
+ git apply --reverse --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < patches/$($1_patch_name ) .patch || true && \
433
+ git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < patches/$($1_patch_name ) .patch || exit 1; \
434
+ fi; \
435
+ fi; \
436
+ if [ -d patches/$($1_patch_name ) ]; then \
437
+ echo "INFO: Applying multiple patch files from directory: patches/$($1_patch_name ) " && \
438
+ for patch in patches/$($1_patch_name ) /*.patch; do \
439
+ echo "INFO: Applying patch file: $$$$patch" && \
440
+ if ! git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < "$$$$patch"; then \
441
+ echo "ERROR: Failed to apply patch: $$$$patch. Reversing and reapplying." && \
442
+ git apply --reverse --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < "$$$$patch" || true && \
443
+ git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < "$$$$patch" || exit 1; \
444
+ fi; \
445
+ done; \
446
+ fi; \
447
+ echo "INFO: Patches applied successfully. Creating .patched file." && \
444
448
touch "$(build ) /$($1_base_dir ) /.patched"; \
445
449
fi
446
450
else
@@ -465,20 +469,45 @@ define define_module =
465
469
mkdir -p "$$(dir $$@ ) "
466
470
tar -xf "$(packages ) /$($1_tar ) " $(or $($1_tar_opt ) ,--strip 1) -C "$$(dir $$@ ) "
467
471
if [ -r patches/$($1_patch_name ) .patch ]; then \
468
- ( git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) ) \
469
- < patches/$($1_patch_name ) .patch \
470
- || exit 1 ; \
471
- fi
472
- if [ -d patches/$($1_patch_name ) ] && \
473
- [ -r patches/$($1_patch_name ) ] ; then \
474
- for patch in patches/$($1_patch_name ) /*.patch ; do \
475
- echo "Applying patch file : $$$$patch " ; \
476
- ( git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) ) \
477
- < $$$$patch \
478
- || exit 1 ; \
472
+ echo "INFO: Applying single patch file: patches/$($1_patch_name ) .patch" && \
473
+ if ! ( git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < patches/$($1_patch_name ) .patch ); then \
474
+ echo "ERROR: Failed to apply patch: patches/$($1_patch_name ) .patch. Reversing and reapplying." && \
475
+ ( git apply --reverse --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < patches/$($1_patch_name ) .patch ) || true && \
476
+ ( git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < patches/$($1_patch_name ) .patch ) || exit 1 ; \
477
+ fi ; \
478
+ fi ; \
479
+ if [ -d patches/$($1_patch_name ) ]; then \
480
+ echo "INFO: Applying multiple patch files from directory: patches/$($1_patch_name ) " && \
481
+ for patch in patches/$($1_patch_name ) /*.patch; do \
482
+ echo "INFO: Applying patch file: $$$$patch" && \
483
+ if ! ( git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < $$$$patch ); then \
484
+ echo "ERROR: Failed to apply patch: $$$$patch. Reversing and reapplying." && \
485
+ ( git apply --reverse --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < $$$$patch ) || true && \
486
+ echo "INFO: Reapplying patch file: $$$$patch" && \
487
+ ( git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < $$$$patch ) || exit 1 ; \
488
+ fi ; \
479
489
done ; \
480
490
fi
481
- @touch "$$@ "
491
+ if [ ! -e "$$@ " ] && [ -e "$(build ) /$($1_base_dir ) /.patched" ]; then \
492
+ echo "INFO: .canary file not found but .patched exists. Reversing and reapplying patches for $1" && \
493
+ if [ -r patches/$($1_patch_name ) .patch ]; then \
494
+ echo "INFO: Reversing single patch file: patches/$($1_patch_name ) .patch." && \
495
+ ( git apply --reverse --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < patches/$($1_patch_name ) .patch ) || true && \
496
+ echo "INFO: Reapplying single patch file: patches/$($1_patch_name ) .patch." && \
497
+ ( git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < patches/$($1_patch_name ) .patch ) || exit 1 ; \
498
+ fi ; \
499
+ if [ -d patches/$($1_patch_name ) ]; then \
500
+ echo "INFO: Reversing and reapplying multiple patch files from directory: patches/$($1_patch_name ) " && \
501
+ for patch in patches/$($1_patch_name ) /*.patch; do \
502
+ echo "INFO: Reversing patch file: $$$$patch" && \
503
+ ( git apply --reverse --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < $$$$patch ) || true && \
504
+ echo "INFO: Reapplying patch file: $$$$patch" && \
505
+ ( git apply --verbose --reject --binary --directory build/$(CONFIG_TARGET_ARCH ) /$($1_base_dir ) < $$$$patch ) || exit 1 ; \
506
+ done ; \
507
+ fi ; \
508
+ rm -f "$(build ) /$($1_base_dir ) /.patched" ; \
509
+ fi
510
+ touch "$$@ "
482
511
endif
483
512
484
513
# Allow the module to override the destination configuration file
@@ -894,26 +923,47 @@ $(board_build)/$(CB_OUTPUT_BASENAME)-gpg-injected.rom: $(board_build)/$(CB_OUTPU
894
923
" $( board_build) /$( CB_OUTPUT_FILE_GPG_INJ) " " $( PUBKEY_ASC) "
895
924
896
925
926
+
897
927
# Dev cycles helpers:
928
+
929
+ # Helper function to overwrite coreboot git repo's .canary file with a bogus commit (.canary checked for matching commit on build)
930
+ # TODO: Implement a cleaner solution to ensure files created by patches are properly deleted instead of requiring manual intervention.
931
+ define overwrite_canary_if_coreboot_git
932
+ @echo "Checking for coreboot directory: build/${CONFIG_TARGET_ARCH}/coreboot-$(CONFIG_COREBOOT_VERSION ) "
933
+ if [ -d "build/${CONFIG_TARGET_ARCH}/coreboot-$(CONFIG_COREBOOT_VERSION ) " ] && \
934
+ [ -d "build/${CONFIG_TARGET_ARCH}/coreboot-$(CONFIG_COREBOOT_VERSION ) /.git" ]; then \
935
+ echo "INFO: Recreating .canary file for 'build/${CONFIG_TARGET_ARCH}/coreboot-$(CONFIG_COREBOOT_VERSION ) ' with placeholder." && \
936
+ echo BOGUS_COMMIT_ID > "build/${CONFIG_TARGET_ARCH}/coreboot-$(CONFIG_COREBOOT_VERSION ) /.canary" && \
937
+ echo "INFO: .canary file has been recreated." ; \
938
+ else \
939
+ echo "INFO: Coreboot directory or .git not found, skipping .canary overwrite." ; \
940
+ fi
941
+ endef
942
+
898
943
real.clean :
944
+ @echo " Cleaning build artifacts and install directories, leaving crossgcc intact."
899
945
for dir in \
900
946
$(module_dirs ) \
901
947
$(kernel_headers ) \
902
948
; do \
903
949
if [ ! -z " $$ dir" ]; then \
904
- rm -rf " build/${CONFIG_TARGET_ARCH} /$$ dir" ; \
905
- fi ; \
950
+ rm -rf " build/${CONFIG_TARGET_ARCH} /$$ dir" ; \
951
+ fi ; \
906
952
done
907
953
cd install && rm -rf -- *
954
+ $(call overwrite_canary_if_coreboot_git)
955
+
908
956
real.gitclean :
909
957
@echo " Cleaning the repository using Git ignore file as a base..."
910
958
@echo " This will wipe everything not in the Git tree, but keep downloaded coreboot forks (detected as Git repos)."
911
959
git clean -fxd
960
+ $(call overwrite_canary_if_coreboot_git)
912
961
913
962
real.gitclean_keep_packages :
914
963
@echo " Cleaning the repository using Git ignore file as a base..."
915
964
@echo " This will wipe everything not in the Git tree, but keep the 'packages' directory."
916
965
git clean -fxd -e " packages"
966
+ $(call overwrite_canary_if_coreboot_git)
917
967
918
968
real.remove_canary_files-extract_patch_rebuild_what_changed :
919
969
@echo " Removing 'canary' files to force Heads to restart building board configurations..."
@@ -924,10 +974,18 @@ real.remove_canary_files-extract_patch_rebuild_what_changed:
924
974
@echo " This approach economizes time since most build artifacts do not need to be rebuilt, as the file dates should be the same as when you originally built them."
925
975
@echo " Only a minimal time is needed for rebuilding, which is also good for your SSD."
926
976
@echo " *** USE THIS APPROACH FIRST ***"
927
- find ./build/ -type f -name " .canary" -print -delete
928
- find ./install/* /* -print -exec rm -rf {} +
977
+ @echo " Removing ./build .canary files..."
978
+ @find ./build/ -type f -name " .canary" -print -delete || true
979
+ @echo " Removing install/*/* content..."
980
+ @find ./install/* /* -print -exec rm -rf {} + 2> /dev/null || true
981
+ @echo " Removing coreboot board related artifact directory: $( build) /$( coreboot_dir) "
982
+ rm -rf " $( build) /$( coreboot_dir) "
983
+ @echo " Removing coreboot board related artifacts directory $( board_build) "
984
+ rm -rf " $( board_build) "
985
+ $(call overwrite_canary_if_coreboot_git)
929
986
930
987
real.gitclean_keep_packages_and_build :
931
988
@echo " Cleaning the repository using Git ignore file as a base..."
932
989
@echo " This will wipe everything not in the Git tree, but keep the 'packages' and 'build' directories."
933
990
git clean -fxd -e " packages" -e " build"
991
+ $(call overwrite_canary_if_coreboot_git)
0 commit comments