blob: 52625190e8c47ffd1fc763aa381c527fa8868bba [file] [log] [blame]
Jamin Lineed879f2021-12-17 15:45:25 +08001# ASPEED AST2600 devices can use Aspeed's utility 'otptool'
2# to create OTP image
3# The variables below carry default values to the create_otp()
4# function below.
5OTPTOOL_CONFIG ?= ""
6OTPTOOL_KEY_DIR ?= ""
7OTPTOOL_EXTRA_OPTS ?= ""
8OTPTOOL_EXTRA_DEPENDS ?= " socsec-native"
9DEPENDS += '${@oe.utils.conditional("SOCSEC_SIGN_ENABLE", "1", "${OTPTOOL_EXTRA_DEPENDS}", "", d)}'
10
11# Creates the OTP image
12create_otp_helper() {
13 if [ "${SOC_FAMILY}" != "aspeed-g6" ] ; then
14 bbwarn "OTP creation is only supported on AST2600 boards"
15 elif [ ! -e "${OTPTOOL_CONFIG}" ] ; then
16 bbfatal "Invalid otptool config: ${OTPTOOL_CONFIG}"
17 elif [ ! -d "${OTPTOOL_KEY_DIR}" ] ; then
18 bbfatal "Invalid otptool signing key directory: ${OTPTOOL_KEY_DIR}"
19 else
Andrew Jefferyc1c74d02022-08-08 21:05:05 +093020 otptool_config_slug="$(basename ${OTPTOOL_CONFIG} .json)"
21 otptool_config_outdir="${B}"/"${CONFIG_B_PATH}"/"${otptool_config_slug}"
22 mkdir -p "${otptool_config_outdir}"
Jamin Lineed879f2021-12-17 15:45:25 +080023 otptool make_otp_image \
24 --key_folder ${OTPTOOL_KEY_DIR} \
Andrew Jefferyc1c74d02022-08-08 21:05:05 +093025 --output_folder "${otptool_config_outdir}" \
Jamin Lineed879f2021-12-17 15:45:25 +080026 ${OTPTOOL_CONFIG} \
27 ${OTPTOOL_EXTRA_OPTS}
28
29 if [ $? -ne 0 ]; then
30 bbfatal "Generated OTP image failed."
31 fi
32
Andrew Jefferyc1c74d02022-08-08 21:05:05 +093033 otptool print "${otptool_config_outdir}"/otp-all.image
Jamin Lineed879f2021-12-17 15:45:25 +080034
35 if [ $? -ne 0 ]; then
36 bbfatal "Printed OTP image failed."
37 fi
38
Andrew Jefferyc1c74d02022-08-08 21:05:05 +093039 install -m 0644 -T \
40 "${otptool_config_outdir}"/otp-all.image \
41 ${DEPLOYDIR}/"${otptool_config_slug}"-otp-all.image
Jamin Lineed879f2021-12-17 15:45:25 +080042 fi
43}
44
45create_otp() {
46 mkdir -p ${DEPLOYDIR}
47 if [ -n "${UBOOT_CONFIG}" ]; then
48 for config in ${UBOOT_MACHINE}; do
49 CONFIG_B_PATH="${config}"
50 cd ${B}/${config}
51 create_otp_helper
52 done
53 else
54 CONFIG_B_PATH=""
55 cd ${B}
56 create_otp_helper
57 fi
58}
59
60do_deploy:prepend() {
61 if [ "${SOCSEC_SIGN_ENABLE}" = "1" ] ; then
62 create_otp
63 fi
64}