| Jamin Lin | eed879f | 2021-12-17 15:45:25 +0800 | [diff] [blame] | 1 | # 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 Jeffery | b164200 | 2022-08-08 21:45:34 +0930 | [diff] [blame] | 5 | OTPTOOL_CONFIGS ?= "" | 
| Jamin Lin | eed879f | 2021-12-17 15:45:25 +0800 | [diff] [blame] | 6 | OTPTOOL_KEY_DIR ?= "" | 
 | 7 | OTPTOOL_EXTRA_OPTS ?= "" | 
 | 8 | OTPTOOL_EXTRA_DEPENDS ?= " socsec-native" | 
 | 9 | DEPENDS += '${@oe.utils.conditional("SOCSEC_SIGN_ENABLE", "1", "${OTPTOOL_EXTRA_DEPENDS}", "", d)}' | 
 | 10 |  | 
| Andrew Jeffery | b164200 | 2022-08-08 21:45:34 +0930 | [diff] [blame] | 11 | do_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 Lin | eed879f | 2021-12-17 15:45:25 +0800 | [diff] [blame] | 37 | # Creates the OTP image | 
 | 38 | create_otp_helper() { | 
 | 39 |     if [ "${SOC_FAMILY}" != "aspeed-g6" ] ; then | 
 | 40 |         bbwarn "OTP creation is only supported on AST2600 boards" | 
| Andrew Jeffery | b164200 | 2022-08-08 21:45:34 +0930 | [diff] [blame] | 41 |     elif [ -z "${OTPTOOL_CONFIGS}" ] ; then | 
 | 42 |         bbfatal "OTPTOOL_CONFIGS is empty, no otptool configurations available" | 
| Jamin Lin | eed879f | 2021-12-17 15:45:25 +0800 | [diff] [blame] | 43 |     elif [ ! -d "${OTPTOOL_KEY_DIR}" ] ; then | 
 | 44 |         bbfatal "Invalid otptool signing key directory: ${OTPTOOL_KEY_DIR}" | 
 | 45 |     else | 
| Andrew Jeffery | b164200 | 2022-08-08 21:45:34 +0930 | [diff] [blame] | 46 |         for otptool_config in ${OTPTOOL_CONFIGS} ; do | 
 | 47 |             if [ ! -e ${otptool_config} ] ; then | 
 | 48 |                 bbfatal "Invalid otptool config: ${otptool_config}" | 
 | 49 |             fi | 
| Jamin Lin | eed879f | 2021-12-17 15:45:25 +0800 | [diff] [blame] | 50 |  | 
| Andrew Jeffery | b164200 | 2022-08-08 21:45:34 +0930 | [diff] [blame] | 51 |             do_otptool $otptool_config | 
 | 52 |         done | 
| Jamin Lin | eed879f | 2021-12-17 15:45:25 +0800 | [diff] [blame] | 53 |     fi | 
 | 54 | } | 
 | 55 |  | 
 | 56 | create_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 |  | 
 | 71 | do_deploy:prepend() { | 
 | 72 |     if [ "${SOCSEC_SIGN_ENABLE}" = "1" ] ; then | 
 | 73 |         create_otp | 
 | 74 |     fi | 
 | 75 | } |