@@ -61,57 +61,43 @@ delete_prompt() {
61
61
extract_update () {
62
62
local image_name=" $1 "
63
63
local disk_layout=" $2 "
64
- local update_path =" ${BUILD_DIR} /${image_name% _image.bin} _update.bin"
64
+ local update =" ${BUILD_DIR} /${image_name% _image.bin} _update.bin"
65
65
66
66
" ${BUILD_LIBRARY_DIR} /disk_util" --disk_layout=" ${disk_layout} " \
67
- extract " ${BUILD_DIR} /${image_name} " " USR-A" " ${update_path } "
67
+ extract " ${BUILD_DIR} /${image_name} " " USR-A" " ${update } "
68
68
69
69
# Compress image
70
- files_to_evaluate+=( " ${update_path } " )
70
+ files_to_evaluate+=( " ${update } " )
71
71
compress_disk_images files_to_evaluate
72
-
73
- # For production as well as dev builds we generate a dev-key-signed update
74
- # payload for running tests (the signature won't be accepted by production systems).
75
- local update_test=" ${BUILD_DIR} /flatcar_test_update.gz"
76
- delta_generator \
77
- -private_key " /usr/share/update_engine/update-payload-key.key.pem" \
78
- -new_image " ${update_path} " \
79
- -new_kernel " ${BUILD_DIR} /${image_name% .bin} .vmlinuz" \
80
- -out_file " ${update_test} "
81
- }
82
-
83
- zip_update_tools () {
84
- # There isn't a 'dev' variant of this zip, so always call it production.
85
- local update_zip=" flatcar_production_update.zip"
86
-
87
- info " Generating update tools zip"
88
- # Make sure some vars this script needs are exported
89
- export REPO_MANIFESTS_DIR SCRIPTS_DIR
90
- " ${BUILD_LIBRARY_DIR} /generate_au_zip.py" \
91
- --arch " $( get_sdk_arch) " --output-dir " ${BUILD_DIR} " --zip-name " ${update_zip} "
92
72
}
93
73
94
74
generate_update () {
95
75
local image_name=" $1 "
96
76
local disk_layout=" $2 "
97
77
local image_kernel=" ${BUILD_DIR} /${image_name% .bin} .vmlinuz"
98
- local update_prefix=" ${image_name% _image.bin} _update"
99
- local update=" ${BUILD_DIR} /${update_prefix} "
78
+ local update=" ${BUILD_DIR} /${image_name% _image.bin} _update.bin"
100
79
local devkey=" /usr/share/update_engine/update-payload-key.key.pem"
101
80
81
+ # Extract the partition if it isn't extracted already.
82
+ [[ -s ${update} ]] || extract_update " ${image_name} " " ${disk_layout} "
83
+
102
84
echo " Generating update payload, signed with a dev key"
103
- " ${BUILD_LIBRARY_DIR} /disk_util" --disk_layout=" ${disk_layout} " \
104
- extract " ${BUILD_DIR} /${image_name} " " USR-A" " ${update} .bin"
105
85
delta_generator \
106
86
-private_key " ${devkey} " \
107
- -new_image " ${update} .bin " \
87
+ -new_image " ${update} " \
108
88
-new_kernel " ${image_kernel} " \
109
- -out_file " ${update} .gz"
89
+ -out_file " ${BUILD_DIR} /flatcar_test_update.gz"
90
+ }
110
91
111
- # Compress image
112
- declare -a files_to_evaluate
113
- files_to_evaluate+=( " ${update} .bin" )
114
- compress_disk_images files_to_evaluate
92
+ zip_update_tools () {
93
+ # There isn't a 'dev' variant of this zip, so always call it production.
94
+ local update_zip=" flatcar_production_update.zip"
95
+
96
+ info " Generating update tools zip"
97
+ # Make sure some vars this script needs are exported
98
+ local -x REPO_MANIFESTS_DIR SCRIPTS_DIR
99
+ " ${BUILD_LIBRARY_DIR} /generate_au_zip.py" \
100
+ --arch " $( get_sdk_arch) " --output-dir " ${BUILD_DIR} " --zip-name " ${update_zip} "
115
101
}
116
102
117
103
# ldconfig cannot generate caches for non-native arches.
@@ -805,10 +791,12 @@ EOF
805
791
seek=${verity_offset} count=64 bs=1 status=none
806
792
fi
807
793
808
- # Sign the kernel after /usr is in a consistent state and verity is calculated
809
- [[ ${COREOS_OFFICIAL:- 0} -ne 1 ]] && \
810
- do_sbsign --output " ${root_fs_dir} /boot/flatcar/vmlinuz-a" {,}
811
- cleanup_sbsign_certs
794
+ # Sign the kernel after /usr is in a consistent state and verity is
795
+ # calculated. Only for unofficial builds as official builds get signed later.
796
+ if [[ ${COREOS_OFFICIAL:- 0} -ne 1 ]]; then
797
+ do_sbsign --output " ${root_fs_dir} /boot/flatcar/vmlinuz-a" {,}
798
+ cleanup_sbsign_certs
799
+ fi
812
800
813
801
if [[ -n " ${image_kernel} " ]]; then
814
802
# copying kernel from vfat so ignore the permissions
894
882
cleanup_mounts " ${root_fs_dir} "
895
883
trap - EXIT
896
884
}
885
+
886
+ sbsign_image () {
887
+ local image_name=" $1 "
888
+ local disk_layout=" $2 "
889
+ local root_fs_dir=" $3 "
890
+ local image_kernel=" $4 "
891
+ local pcr_policy=" $5 "
892
+ local image_grub=" $6 "
893
+
894
+ local disk_img=" ${BUILD_DIR} /${image_name} "
895
+ local EFI_ARCH
896
+
897
+ case " ${BOARD} " in
898
+ amd64-usr) EFI_ARCH=" x64" ;;
899
+ arm64-usr) EFI_ARCH=" aa64" ;;
900
+ * ) die " Unknown board ${BOARD@ Q} " ;;
901
+ esac
902
+
903
+ " ${BUILD_LIBRARY_DIR} /disk_util" --disk_layout=" ${disk_layout} " \
904
+ mount " ${disk_img} " " ${root_fs_dir} "
905
+ trap " cleanup_mounts '${root_fs_dir} '; cleanup_sbsign_certs" EXIT
906
+
907
+ # Sign the kernel with the shim-embedded key.
908
+ do_sbsign --output " ${root_fs_dir} /boot/flatcar/vmlinuz-a" {,}
909
+
910
+ if [[ -n " ${image_kernel} " ]]; then
911
+ # copying kernel from vfat so ignore the permissions
912
+ cp --no-preserve=mode \
913
+ " ${root_fs_dir} /boot/flatcar/vmlinuz-a" \
914
+ " ${BUILD_DIR} /${image_kernel} "
915
+ fi
916
+
917
+ # Sign GRUB and mokmanager(mm) with the shim-embedded key.
918
+ do_sbsign --output " ${root_fs_dir} /boot/EFI/boot/grub${EFI_ARCH} .efi" {,}
919
+ do_sbsign --output " ${root_fs_dir} /boot/EFI/boot/mm${EFI_ARCH} .efi" {,}
920
+
921
+ # copying from vfat so ignore permissions
922
+ if [[ -n " ${image_grub} " ]]; then
923
+ cp --no-preserve=mode " ${root_fs_dir} /boot/EFI/boot/grub${EFI_ARCH} .efi" \
924
+ " ${BUILD_DIR} /${image_grub} "
925
+ fi
926
+
927
+ if [[ -n " ${pcr_policy} " ]]; then
928
+ mkdir -p " ${BUILD_DIR} /pcrs"
929
+ " ${BUILD_LIBRARY_DIR} " /generate_kernel_hash.py \
930
+ " ${root_fs_dir} /boot/flatcar/vmlinuz-a" " ${FLATCAR_VERSION} " \
931
+ > " ${BUILD_DIR} /pcrs/kernel.config"
932
+ fi
933
+
934
+ cleanup_mounts " ${root_fs_dir} "
935
+ cleanup_sbsign_certs
936
+ trap - EXIT
937
+
938
+ if [[ -n " ${pcr_policy} " ]]; then
939
+ " ${BUILD_LIBRARY_DIR} " /generate_grub_hashes.py \
940
+ " ${disk_img} " /usr/lib/grub/ " ${BUILD_DIR} /pcrs" " ${FLATCAR_VERSION} "
941
+
942
+ info " Generating $pcr_policy "
943
+ pushd " ${BUILD_DIR} " > /dev/null
944
+ zip --quiet -r -9 " ${BUILD_DIR} /${pcr_policy} " pcrs
945
+ popd > /dev/null
946
+ rm -rf " ${BUILD_DIR} /pcrs"
947
+ fi
948
+ }
0 commit comments