| 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 ?= "" | 
| Neal Liu | e22ad5b | 2022-09-02 15:22:23 +0800 | [diff] [blame] | 7 | OTPTOOL_USER_DIR ?= "" | 
| Jamin Lin | eed879f | 2021-12-17 15:45:25 +0800 | [diff] [blame] | 8 | OTPTOOL_EXTRA_OPTS ?= "" | 
|  | 9 | OTPTOOL_EXTRA_DEPENDS ?= " socsec-native" | 
|  | 10 | DEPENDS += '${@oe.utils.conditional("SOCSEC_SIGN_ENABLE", "1", "${OTPTOOL_EXTRA_DEPENDS}", "", d)}' | 
|  | 11 |  | 
| Andrew Jeffery | b164200 | 2022-08-08 21:45:34 +0930 | [diff] [blame] | 12 | do_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 Liu | e22ad5b | 2022-09-02 15:22:23 +0800 | [diff] [blame] | 16 | otptool_user_folder="$([ -n "${OTPTOOL_USER_DIR}" ] && echo --user_data_folder ${OTPTOOL_USER_DIR})" | 
| Andrew Jeffery | b164200 | 2022-08-08 21:45:34 +0930 | [diff] [blame] | 17 | mkdir -p "${otptool_config_outdir}" | 
|  | 18 | otptool make_otp_image \ | 
|  | 19 | --key_folder ${OTPTOOL_KEY_DIR} \ | 
|  | 20 | --output_folder "${otptool_config_outdir}" \ | 
| Neal Liu | e22ad5b | 2022-09-02 15:22:23 +0800 | [diff] [blame] | 21 | ${otptool_user_folder} \ | 
| Andrew Jeffery | b164200 | 2022-08-08 21:45:34 +0930 | [diff] [blame] | 22 | ${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 Lin | eed879f | 2021-12-17 15:45:25 +0800 | [diff] [blame] | 40 | # Creates the OTP image | 
|  | 41 | create_otp_helper() { | 
|  | 42 | if [ "${SOC_FAMILY}" != "aspeed-g6" ] ; then | 
|  | 43 | bbwarn "OTP creation is only supported on AST2600 boards" | 
| Andrew Jeffery | b164200 | 2022-08-08 21:45:34 +0930 | [diff] [blame] | 44 | elif [ -z "${OTPTOOL_CONFIGS}" ] ; then | 
|  | 45 | bbfatal "OTPTOOL_CONFIGS is empty, no otptool configurations available" | 
| Jamin Lin | eed879f | 2021-12-17 15:45:25 +0800 | [diff] [blame] | 46 | elif [ ! -d "${OTPTOOL_KEY_DIR}" ] ; then | 
|  | 47 | bbfatal "Invalid otptool signing key directory: ${OTPTOOL_KEY_DIR}" | 
|  | 48 | else | 
| Andrew Jeffery | b164200 | 2022-08-08 21:45:34 +0930 | [diff] [blame] | 49 | for otptool_config in ${OTPTOOL_CONFIGS} ; do | 
|  | 50 | if [ ! -e ${otptool_config} ] ; then | 
|  | 51 | bbfatal "Invalid otptool config: ${otptool_config}" | 
|  | 52 | fi | 
| Jamin Lin | eed879f | 2021-12-17 15:45:25 +0800 | [diff] [blame] | 53 |  | 
| Andrew Jeffery | b164200 | 2022-08-08 21:45:34 +0930 | [diff] [blame] | 54 | do_otptool $otptool_config | 
|  | 55 | done | 
| Jamin Lin | eed879f | 2021-12-17 15:45:25 +0800 | [diff] [blame] | 56 | fi | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | create_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 |  | 
|  | 74 | do_deploy:prepend() { | 
|  | 75 | if [ "${SOCSEC_SIGN_ENABLE}" = "1" ] ; then | 
|  | 76 | create_otp | 
|  | 77 | fi | 
|  | 78 | } |