Basic build script & process changes

This commit is contained in:
Xilin Wu
2022-11-21 23:01:35 +08:00
parent ff4902fa2b
commit 1076bacfb4
8 changed files with 134 additions and 174 deletions

1
.gitignore vendored
View File

@@ -10,3 +10,4 @@ ramdisk
*.swp
*.rej
*.orig
*_FLASH.img

260
build.sh
View File

@@ -3,25 +3,19 @@
function _help(){
echo "Usage: build.sh --device DEV"
echo
echo "Build edk2 for Qualcomm Snapdragon platforms."
echo "Build edk2 for Rockchip RK35xx platforms."
echo
echo "Options: "
echo " --device DEV, -d DEV: build for DEV."
echo " --all, -a: build all devices."
echo " --chinese, -c: use hub.fastgit.xyz for submodule cloning."
echo " --release MODE, -r MODE: Release mode for building, default is 'RELEASE', 'DEBUG' alternatively."
echo " --toolchain TOOLCHAIN: Set toolchain, default is 'CLANG38'."
echo " --uart, -u: compile with UART support, print debug messages to uart debug port."
echo " --skip-rootfs-gen: skip generating SimpleInit rootfs to speed up building."
echo " --no-exception-disp: do not display exception information in DEBUG builds"
echo " --acpi, -A: compile DSDT using MS asl with wine"
echo " --release MODE, -r MODE: Release mode for building, default is 'DEBUG', 'RELEASE' alternatively."
echo " --toolchain TOOLCHAIN: Set toolchain, default is 'GCC5'."
# echo " --skip-rootfs-gen: skip generating SimpleInit rootfs to speed up building."
echo " --clean, -C: clean workspace and output."
echo " --distclean, -D: clean up all files that are not in repo."
echo " --outputdir, -O: output folder."
echo " --boot, -b: fastboot boot image."
echo " --help, -h: show this help."
echo
echo "MainPage: https://github.com/edk2-porting/edk2-msm"
exit "${1}"
}
@@ -42,63 +36,55 @@ function _load_platform_hooks(){
fi
}
function _fit_repack(){
mkdir -p ${WORKSPACE}/unpack
# BL33_AP_UEFI is PrePi executable
cp ${WORKSPACE}/Build/${PLATFORM_NAME}/${_MODE}_${TOOLCHAIN}/FV/BL33_AP_UEFI.Fv ${WORKSPACE}/unpack/uboot
cp ${ROOTDIR}/misc/prebuilts/uboot_uefi.img ${WORKSPACE}/
pushd ${ROOTDIR}/../git/u-boot
./scripts/fit-repack.sh -f ${WORKSPACE}/uboot_uefi.img -d ${WORKSPACE}/unpack/
popd
}
function _pack(){
_fit_repack
echo "****Build 8MB NOR FLASH IMAGE****"
cp ${WORKSPACE}/Build/${PLATFORM_NAME}/${_MODE}_${TOOLCHAIN}/FV/NOR_FLASH_IMAGE.fd ${WORKSPACE}/RK3588_NOR_FLASH.img
# backup NV_DATA at 0x007C0000
dd if=${WORKSPACE}/RK3588_NOR_FLASH.img of=${WORKSPACE}/NV_DATA.img bs=1K skip=7936
# might be GPT table? size:0x4400
dd if=${ROOTDIR}/misc/rk3588_spi_nor_gpt.img of=${WORKSPACE}/RK3588_NOR_FLASH.img
# idblock at 0x8000 and 0x88000
dd if=${ROOTDIR}/misc/prebuilts/idblock.bin of=${WORKSPACE}/RK3588_NOR_FLASH.img bs=1K seek=32
dd if=${ROOTDIR}/misc/prebuilts/idblock.bin of=${WORKSPACE}/RK3588_NOR_FLASH.img bs=1K seek=544
# FIT Image at 0x100000
dd if=${WORKSPACE}/uboot_uefi.img of=${WORKSPACE}/RK3588_NOR_FLASH.img bs=1K seek=1024
# restore NV_DATA at 0x007C0000
dd if=${WORKSPACE}/NV_DATA.img of=${WORKSPACE}/RK3588_NOR_FLASH.img bs=1K seek=7936
cp ${WORKSPACE}/RK3588_NOR_FLASH.img ${ROOTDIR}/
echo "Build done: RK3588_NOR_FLASH.img"
}
function _build(){
local DEVICE="${1}"
shift
source "${_EDK2}/edksetup.sh"
source "${ROOTDIR}/edk2/edksetup.sh"
[ -d "${WORKSPACE}" ]||mkdir "${WORKSPACE}"
set -x
make -C "${_EDK2}/BaseTools"||exit "$?"
make -C "${ROOTDIR}/edk2/BaseTools"||exit "$?"
SPLIT_DSDT=false
EXT=""
if [ -f "configs/devices/${DEVICE}.conf" ]
then source "configs/devices/${DEVICE}.conf"
if [ -f "configs/${DEVICE}.conf" ]
then source "configs/${DEVICE}.conf"
else _error "Device configuration not found"
fi
typeset -l SOC_PLATFORM_L="$SOC_PLATFORM"
if [ -f "configs/${SOC_PLATFORM_L}.conf" ]
then source "configs/${SOC_PLATFORM_L}.conf"
else _error "SoC configuration not found"
fi
# for overriding config
source "configs/devices/${DEVICE}.conf"
_load_platform_hooks Platform/platform.sh.inc
_load_platform_hooks Silicon/platform.sh.inc
_load_platform_hooks "Silicon/${SOC_VENDOR}/platform.sh.inc"
_load_platform_hooks "Platform/${VENDOR_NAME}/platform.sh.inc"
_load_platform_hooks "Silicon/${SOC_VENDOR}/${SOC_PLATFORM_L}/platform.sh.inc"
_load_platform_hooks "Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/platform.sh.inc"
_load_platform_hooks "Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/${PLATFORM_NAME}.sh.inc"
_load_platform_hooks "Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/${DEVICE}.sh.inc"
_call_hook platform_pre_acpi||return "$?"
if "${GEN_ACPI}"
then
if "${SPLIT_DSDT}"
then
rm -rf "${WORKSPACE}/Build/${DEVICE}/ACPI"
mkdir -p "${WORKSPACE}/Build/${DEVICE}/ACPI"
pushd "${WORKSPACE}/Build/${DEVICE}/ACPI"
cp "${ROOTDIR}/Silicon/${SOC_VENDOR}/${SOC_PLATFORM_L}/AcpiTables"/* ./
if compgen -G "${ROOTDIR}/Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/AcpiTables/*.asl" > /dev/null; then
cp "${ROOTDIR}/Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/AcpiTables/"*.asl ./
fi
cp "${ROOTDIR}/Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/AcpiTables/${DEVICE}/"* ./
if [ "${USE_IASL}" == "true" ]
then iasl -ve Dsdt.asl ||_error "iasl failed"
else wine "${ROOTDIR}/tools/asl-x64.exe" Dsdt.asl ||_error "asl.exe failed"
fi
test -e DSDT.aml && cp DSDT.aml "${ROOTDIR}/Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/AcpiTables/${DEVICE}/DSDT.aml"
test -e DSDT.AML && cp DSDT.AML "${ROOTDIR}/Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/AcpiTables/${DEVICE}/DSDT.aml"
popd
else
_error "Building DSDT is unsupported for this device"
fi
fi
# _load_platform_hooks Platform/platform.sh.inc
# _load_platform_hooks Silicon/platform.sh.inc
# based on the instructions from edk2-platform
rm -f "${OUTDIR}/boot-${DEVICE}${EXT}.img" "${OUTDIR}/uefi-${DEVICE}"*
@@ -108,30 +94,22 @@ function _build(){
*) _MODE=DEBUG;;
esac
echo "Building BootShim"
pushd "${ROOTDIR}/tools/BootShim"
rm -f BootShim.bin BootShim.elf
make UEFI_BASE=${FD_BASE} UEFI_SIZE=${FD_SIZE}
popd
# _call_hook platform_pre_build||return "$?"
_call_hook platform_pre_build||return "$?"
cp "${ROOTDIR}/tools/"{build_rule.txt,tools_def.txt} "${ROOTDIR}/Common/edk2/Conf/"
build \
-s \
-n 0 \
-a AARCH64 \
-t "${TOOLCHAIN}" \
-p "${ROOTDIR}/Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/${PLATFORM_NAME}.dsc" \
-p "${ROOTDIR}/${DSC_FILE}" \
-b "${_MODE}" \
-D SECURE_BOOT_ENABLE=true \
-D FIRMWARE_VER="${GITCOMMIT}" \
-D USE_UART="${USE_UART}" \
-D NO_EXCEPTION_DISPLAY="${NO_EXCEPTION_DISPLAY}" \
-D FD_BASE="${FD_BASE}" -D FD_SIZE="${FD_SIZE}" \
||return "$?"
_call_hook platform_build_kernel||return "$?"
_call_hook platform_build_bootimg||return "$?"
echo "Build done: ${OUTDIR}/boot-${DEVICE}${EXT}.img"
_pack
# _call_hook platform_build_kernel||return "$?"
# echo "Build done: ${OUTDIR}/boot-${DEVICE}${EXT}.img"
set +x
}
@@ -145,35 +123,24 @@ cd "${ROOTDIR}"||exit 1
typeset -l DEVICE
typeset -u MODE
DEVICE=""
MODE=RELEASE
CHINESE=false
MODE=DEBUG
CLEAN=false
DISTCLEAN=false
TOOLCHAIN=CLANG38
SOC_VENDOR=Qualcomm
USE_UART=0
NO_EXCEPTION_DISPLAY=0
export ROOTDIR OUTDIR SOC_VENDOR
export GEN_ACPI=false
TOOLCHAIN=GCC5
export ROOTDIR OUTDIR
export GEN_ROOTFS=true
export FASTBOOT=false
OPTS="$(getopt -o t:d:habcACDO:r:u -l toolchain:,device:,help,all,boot,chinese,acpi,skip-rootfs-gen,no-exception-disp,uart,clean,distclean,outputdir:,release: -n 'build.sh' -- "$@")"||exit 1
OPTS="$(getopt -o t:d:haCDO:r -l toolchain:,device:,help,all,skip-rootfs-gen,clean,distclean,outputdir:,release: -n 'build.sh' -- "$@")"||exit 1
eval set -- "${OPTS}"
while true
do case "${1}" in
-d|--device) DEVICE="${2}";shift 2;;
-a|--all) DEVICE=all;shift;;
-b|--boot) FASTBOOT=true;shift;;
-c|--chinese) CHINESE=true;shift;;
-A|--acpi) GEN_ACPI=true;shift;;
-C|--clean) CLEAN=true;shift;;
-D|--distclean) DISTCLEAN=true;shift;;
-O|--outputdir) OUTDIR="${2}";shift 2;;
--skip-rootfs-gen) GEN_ROOTFS=false;shift;;
--no-exception-disp) NO_EXCEPTION_DISPLAY=1;shift;;
-r|--release) MODE="${2}";shift 2;;
-t|--toolchain) TOOLCHAIN="${2}";shift 2;;
-u|--uart) USE_UART=1;shift;;
-h|--help) _help 0;shift;;
--) shift;break;;
*) _help 1;;
@@ -182,102 +149,52 @@ done
if "${DISTCLEAN}";then _distclean;exit "$?";fi
if "${CLEAN}";then _clean;exit "$?";fi
[ -z "${DEVICE}" ]&&_help 1
if ! [ -f Common/edk2/edksetup.sh ] && ! [ -f ../edk2/edksetup.sh ]
then
set -e
echo "Updating submodules"
if "${CHINESE}"
then
git submodule set-url Common/edk2 https://hub.fastgit.xyz/tianocore/edk2.git
git submodule set-url Common/edk2-platforms https://hub.fastgit.xyz/tianocore/edk2-platforms.git
git submodule set-url Platform/EFI_Binaries https://hub.fastgit.xyz/edk2-porting/edk2-sdm845-binary.git
git submodule set-url Platform/RenegadePkg/Library/SimpleInit https://hub.fastgit.xyz/BigfootACA/simple-init.git
git submodule init;git submodule update --depth 1
pushd Common/edk2
git submodule set-url ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3 https://hub.fastgit.xyz/ucb-bar/berkeley-softfloat-3.git
git submodule set-url CryptoPkg/Library/OpensslLib/openssl https://hub.fastgit.xyz/openssl/openssl.git
git submodule set-url BaseTools/Source/C/BrotliCompress/brotli https://hub.fastgit.xyz/google/brotli.git
git submodule set-url UnitTestFrameworkPkg/Library/CmockaLib/cmocka https://hub.fastgit.xyz/tianocore/edk2-cmocka.git
git submodule set-url ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3 https://hub.fastgit.xyz/ucb-bar/berkeley-softfloat-3.git
git submodule set-url MdeModulePkg/Library/BrotliCustomDecompressLib/brotli https://hub.fastgit.xyz/google/brotli.git
git submodule set-url MdeModulePkg/Universal/RegularExpressionDxe/oniguruma https://hub.fastgit.xyz/kkos/oniguruma.git
git submodule set-url RedfishPkg/Library/JsonLib/jansson https://hub.fastgit.xyz/akheron/jansson.git
git submodule init;git submodule update
git checkout .gitmodules
popd
pushd Platform/RenegadePkg/Library/SimpleInit
git submodule set-url libs/lvgl https://hub.fastgit.xyz/lvgl/lvgl.git
git submodule set-url libs/freetype https://hub.fastgit.xyz/freetype/freetype.git
git submodule init;git submodule update
popd
git checkout .gitmodules
else
git submodule init;git submodule update --depth 1
pushd Common/edk2
git submodule init;git submodule update
popd
pushd Platform/RenegadePkg/Library/SimpleInit
git submodule init;git submodule update
popd
fi
echo "SKIP Updating submodules"
set +e
fi
for i in "${EDK2}" ./Common/edk2 ../edk2
do
if [ -n "${i}" ]&&[ -f "${i}/edksetup.sh" ]
then
_EDK2="$(realpath "${i}")"
break
fi
done
for i in "${EDK2_PLATFORMS}" ./Common/edk2-platforms ../edk2-platforms
do
if [ -n "${i}" ]&&[ -d "${i}/Platform" ]
then
_EDK2_PLATFORMS="$(realpath "${i}")"
break
fi
done
for i in "${SIMPLE_INIT}" Platform/RenegadePkg/Library/SimpleInit ./simple-init ../simple-init
do
if [ -n "${i}" ]&&[ -f "${i}/SimpleInit.inc" ]
then
_SIMPLE_INIT="$(realpath "${i}")"
break
fi
done
[ -n "${_EDK2}" ]||_error "EDK2 not found, please see README.md"
[ -n "${_EDK2_PLATFORMS}" ]||_error "EDK2 Platforms not found, please see README.md"
[ -n "${_SIMPLE_INIT}" ]||_error "SimpleInit not found, please see README.md"
[ -f "configs/devices/${DEVICE}.conf" ]||_error "Device configuration not found"
echo "EDK2 Path: ${_EDK2}"
echo "EDK2_PLATFORMS Path: ${_EDK2_PLATFORMS}"
# for i in "${SIMPLE_INIT}" Platform/RenegadePkg/Library/SimpleInit ./simple-init ../simple-init
# do
# if [ -n "${i}" ]&&[ -f "${i}/SimpleInit.inc" ]
# then
# _SIMPLE_INIT="$(realpath "${i}")"
# break
# fi
# done
# [ -n "${_SIMPLE_INIT}" ]||_error "SimpleInit not found, please see README.md"
[ -f "configs/${DEVICE}.conf" ]||_error "Device configuration not found"
export CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}"
export GCC5_AARCH64_PREFIX="${CROSS_COMPILE}"
export CLANG38_AARCH64_PREFIX="${CROSS_COMPILE}"
export PACKAGES_PATH="$_EDK2:$_EDK2_PLATFORMS:$_SIMPLE_INIT:$PWD"
# export PACKAGES_PATH="$_EDK2:$_EDK2_PLATFORMS:$_SIMPLE_INIT:$PWD"
export PACKAGES_PATH="${ROOTDIR}/edk2:${ROOTDIR}/edk2-platforms:${ROOTDIR}/edk2-non-osi:${ROOTDIR}"
export WORKSPACE="${OUTDIR}/workspace"
GITCOMMIT="$(git describe --tags --always)"||GITCOMMIT="unknown"
export GITCOMMIT
echo > ramdisk
set -e
mkdir -p "${_SIMPLE_INIT}/build" "${_SIMPLE_INIT}/root/usr/share/locale"
for i in "${_SIMPLE_INIT}/po/"*.po
do
[ -f "${i}" ]||continue
_name="$(basename "$i" .po)"
_path="${_SIMPLE_INIT}/root/usr/share/locale/${_name}/LC_MESSAGES"
mkdir -p "${_path}"
msgfmt -o "${_path}/simple-init.mo" "${i}"
done
if "${GEN_ROOTFS}"
then
bash "${_SIMPLE_INIT}/scripts/gen-rootfs-source.sh" \
"${_SIMPLE_INIT}" \
"${_SIMPLE_INIT}/build"
fi
# mkdir -p "${_SIMPLE_INIT}/build" "${_SIMPLE_INIT}/root/usr/share/locale"
# for i in "${_SIMPLE_INIT}/po/"*.po
# do
# [ -f "${i}" ]||continue
# _name="$(basename "$i" .po)"
# _path="${_SIMPLE_INIT}/root/usr/share/locale/${_name}/LC_MESSAGES"
# mkdir -p "${_path}"
# msgfmt -o "${_path}/simple-init.mo" "${i}"
# done
# if "${GEN_ROOTFS}"
# then
# bash "${_SIMPLE_INIT}/scripts/gen-rootfs-source.sh" \
# "${_SIMPLE_INIT}" \
# "${_SIMPLE_INIT}/build"
# fi
if [ "${DEVICE}" == "all" ]
then
@@ -292,8 +209,3 @@ then
else
_build "${DEVICE}"
fi
if "${FASTBOOT}"
then
fastboot boot ${OUTDIR}/boot-${DEVICE}${EXT}.img
fi

2
configs/rk3588-evb.conf Normal file
View File

@@ -0,0 +1,2 @@
DSC_FILE=edk2-platforms/Platform/Rockchip/RK3588/RK3588.dsc
PLATFORM_NAME=RK3588

BIN
misc/prebuilts/idblock.bin Normal file

Binary file not shown.

Binary file not shown.

34
misc/repack.sh Executable file
View File

@@ -0,0 +1,34 @@
#!/bin/bash
# Used to pack any executable into a complete flash image
function _fit_repack(){
mkdir -p ${WORKSPACE}/unpack
cp ${REPACK_FILE} ${WORKSPACE}/unpack/uboot
cp ${ROOTDIR}/misc/prebuilts/uboot_uefi.img ${WORKSPACE}/
pushd ${ROOTDIR}/../git/u-boot
./scripts/fit-repack.sh -f ${WORKSPACE}/uboot_uefi.img -d ${WORKSPACE}/unpack/
popd
}
function _pack(){
_fit_repack
echo "****Build 8MB NOR FLASH IMAGE****"
# FIT Image at 0x100000
dd if=${WORKSPACE}/uboot_uefi.img of=${WORKSPACE}/RK3588_NOR_FLASH.img bs=1K seek=1024
cp ${WORKSPACE}/RK3588_NOR_FLASH.img ${ROOTDIR}/
echo "Build done: RK3588_NOR_FLASH.img"
}
ROOTDIR="$(realpath "$(dirname "$0")")/.."
cd "${ROOTDIR}"||exit 1
REPACK_FILE=${1}
export ROOTDIR REPACK_FILE
WORKSPACE="${ROOTDIR}/workspace"
_pack

BIN
misc/rk3588_spi_nor_gpt.img Normal file

Binary file not shown.

View File

@@ -0,0 +1,11 @@
FIRMWARE_VER: 12.0
MACHINE_MODEL: rk3588_s
MACHINE_ID: 007
MANUFACTURER: rockchip
MAGIC: 0x5041524B
ATAG: 0x00200800
MACHINE: rk3588_s
CHECK_MASK: 0x80
PWR_HLD: 0,0,A,0,1
TYPE: GPT
CMDLINE:mtdparts=rk29xxnand:0x00004000@0x00000800(uboot)