blob: 7da3e6ea8105c6e4b22a999c611a965780633e3c [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 ?= ""
7OTPTOOL_EXTRA_OPTS ?= ""
8OTPTOOL_EXTRA_DEPENDS ?= " socsec-native"
9DEPENDS += '${@oe.utils.conditional("SOCSEC_SIGN_ENABLE", "1", "${OTPTOOL_EXTRA_DEPENDS}", "", d)}'
10
Andrew Jefferyb1642002022-08-08 21:45:34 +093011do_otptool() {
12 local otptool_config=$1
13 otptool_config_slug="$(basename ${otptool_config} .json)"
14 otptool_config_outdir="${B}"/"${CONFIG_B_PATH}"/"${otptool_config_slug}"
15 mkdir -p "${otptool_config_outdir}"
16 otptool make_otp_image \
17 --key_folder ${OTPTOOL_KEY_DIR} \
18 --output_folder "${otptool_config_outdir}" \
19 ${otptool_config} \
20 ${OTPTOOL_EXTRA_OPTS}
21
22 if [ $? -ne 0 ]; then
23 bbfatal "Generated OTP image failed."
24 fi
25
26 otptool print "${otptool_config_outdir}"/otp-all.image
27
28 if [ $? -ne 0 ]; then
29 bbfatal "Printed OTP image failed."
30 fi
31
32 install -m 0644 -T \
33 "${otptool_config_outdir}"/otp-all.image \
34 ${DEPLOYDIR}/"${otptool_config_slug}"-otp-all.image
35}
36
Jamin Lineed879f2021-12-17 15:45:25 +080037# Creates the OTP image
38create_otp_helper() {
39 if [ "${SOC_FAMILY}" != "aspeed-g6" ] ; then
40 bbwarn "OTP creation is only supported on AST2600 boards"
Andrew Jefferyb1642002022-08-08 21:45:34 +093041 elif [ -z "${OTPTOOL_CONFIGS}" ] ; then
42 bbfatal "OTPTOOL_CONFIGS is empty, no otptool configurations available"
Jamin Lineed879f2021-12-17 15:45:25 +080043 elif [ ! -d "${OTPTOOL_KEY_DIR}" ] ; then
44 bbfatal "Invalid otptool signing key directory: ${OTPTOOL_KEY_DIR}"
45 else
Andrew Jefferyb1642002022-08-08 21:45:34 +093046 for otptool_config in ${OTPTOOL_CONFIGS} ; do
47 if [ ! -e ${otptool_config} ] ; then
48 bbfatal "Invalid otptool config: ${otptool_config}"
49 fi
Jamin Lineed879f2021-12-17 15:45:25 +080050
Andrew Jefferyb1642002022-08-08 21:45:34 +093051 do_otptool $otptool_config
52 done
Jamin Lineed879f2021-12-17 15:45:25 +080053 fi
54}
55
56create_otp() {
57 mkdir -p ${DEPLOYDIR}
58 if [ -n "${UBOOT_CONFIG}" ]; then
59 for config in ${UBOOT_MACHINE}; do
60 CONFIG_B_PATH="${config}"
61 cd ${B}/${config}
62 create_otp_helper
63 done
64 else
65 CONFIG_B_PATH=""
66 cd ${B}
67 create_otp_helper
68 fi
69}
70
71do_deploy:prepend() {
72 if [ "${SOCSEC_SIGN_ENABLE}" = "1" ] ; then
73 create_otp
74 fi
75}