hololake-system-architecture/product-source/hololake-platform/guanghu-os/scripts/build-native-final-resident-candidate.sh

52 lines
1.7 KiB
Shell
Executable file

#!/usr/bin/env bash
set -euo pipefail
[[ $# -eq 3 ]] || {
echo "usage: build-native-final-resident-candidate.sh <world-root> <output-directory> <recovery-token-file>" >&2
exit 64
}
world_root=$(readlink -f "$1")
output_root=$(readlink -m "$2")
token_file=$(readlink -f "$3")
source_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
native_root=${source_root}/native/x86_64-bios
command -v nasm >/dev/null
token_hex=$(tr -d '\r\n ' <"${token_file}")
[[ ${token_hex} =~ ^[0-9a-fA-F]{32}$ ]] || {
echo "recovery token must be exactly 16 bytes encoded as 32 hexadecimal characters" >&2
exit 65
}
mkdir -p "${output_root}"
chmod 0700 "${output_root}"
cargo run --quiet --manifest-path "${source_root}/Cargo.toml" \
-p hldp-native-compiler -- "${world_root}" "${output_root}/world.inc"
{
printf 'ghal_recovery_capability: db '
for index in $(seq 0 15); do
[[ ${index} -eq 0 ]] || printf ','
printf '0x%s' "${token_hex:$((index * 2)):2}"
done
printf '\n'
} >"${output_root}/recovery-token.inc"
chmod 0600 "${output_root}/recovery-token.inc"
layout_args=()
while IFS= read -r argument; do layout_args+=("${argument}"); done \
< <("${source_root}/scripts/native-layout-nasm-args.sh" "${world_root}")
(
cd "${output_root}"
nasm -f bin -I "${output_root}/" -I "${native_root}/" \
"${layout_args[@]}" \
-dGHOS_PHYSICAL_CANDIDATE=1 \
-dGHOS_NATIVE_RESIDENT=1 \
-dGHOS_NATIVE_FINAL_RESIDENT=1 \
-dGHOS_NATIVE_ANCHOR_SERVICE=1 \
"${native_root}/boot.asm" \
-o guanghu-os-x86_64-bios-final-resident.img
)
[[ $(stat -c %s "${output_root}/guanghu-os-x86_64-bios-final-resident.img") -eq 14848 ]]
sha256sum "${output_root}/guanghu-os-x86_64-bios-final-resident.img" \
>"${output_root}/guanghu-os-x86_64-bios-final-resident.img.sha256"