blob: bb05e643211d79c49ad31e059c9601616afb8a74 [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.
Andrew Jefferyb1642002022-08-08 21:45:34 +09305OTPTOOL_CONFIGS ?= ""
Jamin Lineed879f2021-12-17 15:45:25 +08006OTPTOOL_KEY_DIR ?= ""
Neal Liue22ad5b2022-09-02 15:22:23 +08007OTPTOOL_USER_DIR ?= ""
Jamin Lineed879f2021-12-17 15:45:25 +08008OTPTOOL_EXTRA_OPTS ?= ""
9OTPTOOL_EXTRA_DEPENDS ?= " socsec-native"
10DEPENDS += '${@oe.utils.conditional("SOCSEC_SIGN_ENABLE", "1", "${OTPTOOL_EXTRA_DEPENDS}", "", d)}'
11
Andrew Jefferyb1642002022-08-08 21:45:34 +093012do_otptool() {
13 local otptool_config=$1
14 otptool_config_slug="$(basename ${otptool_config} .json)"
15 otptool_config_outdir="${B}"/"${CONFIG_B_PATH}"/"${otptool_config_slug}"
Neal Liue22ad5b2022-09-02 15:22:23 +080016 otptool_user_folder="$([ -n "${OTPTOOL_USER_DIR}" ] && echo --user_data_folder ${OTPTOOL_USER_DIR})"
Andrew Jefferyb1642002022-08-08 21:45:34 +093017 mkdir -p "${otptool_config_outdir}"
18 otptool make_otp_image \
19 --key_folder ${OTPTOOL_KEY_DIR} \
20 --output_folder "${otptool_config_outdir}" \
Neal Liue22ad5b2022-09-02 15:22:23 +080021 ${otptool_user_folder} \
Andrew Jefferyb1642002022-08-08 21:45:34 +093022 ${otptool_config} \
23 ${OTPTOOL_EXTRA_OPTS}
24
25 if [ $? -ne 0 ]; then
26 bbfatal "Generated OTP image failed."
27 fi
28
29 otptool print "${otptool_config_outdir}"/otp-all.image
30
31 if [ $? -ne 0 ]; then
32 bbfatal "Printed OTP image failed."
33 fi
34
35 install -m 0644 -T \
36 "${otptool_config_outdir}"/otp-all.image \
37 ${DEPLOYDIR}/"${otptool_config_slug}"-otp-all.image
38}
39
Jamin Lineed879f2021-12-17 15:45:25 +080040# Creates the OTP image
41create_otp_helper() {
42 if [ "${SOC_FAMILY}" != "aspeed-g6" ] ; then
43 bbwarn "OTP creation is only supported on AST2600 boards"
Andrew Jefferyb1642002022-08-08 21:45:34 +093044 elif [ -z "${OTPTOOL_CONFIGS}" ] ; then
45 bbfatal "OTPTOOL_CONFIGS is empty, no otptool configurations available"
Jamin Lineed879f2021-12-17 15:45:25 +080046 elif [ ! -d "${OTPTOOL_KEY_DIR}" ] ; then
47 bbfatal "Invalid otptool signing key directory: ${OTPTOOL_KEY_DIR}"
48 else
Andrew Jefferyb1642002022-08-08 21:45:34 +093049 for otptool_config in ${OTPTOOL_CONFIGS} ; do
50 if [ ! -e ${otptool_config} ] ; then
51 bbfatal "Invalid otptool config: ${otptool_config}"
52 fi
Jamin Lineed879f2021-12-17 15:45:25 +080053
Andrew Jefferyb1642002022-08-08 21:45:34 +093054 do_otptool $otptool_config
55 done
Jamin Lineed879f2021-12-17 15:45:25 +080056 fi
57}
58
59create_otp() {
60 mkdir -p ${DEPLOYDIR}
61 if [ -n "${UBOOT_CONFIG}" ]; then
62 for config in ${UBOOT_MACHINE}; do
63 CONFIG_B_PATH="${config}"
64 cd ${B}/${config}
65 create_otp_helper
66 done
67 else
68 CONFIG_B_PATH=""
69 cd ${B}
70 create_otp_helper
71 fi
72}
73
74do_deploy:prepend() {
75 if [ "${SOCSEC_SIGN_ENABLE}" = "1" ] ; then
76 create_otp
77 fi
78}