From 81ed5ef8d5a7d3ffac0726c39d591fa2314c63a5 Mon Sep 17 00:00:00 2001 From: Pawel Langowski Date: Fri, 6 Dec 2024 10:27:14 +0100 Subject: [PATCH] Fix indents in scripts Signed-off-by: Pawel Langowski --- include/dts-environment.sh | 4 +- include/dts-functions.sh | 1639 +++++++++++++++---------------- include/dts-subscription.sh | 56 +- include/hal/common-mock-func.sh | 226 ++--- include/hal/dts-hal.sh | 129 ++- tests/compare_version.sh | 72 +- 6 files changed, 1060 insertions(+), 1066 deletions(-) diff --git a/include/dts-environment.sh b/include/dts-environment.sh index 01ebf76f..118fdb46 100644 --- a/include/dts-environment.sh +++ b/include/dts-environment.sh @@ -191,7 +191,7 @@ DTS_LOGS_PASSWORD="/w\J&>8 & 0xff)) + $IOTOOLS io_write8 0x2f $(($2 >> 8 & 0xff)) # Address low byte $IOTOOLS io_write8 0x2e 0x2e @@ -134,12 +134,12 @@ it5570_i2ec() { $IOTOOLS io_write8 0x2e 0x2f case $1 in - "r") - $IOTOOLS io_read8 0x2f - ;; - "w") - $IOTOOLS io_write8 0x2f "$3" - ;; + "r") + $IOTOOLS io_read8 0x2f + ;; + "w") + $IOTOOLS io_write8 0x2f "$3" + ;; esac } @@ -150,7 +150,7 @@ it5570_shutdown() { } check_network_connection() { - if wget --spider cloud.3mdeb.com > /dev/null 2>&1; then + if wget --spider cloud.3mdeb.com >/dev/null 2>&1; then return 0 else return 1 @@ -161,13 +161,13 @@ wait_for_network_connection() { echo 'Waiting for network connection ...' n="10" - while : ; do + while :; do if check_network_connection; then print_ok "Network connection have been established!" return 0 fi - n=$((n-1)) + n=$((n - 1)) if [ "${n}" == "0" ]; then print_error "Could not connect to network, please check network connection!" return 1 @@ -177,7 +177,7 @@ wait_for_network_connection() { } ask_for_model() { - local model=( "$@" ) + local model=("$@") if [ $# -lt 1 ]; then BOARD_MODEL="" return @@ -186,7 +186,7 @@ ask_for_model() { while :; do echo "Choose your board model:" echo " 0. None below" - for ((i=0; i < $#; i++)); do + for ((i = 0; i < $#; i++)); do echo " $((i + 1)): ${model[$i]}" done @@ -206,20 +206,20 @@ ask_for_model() { } board_config() { -# This functions checks used platform and configure environment in case the -# platform is supported. The supported platforms are sorted by variables -# SYSTEM_VENDOR, SYSTEM_MODEL, and BOARD_MODEL in switch/case statements. -# -# Every platform uses some standard environment configuration variables -# described in dts-environment.sh file, these could be specified for a specific -# board or vendor or shared between some, some platforms may have their own env. -# var. as well. -# -# All the standard variables are explicitly declared in dts-environment.sh -# script and, if appropriate, set to default values. If a platform has its own -# configuration variables - it must declare them here, even if they are not -# set. This is made with a goal to limit global variables declaration to -# dts-environment.sh and board_config function. + # This functions checks used platform and configure environment in case the + # platform is supported. The supported platforms are sorted by variables + # SYSTEM_VENDOR, SYSTEM_MODEL, and BOARD_MODEL in switch/case statements. + # + # Every platform uses some standard environment configuration variables + # described in dts-environment.sh file, these could be specified for a specific + # board or vendor or shared between some, some platforms may have their own env. + # var. as well. + # + # All the standard variables are explicitly declared in dts-environment.sh + # script and, if appropriate, set to default values. If a platform has its own + # configuration variables - it must declare them here, even if they are not + # set. This is made with a goal to limit global variables declaration to + # dts-environment.sh and board_config function. # We download firmwares via network. At this point, the network connection # must be up already. @@ -227,424 +227,424 @@ board_config() { echo "Checking if board is Dasharo compatible." case "$SYSTEM_VENDOR" in - "Notebook") - # Common settings for all Notebooks: - CAN_USE_FLASHROM="true" - HAVE_EC="true" - NEED_EC_RESET="true" - PLATFORM_SIGN_KEY="customer-keys/novacustom/novacustom-open-source-firmware-release-1.x-key.asc \ + "Notebook") + # Common settings for all Notebooks: + CAN_USE_FLASHROM="true" + HAVE_EC="true" + NEED_EC_RESET="true" + PLATFORM_SIGN_KEY="customer-keys/novacustom/novacustom-open-source-firmware-release-1.x-key.asc \ customer-keys/novacustom/dasharo-release-0.9.x-for-novacustom-signing-key.asc" - NEED_SMMSTORE_MIGRATION="true" - - case "$SYSTEM_MODEL" in - "NV4XMB,ME,MZ") - DASHARO_REL_NAME="novacustom_nv4x_tgl" - DASHARO_REL_VER="1.5.2" - CAN_INSTALL_BIOS="true" - COMPATIBLE_EC_FW_VERSION="2022-10-07_c662165" - if check_if_dasharo; then - # if v1.5.1 or older, flash the whole bios region - # TODO: Let DTS determine which parameters are suitable. - # FIXME: Can we ever get rid of that? We change so much in each release, - # that we almost always need to flash whole BIOS regions - # because of non-backward compatible or breaking changes. - compare_versions $DASHARO_VERSION 1.5.2 - if [ $? -eq 1 ]; then - # For Dasharo version lesser than 1.5.2 - NEED_BOOTSPLASH_MIGRATION="true" - FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" - fi - fi - ;; - "NS50_70MU") - DASHARO_REL_NAME="novacustom_ns5x_tgl" - DASHARO_REL_VER="1.5.2" - CAN_INSTALL_BIOS="true" - COMPATIBLE_EC_FW_VERSION="2022-08-31_cbff21b" - if check_if_dasharo; then - # if v1.5.1 or older, flash the whole bios region - # TODO: Let DTS determine which parameters are suitable. - # FIXME: Can we ever get rid of that? We change so much in each release, - # that we almost always need to flash whole BIOS regions - # because of non-backward compatible or breaking changes. - compare_versions $DASHARO_VERSION 1.5.2 - if [ $? -eq 1 ]; then - # For Dasharo version lesser than 1.5.2 - NEED_BOOTSPLASH_MIGRATION="true" - FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" - fi - fi - ;; - "NS5x_NS7xPU") - DASHARO_REL_NAME="novacustom_ns5x_adl" - DASHARO_REL_VER="1.7.2" - COMPATIBLE_EC_FW_VERSION="2022-08-31_cbff21b" - if check_if_dasharo; then - # if v1.7.2 or older, flash the whole bios region - # TODO: Let DTS determine which parameters are suitable. - # FIXME: Can we ever get rid of that? We change so much in each release, - # that we almost always need to flash whole BIOS regions - # because of non-backward compatible or breaking changes. - compare_versions $DASHARO_VERSION 1.7.2 - if [ $? -eq 1 ]; then - # For Dasharo version lesser than 1.7.2 - NEED_BOOTSPLASH_MIGRATION="true" - FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" - fi - fi - ;; - "NV4xPZ") - DASHARO_REL_NAME="novacustom_nv4x_adl" - DASHARO_REL_VER="1.7.2" - HEADS_REL_VER_DPP="0.9.1" - HEADS_LINK_DPP="${FW_STORE_URL_DPP}/${DASHARO_REL_NAME}/v${HEADS_REL_VER_DPP}/${DASHARO_REL_NAME}_v${HEADS_REL_VER_DPP}_heads.rom" - HEADS_SWITCH_FLASHROM_OPT_OVERRIDE="--ifd -i bios" - COMPATIBLE_EC_FW_VERSION="2022-08-31_cbff21b" - if check_if_dasharo; then - # if v1.7.2 or older, flash the whole bios region - # TODO: Let DTS determine which parameters are suitable. - # FIXME: Can we ever get rid of that? We change so much in each release, - # that we almost always need to flash whole BIOS regions - # because of non-backward compatible or breaking changes. - compare_versions $DASHARO_VERSION 1.7.2 - if [ $? -eq 1 ]; then - # For Dasharo version lesser than 1.7.2 - NEED_BOOTSPLASH_MIGRATION="true" - FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" - else - HAVE_HEADS_FW="true" - fi - if [ "$DASHARO_FLAVOR" == "Dasharo (coreboot+heads)" ]; then - HAVE_HEADS_FW="true" - fi - fi - ;; - "V54x_6x_TU") - # Dasharo 0.9.0-rc10 and higher have board model in baseboard-version - if check_if_dasharo && compare_versions "$DASHARO_VERSION" 0.9.0-rc10; then - BOARD_MODEL="$($DMIDECODE dump_var_mock -s baseboard-version)" - elif ! $DASHARO_ECTOOL check_for_opensource_firm_mock info 2>/dev/null; then - ask_for_model V540TU V560TU - else - BOARD_MODEL=$($DASHARO_ECTOOL novacustom_check_sys_model_mock info | grep "board:" | - sed -r 's|.*novacustom/(.*)|\1|' | awk '{print toupper($1)}') - fi + NEED_SMMSTORE_MIGRATION="true" - # Common configuration for all V54x_6x_TU: - DASHARO_REL_VER="0.9.0" - COMPATIBLE_EC_FW_VERSION="2024-07-17_4ae73b9" + case "$SYSTEM_MODEL" in + "NV4XMB,ME,MZ") + DASHARO_REL_NAME="novacustom_nv4x_tgl" + DASHARO_REL_VER="1.5.2" + CAN_INSTALL_BIOS="true" + COMPATIBLE_EC_FW_VERSION="2022-10-07_c662165" + if check_if_dasharo; then + # if v1.5.1 or older, flash the whole bios region + # TODO: Let DTS determine which parameters are suitable. + # FIXME: Can we ever get rid of that? We change so much in each release, + # that we almost always need to flash whole BIOS regions + # because of non-backward compatible or breaking changes. + compare_versions $DASHARO_VERSION 1.5.2 + if [ $? -eq 1 ]; then + # For Dasharo version lesser than 1.5.2 NEED_BOOTSPLASH_MIGRATION="true" - - case $BOARD_MODEL in - "V540TU") - DASHARO_REL_NAME="novacustom_v54x_mtl" - FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" - ;; - "V560TU") - DASHARO_REL_NAME="novacustom_v56x_mtl" - FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" - ;; - *) - print_error "Board model $BOARD_MODEL is currently not supported" - return 1 - ;; - esac - ;; - "V5xTNC_TND_TNE") - if check_if_dasharo; then - BOARD_MODEL="$($DMIDECODE dump_var_mock -s baseboard-version)" - else - ask_for_model V540TNx V560TNx - fi - + FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" + fi + fi + ;; + "NS50_70MU") + DASHARO_REL_NAME="novacustom_ns5x_tgl" + DASHARO_REL_VER="1.5.2" + CAN_INSTALL_BIOS="true" + COMPATIBLE_EC_FW_VERSION="2022-08-31_cbff21b" + if check_if_dasharo; then + # if v1.5.1 or older, flash the whole bios region + # TODO: Let DTS determine which parameters are suitable. + # FIXME: Can we ever get rid of that? We change so much in each release, + # that we almost always need to flash whole BIOS regions + # because of non-backward compatible or breaking changes. + compare_versions $DASHARO_VERSION 1.5.2 + if [ $? -eq 1 ]; then + # For Dasharo version lesser than 1.5.2 NEED_BOOTSPLASH_MIGRATION="true" - - case $BOARD_MODEL in - "V540TNx") - DASHARO_REL_NAME="novacustom_v54x_mtl" - DASHARO_REL_VER="0.9.1" - COMPATIBLE_EC_FW_VERSION="2024-09-10_3786c8c" - FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" - ;; - "V560TNx") - DASHARO_REL_NAME="novacustom_v56x_mtl" - DASHARO_REL_VER="0.9.1" - COMPATIBLE_EC_FW_VERSION="2024-09-10_3786c8c" - FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" - ;; - *) - print_error "Board model $BOARD_MODEL is currently not supported" - return 1 - ;; - esac - ;; - *) - print_error "Board model $SYSTEM_MODEL is currently not supported" - return 1 - ;; - esac - BIOS_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}.rom" - EC_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_ec_v${DASHARO_REL_VER}.rom" + FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" + fi + fi ;; - "Micro-Star International Co., Ltd.") - case "$SYSTEM_MODEL" in - "MS-7D25") - # Common configuration for all MS-7D25: - DASHARO_REL_NAME="msi_ms7d25" - DASHARO_REL_VER="1.1.1" - DASHARO_REL_VER_DPP="1.1.4" - CAN_INSTALL_BIOS="true" - HAVE_HEADS_FW="true" - HEADS_REL_VER_DPP="0.9.0" - HEADS_SWITCH_FLASHROM_OPT_OVERRIDE="--ifd -i bios" - PLATFORM_SIGN_KEY="dasharo/msi_ms7d25/dasharo-release-1.x-compatible-with-msi-ms-7d25-signing-key.asc \ - dasharo/msi_ms7d25/dasharo-release-0.x-compatible-with-msi-ms-7d25-signing-key.asc" - NEED_SMBIOS_MIGRATION="true" - NEED_SMMSTORE_MIGRATION="true" - NEED_ROMHOLE_MIGRATION="true" - - # Add capsules: - DASHARO_REL_NAME_CAP="$DASHARO_REL_NAME" - DASHARO_REL_VER_DPP_CAP="$DASHARO_REL_VER_DPP" - DASHARO_SUPPORT_CAP_FROM="1.1.4" - - # flash the whole bios region - # TODO: Let DTS determine which parameters are suitable. - # FIXME: Can we ever get rid of that? We change so much in each release, - # that we almost always need to flash whole BIOS region - # because of non-backward compatible or breaking changes. + "NS5x_NS7xPU") + DASHARO_REL_NAME="novacustom_ns5x_adl" + DASHARO_REL_VER="1.7.2" + COMPATIBLE_EC_FW_VERSION="2022-08-31_cbff21b" + if check_if_dasharo; then + # if v1.7.2 or older, flash the whole bios region + # TODO: Let DTS determine which parameters are suitable. + # FIXME: Can we ever get rid of that? We change so much in each release, + # that we almost always need to flash whole BIOS regions + # because of non-backward compatible or breaking changes. + compare_versions $DASHARO_VERSION 1.7.2 + if [ $? -eq 1 ]; then + # For Dasharo version lesser than 1.7.2 NEED_BOOTSPLASH_MIGRATION="true" FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" - - case "$BOARD_MODEL" in - "PRO Z690-A WIFI DDR4(MS-7D25)" | "PRO Z690-A DDR4(MS-7D25)") - BIOS_LINK_COMM="${FW_STORE_URL}/${DASHARO_REL_NAME}/v${DASHARO_REL_VER}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_ddr4.rom" - BIOS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7D25/v${DASHARO_REL_VER_DPP}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER_DPP}_ddr4.rom" - BIOS_LINK_DPP_CAP="${FW_STORE_URL_DPP}/MS-7D25/v${DASHARO_REL_VER_DPP_CAP}/${DASHARO_REL_NAME_CAP}_v${DASHARO_REL_VER_DPP_CAP}_ddr4.cap" - HEADS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7D25/v${HEADS_REL_VER_DPP}/${DASHARO_REL_NAME}_v${HEADS_REL_VER_DPP}_ddr4_heads.rom" - ;; - "PRO Z690-A WIFI (MS-7D25)" | "PRO Z690-A (MS-7D25)") - BIOS_LINK_COMM="${FW_STORE_URL}/${DASHARO_REL_NAME}/v${DASHARO_REL_VER}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_ddr5.rom" - BIOS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7D25/v${DASHARO_REL_VER_DPP}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER_DPP}_ddr5.rom" - BIOS_LINK_DPP_CAP="${FW_STORE_URL_DPP}/MS-7D25/v${DASHARO_REL_VER_DPP_CAP}/${DASHARO_REL_NAME_CAP}_v${DASHARO_REL_VER_DPP_CAP}_ddr5.cap" - HEADS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7D25/v${HEADS_REL_VER_DPP}/${DASHARO_REL_NAME}_v${HEADS_REL_VER_DPP}_ddr5_heads.rom" - ;; - *) - print_error "Board model $BOARD_MODEL is currently not supported" - return 1 - ;; - esac - ;; - "MS-7E06") - # Common configuration for all MS-7E06: - DASHARO_REL_NAME="msi_ms7e06" - #DASHARO_REL_VER="" - DASHARO_REL_VER_DPP="0.9.2" - CAN_INSTALL_BIOS="true" - HAVE_HEADS_FW="true" - HEADS_REL_VER_DPP="0.9.0" - HEADS_SWITCH_FLASHROM_OPT_OVERRIDE="--ifd -i bios" - PLATFORM_SIGN_KEY="dasharo/msi_ms7e06/dasharo-release-0.x-compatible-with-msi-ms-7e06-signing-key.asc" - NEED_SMMSTORE_MIGRATION="true" - NEED_ROMHOLE_MIGRATION="true" - - # Add capsules: - DASHARO_REL_NAME_CAP="$DASHARO_REL_NAME" - DASHARO_REL_VER_DPP_CAP="$DASHARO_REL_VER_DPP" - DASHARO_SUPPORT_CAP_FROM="0.9.2" - - # flash the whole bios region - # TODO: Let DTS determine which parameters are suitable. - # FIXME: Can we ever get rid of that? We change so much in each release, - # that we almost always need to flash whole BIOS region - # because of non-backward compatible or breaking changes. + fi + fi + ;; + "NV4xPZ") + DASHARO_REL_NAME="novacustom_nv4x_adl" + DASHARO_REL_VER="1.7.2" + HEADS_REL_VER_DPP="0.9.1" + HEADS_LINK_DPP="${FW_STORE_URL_DPP}/${DASHARO_REL_NAME}/v${HEADS_REL_VER_DPP}/${DASHARO_REL_NAME}_v${HEADS_REL_VER_DPP}_heads.rom" + HEADS_SWITCH_FLASHROM_OPT_OVERRIDE="--ifd -i bios" + COMPATIBLE_EC_FW_VERSION="2022-08-31_cbff21b" + if check_if_dasharo; then + # if v1.7.2 or older, flash the whole bios region + # TODO: Let DTS determine which parameters are suitable. + # FIXME: Can we ever get rid of that? We change so much in each release, + # that we almost always need to flash whole BIOS regions + # because of non-backward compatible or breaking changes. + compare_versions $DASHARO_VERSION 1.7.2 + if [ $? -eq 1 ]; then + # For Dasharo version lesser than 1.7.2 NEED_BOOTSPLASH_MIGRATION="true" FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" + else + HAVE_HEADS_FW="true" + fi + if [ "$DASHARO_FLAVOR" == "Dasharo (coreboot+heads)" ]; then + HAVE_HEADS_FW="true" + fi + fi + ;; + "V54x_6x_TU") + # Dasharo 0.9.0-rc10 and higher have board model in baseboard-version + if check_if_dasharo && compare_versions "$DASHARO_VERSION" 0.9.0-rc10; then + BOARD_MODEL="$($DMIDECODE dump_var_mock -s baseboard-version)" + elif ! $DASHARO_ECTOOL check_for_opensource_firm_mock info 2>/dev/null; then + ask_for_model V540TU V560TU + else + BOARD_MODEL=$($DASHARO_ECTOOL novacustom_check_sys_model_mock info | grep "board:" | + sed -r 's|.*novacustom/(.*)|\1|' | awk '{print toupper($1)}') + fi - case "$BOARD_MODEL" in - "PRO Z790-P WIFI DDR4(MS-7E06)" | "PRO Z790-P DDR4(MS-7E06)" | "PRO Z790-P WIFI DDR4 (MS-7E06)" | "PRO Z790-P DDR4 (MS-7E06)") - #BIOS_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_ddr4.rom" - BIOS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7E06/v${DASHARO_REL_VER_DPP}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER_DPP}_ddr4.rom" - BIOS_LINK_DPP_CAP="${FW_STORE_URL_DPP}/MS-7E06/v${DASHARO_REL_VER_DPP_CAP}/${DASHARO_REL_NAME_CAP}_v${DASHARO_REL_VER_DPP_CAP}_ddr4.cap" - HEADS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7E06/v${HEADS_REL_VER_DPP}/${DASHARO_REL_NAME}_v${HEADS_REL_VER_DPP}_ddr4_heads.rom" - PROGRAMMER_BIOS="internal:boardmismatch=force" - ;; - "PRO Z790-P WIFI (MS-7E06)" | "PRO Z790-P (MS-7E06)") - #BIOS_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_ddr5.rom" - BIOS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7E06/v${DASHARO_REL_VER_DPP}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER_DPP}_ddr5.rom" - BIOS_LINK_DPP_CAP="${FW_STORE_URL_DPP}/MS-7E06/v${DASHARO_REL_VER_DPP_CAP}/${DASHARO_REL_NAME_CAP}_v${DASHARO_REL_VER_DPP_CAP}_ddr5.cap" - HEADS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7E06/v${HEADS_REL_VER_DPP}/${DASHARO_REL_NAME}_v${HEADS_REL_VER_DPP}_ddr5_heads.rom" - ;; - *) - print_error "Board model $BOARD_MODEL is currently not supported" - return 1 - ;; - esac - ;; - *) - print_error "Board model $SYSTEM_MODEL is currently not supported" - return 1 - ;; + # Common configuration for all V54x_6x_TU: + DASHARO_REL_VER="0.9.0" + COMPATIBLE_EC_FW_VERSION="2024-07-17_4ae73b9" + NEED_BOOTSPLASH_MIGRATION="true" + + case $BOARD_MODEL in + "V540TU") + DASHARO_REL_NAME="novacustom_v54x_mtl" + FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" + ;; + "V560TU") + DASHARO_REL_NAME="novacustom_v56x_mtl" + FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" + ;; + *) + print_error "Board model $BOARD_MODEL is currently not supported" + return 1 + ;; esac ;; - "Dell Inc.") - # Common configuration for all Dell releases: - DASHARO_REL_NAME="dell_optiplex_7010_9010" - DASHARO_REL_VER_DPP="0.1.0" - BIOS_LINK_DPP="$FW_STORE_URL_DPP/v$DASHARO_REL_VER_DPP/${DASHARO_REL_NAME}_v$DASHARO_REL_VER_DPP.rom" - CAN_INSTALL_BIOS="true" - NEED_SMBIOS_MIGRATION="true" - NEED_BLOB_TRANSMISSION="true" - SINIT_ACM_FILENAME="/tmp/630744_003.zip" - SINIT_ACM_URL="https://cdrdv2.intel.com/v1/dl/getContent/630744" - SINIT_ACM_HASH="0b412c1832bd504d4b8f5fa01b32449c344fe0019e5e4da6bb5d80d393df5e8b $SINIT_ACM_FILENAME" - SINIT_ACM="/tmp/630744_003/SNB_IVB_SINIT_20190708_PW.bin" - FLASHROM_ADD_OPT_DEPLOY="--ifd -i bios" - FLASHROM_ADD_OPT_UPDATE="--fmap -i RW_SECTION_A" - - case "$SYSTEM_MODEL" in - "OptiPlex 7010") - DBT_BIOS_UPDATE_FILENAME="/tmp/O7010A29.exe" - DBT_BIOS_UPDATE_URL="https://dl.dell.com/FOLDER05066036M/1/O7010A29.exe" - DBT_BIOS_UPDATE_HASH="ceb82586c67cd8d5933ac858c12e0cb52f6e0e4cb3249f964f1c0cfc06d16f52 $DBT_BIOS_UPDATE_FILENAME" - DBT_UEFI_IMAGE="/tmp/_O7010A29.exe.extracted/65C10" - SCH5545_FW="/tmp/_O7010A29.exe.extracted/65C10_output/pfsobject/section-7ec6c2b0-3fe3-42a0-a316-22dd0517c1e8/volume-0x50000/file-d386beb8-4b54-4e69-94f5-06091f67e0d3/section0.raw" - ACM_BIN="/tmp/_O7010A29.exe.extracted/65C10_output/pfsobject/section-7ec6c2b0-3fe3-42a0-a316-22dd0517c1e8/volume-0x500000/file-2d27c618-7dcd-41f5-bb10-21166be7e143/object-0.raw" - ;; - "OptiPlex 9010") - DBT_BIOS_UPDATE_FILENAME="/tmp/O9010A30.exe" - DBT_BIOS_UPDATE_URL="https://dl.dell.com/FOLDER05066009M/1/O9010A30.exe" - DBT_BIOS_UPDATE_HASH="b11952f43d0ad66f3ce79558b8c5dd43f30866158ed8348e3b2dae1bbb07701b $DBT_BIOS_UPDATE_FILENAME" - DBT_UEFI_IMAGE="/tmp/_O9010A30.exe.extracted/65C10" - SCH5545_FW="/tmp/_O9010A30.exe.extracted/65C10_output/pfsobject/section-7ec6c2b0-3fe3-42a0-a316-22dd0517c1e8/volume-0x50000/file-d386beb8-4b54-4e69-94f5-06091f67e0d3/section0.raw" - ACM_BIN="/tmp/_O9010A30.exe.extracted/65C10_output/pfsobject/section-7ec6c2b0-3fe3-42a0-a316-22dd0517c1e8/volume-0x500000/file-2d27c618-7dcd-41f5-bb10-21166be7e143/object-0.raw" - ;; - "Precision T1650") - # tested on Dasharo Firmware for OptiPlex 9010, will need to be - # enabled when build for T1650 exists - # - # DBT_BIOS_UPDATE_FILENAME="/tmp/T1650A28.exe" - # DBT_BIOS_UPDATE_URL="https://dl.dell.com/FOLDER05065992M/1/T1650A28.exe" - # DBT_BIOS_UPDATE_HASH="40a66210b8882f523885849c1d879e726dc58aa14718168b1e75f3e2caaa523b $DBT_BIOS_UPDATE_FILENAME" - # DBT_UEFI_IMAGE="/tmp/_T1650A28.exe.extracted/65C10" - # SCH5545_FW="/tmp/_T1650A28.exe.extracted/65C10_output/pfsobject/section-7ec6c2b0-3fe3-42a0-a316-22dd0517c1e8/volume-0x60000/file-d386beb8-4b54-4e69-94f5-06091f67e0d3/section0.raw" - # ACM_BIN="/tmp/_T1650A28.exe.extracted/65C10_output/pfsobject/section-7ec6c2b0-3fe3-42a0-a316-22dd0517c1e8/volume-0x500000/file-2d27c618-7dcd-41f5-bb10-21166be7e143/object-0.raw" - print_warning "Dasharo Firmware for Precision T1650 not available yet!" - print_error "Board model $SYSTEM_MODEL is currently not supported" - return 1 - ;; - *) - print_error "Board model $SYSTEM_MODEL is currently not supported" - return 1 - ;; + "V5xTNC_TND_TNE") + if check_if_dasharo; then + BOARD_MODEL="$($DMIDECODE dump_var_mock -s baseboard-version)" + else + ask_for_model V540TNx V560TNx + fi + + NEED_BOOTSPLASH_MIGRATION="true" + + case $BOARD_MODEL in + "V540TNx") + DASHARO_REL_NAME="novacustom_v54x_mtl" + DASHARO_REL_VER="0.9.1" + COMPATIBLE_EC_FW_VERSION="2024-09-10_3786c8c" + FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" + ;; + "V560TNx") + DASHARO_REL_NAME="novacustom_v56x_mtl" + DASHARO_REL_VER="0.9.1" + COMPATIBLE_EC_FW_VERSION="2024-09-10_3786c8c" + FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" + ;; + *) + print_error "Board model $BOARD_MODEL is currently not supported" + return 1 + ;; esac ;; - "ASUS") - case "$SYSTEM_MODEL" in - "KGPE-D16") - DASHARO_REL_NAME="asus_kgpe-d16" - DASHARO_REL_VER="0.4.0" - CAN_INSTALL_BIOS="true" - case "$FLASH_CHIP_SIZE" in - "2") - BIOS_HASH_LINK_COMM="65e5370e9ea6b8ae7cd6cc878a031a4ff3a8f5d36830ef39656b8e5a6e37e889 $BIOS_UPDATE_FILE" - BIOS_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_vboot_notpm.rom" - ;; - "8") - BIOS_HASH_LINK_COMM="da4e6217d50f2ac199dcb9a927a0bc02aa4e792ed73c8c9bac8ba74fc787dbef $BIOS_UPDATE_FILE" - BIOS_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_${FLASH_CHIP_SIZE}M_vboot_notpm.rom" - ;; - "16") - BIOS_HASH_LINK_COMM="20055cf57185f149259706f58d5e9552a1589259c6617999c1ac7d8d3c960020 $BIOS_UPDATE_FILE" - BIOS_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_${FLASH_CHIP_SIZE}M_vboot_notpm.rom" - ;; - *) - print_error "Platform uses chipset with not supported size" - return 1 - ;; - esac - NEED_SMBIOS_MIGRATION="true" - ;; - *) - print_error "Board model $SYSTEM_MODEL is currently not supported" - return 1 - ;; + *) + print_error "Board model $SYSTEM_MODEL is currently not supported" + return 1 + ;; + esac + BIOS_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}.rom" + EC_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_ec_v${DASHARO_REL_VER}.rom" + ;; + "Micro-Star International Co., Ltd.") + case "$SYSTEM_MODEL" in + "MS-7D25") + # Common configuration for all MS-7D25: + DASHARO_REL_NAME="msi_ms7d25" + DASHARO_REL_VER="1.1.1" + DASHARO_REL_VER_DPP="1.1.4" + CAN_INSTALL_BIOS="true" + HAVE_HEADS_FW="true" + HEADS_REL_VER_DPP="0.9.0" + HEADS_SWITCH_FLASHROM_OPT_OVERRIDE="--ifd -i bios" + PLATFORM_SIGN_KEY="dasharo/msi_ms7d25/dasharo-release-1.x-compatible-with-msi-ms-7d25-signing-key.asc \ + dasharo/msi_ms7d25/dasharo-release-0.x-compatible-with-msi-ms-7d25-signing-key.asc" + NEED_SMBIOS_MIGRATION="true" + NEED_SMMSTORE_MIGRATION="true" + NEED_ROMHOLE_MIGRATION="true" + + # Add capsules: + DASHARO_REL_NAME_CAP="$DASHARO_REL_NAME" + DASHARO_REL_VER_DPP_CAP="$DASHARO_REL_VER_DPP" + DASHARO_SUPPORT_CAP_FROM="1.1.4" + + # flash the whole bios region + # TODO: Let DTS determine which parameters are suitable. + # FIXME: Can we ever get rid of that? We change so much in each release, + # that we almost always need to flash whole BIOS region + # because of non-backward compatible or breaking changes. + NEED_BOOTSPLASH_MIGRATION="true" + FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" + + case "$BOARD_MODEL" in + "PRO Z690-A WIFI DDR4(MS-7D25)" | "PRO Z690-A DDR4(MS-7D25)") + BIOS_LINK_COMM="${FW_STORE_URL}/${DASHARO_REL_NAME}/v${DASHARO_REL_VER}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_ddr4.rom" + BIOS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7D25/v${DASHARO_REL_VER_DPP}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER_DPP}_ddr4.rom" + BIOS_LINK_DPP_CAP="${FW_STORE_URL_DPP}/MS-7D25/v${DASHARO_REL_VER_DPP_CAP}/${DASHARO_REL_NAME_CAP}_v${DASHARO_REL_VER_DPP_CAP}_ddr4.cap" + HEADS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7D25/v${HEADS_REL_VER_DPP}/${DASHARO_REL_NAME}_v${HEADS_REL_VER_DPP}_ddr4_heads.rom" + ;; + "PRO Z690-A WIFI (MS-7D25)" | "PRO Z690-A (MS-7D25)") + BIOS_LINK_COMM="${FW_STORE_URL}/${DASHARO_REL_NAME}/v${DASHARO_REL_VER}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_ddr5.rom" + BIOS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7D25/v${DASHARO_REL_VER_DPP}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER_DPP}_ddr5.rom" + BIOS_LINK_DPP_CAP="${FW_STORE_URL_DPP}/MS-7D25/v${DASHARO_REL_VER_DPP_CAP}/${DASHARO_REL_NAME_CAP}_v${DASHARO_REL_VER_DPP_CAP}_ddr5.cap" + HEADS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7D25/v${HEADS_REL_VER_DPP}/${DASHARO_REL_NAME}_v${HEADS_REL_VER_DPP}_ddr5_heads.rom" + ;; + *) + print_error "Board model $BOARD_MODEL is currently not supported" + return 1 + ;; esac ;; - "PC Engines") - # Common configuration for all PC Engines releases: - DASHARO_REL_VER_DPP="0.9.0" + "MS-7E06") + # Common configuration for all MS-7E06: + DASHARO_REL_NAME="msi_ms7e06" + #DASHARO_REL_VER="" + DASHARO_REL_VER_DPP="0.9.2" CAN_INSTALL_BIOS="true" - DASHARO_REL_VER_DPP_SEABIOS="24.05.00.01" - PROGRAMMER_BIOS="internal:boardmismatch=force" + HAVE_HEADS_FW="true" + HEADS_REL_VER_DPP="0.9.0" + HEADS_SWITCH_FLASHROM_OPT_OVERRIDE="--ifd -i bios" + PLATFORM_SIGN_KEY="dasharo/msi_ms7e06/dasharo-release-0.x-compatible-with-msi-ms-7e06-signing-key.asc" NEED_SMMSTORE_MIGRATION="true" + NEED_ROMHOLE_MIGRATION="true" + + # Add capsules: + DASHARO_REL_NAME_CAP="$DASHARO_REL_NAME" + DASHARO_REL_VER_DPP_CAP="$DASHARO_REL_VER_DPP" + DASHARO_SUPPORT_CAP_FROM="0.9.2" + + # flash the whole bios region + # TODO: Let DTS determine which parameters are suitable. + # FIXME: Can we ever get rid of that? We change so much in each release, + # that we almost always need to flash whole BIOS region + # because of non-backward compatible or breaking changes. NEED_BOOTSPLASH_MIGRATION="true" - FLASH_CHIP_LIST="W25Q64JV-.Q" - - shopt -s nocasematch - case "$SYSTEM_MODEL" in - "APU2") - DASHARO_REL_NAME="pcengines_apu2" - ;; - "APU3") - DASHARO_REL_NAME="pcengines_apu3" - ;; - "APU4") - DASHARO_REL_NAME="pcengines_apu4" - ;; - "APU6") - DASHARO_REL_NAME="pcengines_apu6" - ;; - *) - print_error "Board model $SYSTEM_MODEL is currently not supported" - return 1 - ;; + FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" + + case "$BOARD_MODEL" in + "PRO Z790-P WIFI DDR4(MS-7E06)" | "PRO Z790-P DDR4(MS-7E06)" | "PRO Z790-P WIFI DDR4 (MS-7E06)" | "PRO Z790-P DDR4 (MS-7E06)") + #BIOS_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_ddr4.rom" + BIOS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7E06/v${DASHARO_REL_VER_DPP}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER_DPP}_ddr4.rom" + BIOS_LINK_DPP_CAP="${FW_STORE_URL_DPP}/MS-7E06/v${DASHARO_REL_VER_DPP_CAP}/${DASHARO_REL_NAME_CAP}_v${DASHARO_REL_VER_DPP_CAP}_ddr4.cap" + HEADS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7E06/v${HEADS_REL_VER_DPP}/${DASHARO_REL_NAME}_v${HEADS_REL_VER_DPP}_ddr4_heads.rom" + PROGRAMMER_BIOS="internal:boardmismatch=force" + ;; + "PRO Z790-P WIFI (MS-7E06)" | "PRO Z790-P (MS-7E06)") + #BIOS_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_ddr5.rom" + BIOS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7E06/v${DASHARO_REL_VER_DPP}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER_DPP}_ddr5.rom" + BIOS_LINK_DPP_CAP="${FW_STORE_URL_DPP}/MS-7E06/v${DASHARO_REL_VER_DPP_CAP}/${DASHARO_REL_NAME_CAP}_v${DASHARO_REL_VER_DPP_CAP}_ddr5.cap" + HEADS_LINK_DPP="${FW_STORE_URL_DPP}/MS-7E06/v${HEADS_REL_VER_DPP}/${DASHARO_REL_NAME}_v${HEADS_REL_VER_DPP}_ddr5_heads.rom" + ;; + *) + print_error "Board model $BOARD_MODEL is currently not supported" + return 1 + ;; esac - - BIOS_LINK_DPP="${FW_STORE_URL_DPP}/pcengines_apu2/v${DASHARO_REL_VER_DPP}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER_DPP}.rom" - BIOS_LINK_DPP_SEABIOS="${FW_STORE_URL_DPP}/pcengines_apu2/v${DASHARO_REL_VER_DPP_SEABIOS}/${DASHARO_REL_NAME}_seabios_v${DASHARO_REL_VER_DPP_SEABIOS}.rom" - - shopt -u nocasematch ;; - "HARDKERNEL") + *) + print_error "Board model $SYSTEM_MODEL is currently not supported" + return 1 + ;; + esac + ;; + "Dell Inc.") + # Common configuration for all Dell releases: + DASHARO_REL_NAME="dell_optiplex_7010_9010" + DASHARO_REL_VER_DPP="0.1.0" + BIOS_LINK_DPP="$FW_STORE_URL_DPP/v$DASHARO_REL_VER_DPP/${DASHARO_REL_NAME}_v$DASHARO_REL_VER_DPP.rom" + CAN_INSTALL_BIOS="true" + NEED_SMBIOS_MIGRATION="true" + NEED_BLOB_TRANSMISSION="true" + SINIT_ACM_FILENAME="/tmp/630744_003.zip" + SINIT_ACM_URL="https://cdrdv2.intel.com/v1/dl/getContent/630744" + SINIT_ACM_HASH="0b412c1832bd504d4b8f5fa01b32449c344fe0019e5e4da6bb5d80d393df5e8b $SINIT_ACM_FILENAME" + SINIT_ACM="/tmp/630744_003/SNB_IVB_SINIT_20190708_PW.bin" + FLASHROM_ADD_OPT_DEPLOY="--ifd -i bios" + FLASHROM_ADD_OPT_UPDATE="--fmap -i RW_SECTION_A" + + case "$SYSTEM_MODEL" in + "OptiPlex 7010") + DBT_BIOS_UPDATE_FILENAME="/tmp/O7010A29.exe" + DBT_BIOS_UPDATE_URL="https://dl.dell.com/FOLDER05066036M/1/O7010A29.exe" + DBT_BIOS_UPDATE_HASH="ceb82586c67cd8d5933ac858c12e0cb52f6e0e4cb3249f964f1c0cfc06d16f52 $DBT_BIOS_UPDATE_FILENAME" + DBT_UEFI_IMAGE="/tmp/_O7010A29.exe.extracted/65C10" + SCH5545_FW="/tmp/_O7010A29.exe.extracted/65C10_output/pfsobject/section-7ec6c2b0-3fe3-42a0-a316-22dd0517c1e8/volume-0x50000/file-d386beb8-4b54-4e69-94f5-06091f67e0d3/section0.raw" + ACM_BIN="/tmp/_O7010A29.exe.extracted/65C10_output/pfsobject/section-7ec6c2b0-3fe3-42a0-a316-22dd0517c1e8/volume-0x500000/file-2d27c618-7dcd-41f5-bb10-21166be7e143/object-0.raw" + ;; + "OptiPlex 9010") + DBT_BIOS_UPDATE_FILENAME="/tmp/O9010A30.exe" + DBT_BIOS_UPDATE_URL="https://dl.dell.com/FOLDER05066009M/1/O9010A30.exe" + DBT_BIOS_UPDATE_HASH="b11952f43d0ad66f3ce79558b8c5dd43f30866158ed8348e3b2dae1bbb07701b $DBT_BIOS_UPDATE_FILENAME" + DBT_UEFI_IMAGE="/tmp/_O9010A30.exe.extracted/65C10" + SCH5545_FW="/tmp/_O9010A30.exe.extracted/65C10_output/pfsobject/section-7ec6c2b0-3fe3-42a0-a316-22dd0517c1e8/volume-0x50000/file-d386beb8-4b54-4e69-94f5-06091f67e0d3/section0.raw" + ACM_BIN="/tmp/_O9010A30.exe.extracted/65C10_output/pfsobject/section-7ec6c2b0-3fe3-42a0-a316-22dd0517c1e8/volume-0x500000/file-2d27c618-7dcd-41f5-bb10-21166be7e143/object-0.raw" + ;; + "Precision T1650") + # tested on Dasharo Firmware for OptiPlex 9010, will need to be + # enabled when build for T1650 exists + # + # DBT_BIOS_UPDATE_FILENAME="/tmp/T1650A28.exe" + # DBT_BIOS_UPDATE_URL="https://dl.dell.com/FOLDER05065992M/1/T1650A28.exe" + # DBT_BIOS_UPDATE_HASH="40a66210b8882f523885849c1d879e726dc58aa14718168b1e75f3e2caaa523b $DBT_BIOS_UPDATE_FILENAME" + # DBT_UEFI_IMAGE="/tmp/_T1650A28.exe.extracted/65C10" + # SCH5545_FW="/tmp/_T1650A28.exe.extracted/65C10_output/pfsobject/section-7ec6c2b0-3fe3-42a0-a316-22dd0517c1e8/volume-0x60000/file-d386beb8-4b54-4e69-94f5-06091f67e0d3/section0.raw" + # ACM_BIN="/tmp/_T1650A28.exe.extracted/65C10_output/pfsobject/section-7ec6c2b0-3fe3-42a0-a316-22dd0517c1e8/volume-0x500000/file-2d27c618-7dcd-41f5-bb10-21166be7e143/object-0.raw" + print_warning "Dasharo Firmware for Precision T1650 not available yet!" + print_error "Board model $SYSTEM_MODEL is currently not supported" + return 1 + ;; + *) + print_error "Board model $SYSTEM_MODEL is currently not supported" + return 1 + ;; + esac + ;; + "ASUS") + case "$SYSTEM_MODEL" in + "KGPE-D16") + DASHARO_REL_NAME="asus_kgpe-d16" + DASHARO_REL_VER="0.4.0" + CAN_INSTALL_BIOS="true" + case "$FLASH_CHIP_SIZE" in + "2") + BIOS_HASH_LINK_COMM="65e5370e9ea6b8ae7cd6cc878a031a4ff3a8f5d36830ef39656b8e5a6e37e889 $BIOS_UPDATE_FILE" + BIOS_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_vboot_notpm.rom" + ;; + "8") + BIOS_HASH_LINK_COMM="da4e6217d50f2ac199dcb9a927a0bc02aa4e792ed73c8c9bac8ba74fc787dbef $BIOS_UPDATE_FILE" + BIOS_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_${FLASH_CHIP_SIZE}M_vboot_notpm.rom" + ;; + "16") + BIOS_HASH_LINK_COMM="20055cf57185f149259706f58d5e9552a1589259c6617999c1ac7d8d3c960020 $BIOS_UPDATE_FILE" + BIOS_LINK_COMM="$FW_STORE_URL/$DASHARO_REL_NAME/v$DASHARO_REL_VER/${DASHARO_REL_NAME}_v${DASHARO_REL_VER}_${FLASH_CHIP_SIZE}M_vboot_notpm.rom" + ;; + *) + print_error "Platform uses chipset with not supported size" + return 1 + ;; + esac NEED_SMBIOS_MIGRATION="true" + ;; + *) + print_error "Board model $SYSTEM_MODEL is currently not supported" + return 1 + ;; + esac + ;; + "PC Engines") + # Common configuration for all PC Engines releases: + DASHARO_REL_VER_DPP="0.9.0" + CAN_INSTALL_BIOS="true" + DASHARO_REL_VER_DPP_SEABIOS="24.05.00.01" + PROGRAMMER_BIOS="internal:boardmismatch=force" + NEED_SMMSTORE_MIGRATION="true" + NEED_BOOTSPLASH_MIGRATION="true" + FLASH_CHIP_LIST="W25Q64JV-.Q" + + shopt -s nocasematch + case "$SYSTEM_MODEL" in + "APU2") + DASHARO_REL_NAME="pcengines_apu2" + ;; + "APU3") + DASHARO_REL_NAME="pcengines_apu3" + ;; + "APU4") + DASHARO_REL_NAME="pcengines_apu4" + ;; + "APU6") + DASHARO_REL_NAME="pcengines_apu6" + ;; + *) + print_error "Board model $SYSTEM_MODEL is currently not supported" + return 1 + ;; + esac - case "$SYSTEM_MODEL" in - "ODROID-H4") - PLATFORM_SIGN_KEY="dasharo/hardkernel_odroid_h4/dasharo-release-0.x-compatible-with-hardkernel-odroid-h4-family-signing-key.asc" - DASHARO_REL_NAME="hardkernel_odroid_h4" - DASHARO_REL_VER_DPP="0.9.0" - ;; - *) - print_error "Board model $SYSTEM_MODEL is currently not supported" - return 1 - ;; - esac + BIOS_LINK_DPP="${FW_STORE_URL_DPP}/pcengines_apu2/v${DASHARO_REL_VER_DPP}/${DASHARO_REL_NAME}_v${DASHARO_REL_VER_DPP}.rom" + BIOS_LINK_DPP_SEABIOS="${FW_STORE_URL_DPP}/pcengines_apu2/v${DASHARO_REL_VER_DPP_SEABIOS}/${DASHARO_REL_NAME}_seabios_v${DASHARO_REL_VER_DPP_SEABIOS}.rom" + + shopt -u nocasematch + ;; + "HARDKERNEL") + NEED_SMBIOS_MIGRATION="true" - BIOS_LINK_DPP="$FW_STORE_URL_DPP/$DASHARO_REL_NAME/v$DASHARO_REL_VER_DPP/${DASHARO_REL_NAME}_v$DASHARO_REL_VER_DPP.rom" + case "$SYSTEM_MODEL" in + "ODROID-H4") + PLATFORM_SIGN_KEY="dasharo/hardkernel_odroid_h4/dasharo-release-0.x-compatible-with-hardkernel-odroid-h4-family-signing-key.asc" + DASHARO_REL_NAME="hardkernel_odroid_h4" + DASHARO_REL_VER_DPP="0.9.0" ;; - "QEMU"|"Emulation") - case "$SYSTEM_MODEL" in - *Q35*ICH9*|*q35*ich9*) - # Update type: - CAN_INSTALL_BIOS="true" - # Download and versioning variables: - DASHARO_REL_NAME_CAP="qemu_q35" - DASHARO_REL_VER_CAP="0.2.0" - DASHARO_SUPPORT_CAP_FROM="0.2.0" - # TODO: wait till the binaries will be uploaded to the server. - BIOS_LINK_COMM_CAP="${FW_STORE_URL}/${DASHARO_REL_NAME_CAP}/v${DASHARO_REL_VER_CAP}/" - ;; - *) - print_error "Board model $SYSTEM_MODEL is currently not supported" - return 1 - ;; - esac + *) + print_error "Board model $SYSTEM_MODEL is currently not supported" + return 1 + ;; + esac + + BIOS_LINK_DPP="$FW_STORE_URL_DPP/$DASHARO_REL_NAME/v$DASHARO_REL_VER_DPP/${DASHARO_REL_NAME}_v$DASHARO_REL_VER_DPP.rom" + ;; + "QEMU" | "Emulation") + case "$SYSTEM_MODEL" in + *Q35*ICH9* | *q35*ich9*) + # Update type: + CAN_INSTALL_BIOS="true" + # Download and versioning variables: + DASHARO_REL_NAME_CAP="qemu_q35" + DASHARO_REL_VER_CAP="0.2.0" + DASHARO_SUPPORT_CAP_FROM="0.2.0" + # TODO: wait till the binaries will be uploaded to the server. + BIOS_LINK_COMM_CAP="${FW_STORE_URL}/${DASHARO_REL_NAME_CAP}/v${DASHARO_REL_VER_CAP}/" ;; *) - print_error "Board vendor: $SYSTEM_VENDOR is currently not supported" + print_error "Board model $SYSTEM_MODEL is currently not supported" return 1 ;; + esac + ;; + *) + print_error "Board vendor: $SYSTEM_VENDOR is currently not supported" + return 1 + ;; esac # Set some default values at the end: @@ -673,35 +673,34 @@ board_config() { } check_flash_lock() { - $FLASHROM check_flash_lock_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} > /tmp/check_flash_lock 2> /tmp/check_flash_lock.err - # Check in flashrom output if lock is enabled - grep -q 'PR0: Warning:.* is read-only\|SMM protection is enabled' /tmp/check_flash_lock.err - if [ $? -eq 0 ]; then - print_warning "Flash lock enabled, please go into BIOS setup / Dasharo System Features / Dasharo\r + $FLASHROM check_flash_lock_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} >/tmp/check_flash_lock 2>/tmp/check_flash_lock.err + # Check in flashrom output if lock is enabled + grep -q 'PR0: Warning:.* is read-only\|SMM protection is enabled' /tmp/check_flash_lock.err + if [ $? -eq 0 ]; then + print_warning "Flash lock enabled, please go into BIOS setup / Dasharo System Features / Dasharo\r \rSecurity Options and enable access to flash with flashrom.\r\n \rYou can learn more about this on: https://docs.dasharo.com/dasharo-menu-docs/dasharo-system-features/#dasharo-security-options" - exit 1 - fi + exit 1 + fi } check_flash_chip() { echo "Gathering flash chip and chipset information..." - $FLASHROM flash_chip_name_mock -p "$PROGRAMMER_BIOS" --flash-name >> "$FLASH_INFO_FILE" 2>> "$ERR_LOG_FILE" + $FLASHROM flash_chip_name_mock -p "$PROGRAMMER_BIOS" --flash-name >>"$FLASH_INFO_FILE" 2>>"$ERR_LOG_FILE" if [ $? -eq 0 ]; then echo -n "Flash information: " tail -n1 "$FLASH_INFO_FILE" - FLASH_CHIP_SIZE=$(($($FLASHROM flash_chip_size_mock -p "$PROGRAMMER_BIOS" --flash-size 2>> /dev/null | tail -n1) / 1024 / 1024)) + FLASH_CHIP_SIZE=$(($($FLASHROM flash_chip_size_mock -p "$PROGRAMMER_BIOS" --flash-size 2>>/dev/null | tail -n1) / 1024 / 1024)) echo -n "Flash size: " echo ${FLASH_CHIP_SIZE}M else - for flash_name in $FLASH_CHIP_LIST - do - $FLASHROM flash_chip_name_mock -p "$PROGRAMMER_BIOS" -c "$flash_name" --flash-name >> "$FLASH_INFO_FILE" 2>> "$ERR_LOG_FILE" + for flash_name in $FLASH_CHIP_LIST; do + $FLASHROM flash_chip_name_mock -p "$PROGRAMMER_BIOS" -c "$flash_name" --flash-name >>"$FLASH_INFO_FILE" 2>>"$ERR_LOG_FILE" if [ $? -eq 0 ]; then echo "Chipset found" tail -n1 "$FLASH_INFO_FILE" FLASH_CHIP_SELECT="-c ${flash_name}" - FLASH_CHIP_SIZE=$(($($FLASHROM flash_chip_size_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} --flash-size 2>> /dev/null | tail -n1) / 1024 / 1024)) + FLASH_CHIP_SIZE=$(($($FLASHROM flash_chip_size_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} --flash-size 2>>/dev/null | tail -n1) / 1024 / 1024)) echo "Chipset size" echo ${FLASH_CHIP_SIZE}M break @@ -714,26 +713,26 @@ check_flash_chip() { } compare_versions() { - # return 1 if ver2 > ver1 - # return 0 otherwise - local ver1= - local ver2= - local compare= - # convert version ending with '-rc' to '-rc.' where is number - # as semantic versioning compares whole 'rc' as alphanumeric identifier - # which results in rc2 > rc12. More information at https://semver.org/ - ver1=$(sed -r "s/-rc([0-9]+)$/-rc.\1/" <<< "$1") - ver2=$(sed -r "s/-rc([0-9]+)$/-rc.\1/" <<< "$2") - - if ! python3 -m semver check "$ver1" || ! python3 -m semver check "$ver2"; then - error_exit "Incorrect version format" - fi - compare=$(python3 -m semver compare "$ver1" "$ver2") - if [ "$compare" -eq -1 ]; then - return 1 - else - return 0 - fi + # return 1 if ver2 > ver1 + # return 0 otherwise + local ver1= + local ver2= + local compare= + # convert version ending with '-rc' to '-rc.' where is number + # as semantic versioning compares whole 'rc' as alphanumeric identifier + # which results in rc2 > rc12. More information at https://semver.org/ + ver1=$(sed -r "s/-rc([0-9]+)$/-rc.\1/" <<<"$1") + ver2=$(sed -r "s/-rc([0-9]+)$/-rc.\1/" <<<"$2") + + if ! python3 -m semver check "$ver1" || ! python3 -m semver check "$ver2"; then + error_exit "Incorrect version format" + fi + compare=$(python3 -m semver compare "$ver1" "$ver2") + if [ "$compare" -eq -1 ]; then + return 1 + else + return 0 + fi } download_bios() { @@ -787,31 +786,31 @@ download_ec() { download_keys() { mkdir $KEYS_DIR - wget -O $KEYS_DIR/recovery_key.vbpubk https://github.com/Dasharo/vboot/raw/dasharo/tests/devkeys/recovery_key.vbpubk >> $ERR_LOG_FILE 2>&1 - wget -O $KEYS_DIR/firmware.keyblock https://github.com/Dasharo/vboot/raw/dasharo/tests/devkeys/firmware.keyblock >> $ERR_LOG_FILE 2>&1 - wget -O $KEYS_DIR/firmware_data_key.vbprivk https://github.com/Dasharo/vboot/raw/dasharo/tests/devkeys/firmware_data_key.vbprivk >> $ERR_LOG_FILE 2>&1 - wget -O $KEYS_DIR/kernel_subkey.vbpubk https://github.com/Dasharo/vboot/raw/dasharo/tests/devkeys/kernel_subkey.vbpubk >> $ERR_LOG_FILE 2>&1 - wget -O $KEYS_DIR/root_key.vbpubk https://github.com/Dasharo/vboot/raw/dasharo/tests/devkeys/root_key.vbpubk >> $ERR_LOG_FILE 2>&1 + wget -O $KEYS_DIR/recovery_key.vbpubk https://github.com/Dasharo/vboot/raw/dasharo/tests/devkeys/recovery_key.vbpubk >>$ERR_LOG_FILE 2>&1 + wget -O $KEYS_DIR/firmware.keyblock https://github.com/Dasharo/vboot/raw/dasharo/tests/devkeys/firmware.keyblock >>$ERR_LOG_FILE 2>&1 + wget -O $KEYS_DIR/firmware_data_key.vbprivk https://github.com/Dasharo/vboot/raw/dasharo/tests/devkeys/firmware_data_key.vbprivk >>$ERR_LOG_FILE 2>&1 + wget -O $KEYS_DIR/kernel_subkey.vbpubk https://github.com/Dasharo/vboot/raw/dasharo/tests/devkeys/kernel_subkey.vbpubk >>$ERR_LOG_FILE 2>&1 + wget -O $KEYS_DIR/root_key.vbpubk https://github.com/Dasharo/vboot/raw/dasharo/tests/devkeys/root_key.vbpubk >>$ERR_LOG_FILE 2>&1 } get_signing_keys() { - local platform_keys=$PLATFORM_SIGN_KEY - echo -n "Getting platform specific GPG key... " - for key in $platform_keys; do - wget -q https://raw.githubusercontent.com/3mdeb/3mdeb-secpack/master/$key -O - | gpg --import - >> $ERR_LOG_FILE 2>&1 - error_check "Cannot get $key key to verify signatures." - done - print_ok "Done" + local platform_keys=$PLATFORM_SIGN_KEY + echo -n "Getting platform specific GPG key... " + for key in $platform_keys; do + wget -q https://raw.githubusercontent.com/3mdeb/3mdeb-secpack/master/$key -O - | gpg --import - >>$ERR_LOG_FILE 2>&1 + error_check "Cannot get $key key to verify signatures." + done + print_ok "Done" } verify_artifacts() { -# This function checks downloaded files, the files that are being downloaded -# should have hashes provided on the server too. The hashes will ben downloaded -# and the binaries will be verified upon them. -# -# In case of .rom files it will be enough but capsules have additional -# protection layer built in, the binaries they provide will be verified by -# drivers, so no need to implement it here. + # This function checks downloaded files, the files that are being downloaded + # should have hashes provided on the server too. The hashes will ben downloaded + # and the binaries will be verified upon them. + # + # In case of .rom files it will be enough but capsules have additional + # protection layer built in, the binaries they provide will be verified by + # drivers, so no need to implement it here. local _update_file="" local _hash_file="" local _sign_file="" @@ -822,33 +821,33 @@ verify_artifacts() { local _type="$1" case $_type in - ec) - _update_file=$EC_UPDATE_FILE - _hash_file=$EC_HASH_FILE - _sign_file=$EC_SIGN_FILE - _name="Dasharo EC" - shift - ;; - bios) - _update_file=$BIOS_UPDATE_FILE - _hash_file=$BIOS_HASH_FILE - _sign_file=$BIOS_SIGN_FILE - _name="Dasharo" - shift - ;; - *) - error_exit "Unknown artifact type: $_type" - ;; + ec) + _update_file=$EC_UPDATE_FILE + _hash_file=$EC_HASH_FILE + _sign_file=$EC_SIGN_FILE + _name="Dasharo EC" + shift + ;; + bios) + _update_file=$BIOS_UPDATE_FILE + _hash_file=$BIOS_HASH_FILE + _sign_file=$BIOS_SIGN_FILE + _name="Dasharo" + shift + ;; + *) + error_exit "Unknown artifact type: $_type" + ;; esac echo -n "Checking $_name firmware checksum... " - sha256sum --check <(echo "$(cat $_hash_file | cut -d ' ' -f 1)" $_update_file) >> $ERR_LOG_FILE 2>&1 + sha256sum --check <(echo "$(cat $_hash_file | cut -d ' ' -f 1)" $_update_file) >>$ERR_LOG_FILE 2>&1 error_check "Failed to verify $_name firmware checksum" print_ok "Verified." if [ -n "$PLATFORM_SIGN_KEY" ]; then echo -n "Checking $_name firmware signature... " - _sig_result="$(cat $_hash_file | gpg --verify $_sign_file - >> $ERR_LOG_FILE 2>&1)" + _sig_result="$(cat $_hash_file | gpg --verify $_sign_file - >>$ERR_LOG_FILE 2>&1)" error_check "Failed to verify $_name firmware signature.$'\n'$_sig_result" print_ok "Verified." fi @@ -870,16 +869,16 @@ check_intel_regions() { BOARD_GBE_REGION_RW=0 BOARD_GBE_REGION_LOCKED=0 - grep -q "Flash Descriptor region" <<< "$FLASH_REGIONS" && BOARD_HAS_FD_REGION=1 - grep -qE "Flash Descriptor region.*read-write" <<< "$FLASH_REGIONS" && BOARD_FD_REGION_RW=1 + grep -q "Flash Descriptor region" <<<"$FLASH_REGIONS" && BOARD_HAS_FD_REGION=1 + grep -qE "Flash Descriptor region.*read-write" <<<"$FLASH_REGIONS" && BOARD_FD_REGION_RW=1 - grep -q "Management Engine region" <<< "$FLASH_REGIONS" && BOARD_HAS_ME_REGION=1 - grep -qE "Management Engine region.*read-write" <<< "$FLASH_REGIONS" && BOARD_ME_REGION_RW=1 - grep -qE "Management Engine region.*locked" <<< "$FLASH_REGIONS" && BOARD_ME_REGION_LOCKED=1 + grep -q "Management Engine region" <<<"$FLASH_REGIONS" && BOARD_HAS_ME_REGION=1 + grep -qE "Management Engine region.*read-write" <<<"$FLASH_REGIONS" && BOARD_ME_REGION_RW=1 + grep -qE "Management Engine region.*locked" <<<"$FLASH_REGIONS" && BOARD_ME_REGION_LOCKED=1 - grep -q "Gigabit Ethernet region" <<< "$FLASH_REGIONS" && BOARD_HAS_GBE_REGION=1 - grep -qE "Gigabit Ethernet region.*read-write" <<< "$FLASH_REGIONS" && BOARD_GBE_REGION_RW=1 - grep -qE "Gigabit Ethernet region.*locked" <<< "$FLASH_REGIONS" && BOARD_GBE_REGION_LOCKED=1 + grep -q "Gigabit Ethernet region" <<<"$FLASH_REGIONS" && BOARD_HAS_GBE_REGION=1 + grep -qE "Gigabit Ethernet region.*read-write" <<<"$FLASH_REGIONS" && BOARD_GBE_REGION_RW=1 + grep -qE "Gigabit Ethernet region.*locked" <<<"$FLASH_REGIONS" && BOARD_GBE_REGION_LOCKED=1 } check_blobs_in_binary() { @@ -888,21 +887,21 @@ check_blobs_in_binary() { # If there is no descriptor, there is no ME as well, so skip the check if [ $BOARD_HAS_FD_REGION -ne 0 ]; then - ME_OFFSET=$($IFDTOOL check_blobs_in_binary_mock -d $1 2> /dev/null | grep "Flash Region 2 (Intel ME):" | sed 's/Flash Region 2 (Intel ME)\://' | awk '{print $1;}') + ME_OFFSET=$($IFDTOOL check_blobs_in_binary_mock -d $1 2>/dev/null | grep "Flash Region 2 (Intel ME):" | sed 's/Flash Region 2 (Intel ME)\://' | awk '{print $1;}') # Check for IFD signature at offset 0 (old descriptors) - if [ "$(tail -c +0 $1|head -c 4|xxd -ps)" == "5aa5f00f" ]; then + if [ "$(tail -c +0 $1 | head -c 4 | xxd -ps)" == "5aa5f00f" ]; then BINARY_HAS_FD=1 fi # Check for IFD signature at offset 16 (new descriptors) - if [ "$(tail -c +17 $1|head -c 4|xxd -ps)" == "5aa5f00f" ]; then + if [ "$(tail -c +17 $1 | head -c 4 | xxd -ps)" == "5aa5f00f" ]; then BINARY_HAS_FD=1 fi # Check for ME FPT signature at ME offset + 16 (old ME) - if [ "$(tail -c +$((0x$ME_OFFSET + 17)) $1|head -c 4|tr -d '\0')" == "\$FPT" ]; then + if [ "$(tail -c +$((0x$ME_OFFSET + 17)) $1 | head -c 4 | tr -d '\0')" == "\$FPT" ]; then BINARY_HAS_ME=1 fi # Check for aa55 signature at ME offset + 4096 (new ME) - if [ "$(tail -c +$((0x$ME_OFFSET + 4097)) $1|head -c 2|xxd -ps)" == "aa55" ]; then + if [ "$(tail -c +$((0x$ME_OFFSET + 4097)) $1 | head -c 2 | xxd -ps)" == "aa55" ]; then BINARY_HAS_ME=1 fi fi @@ -921,70 +920,69 @@ check_if_me_disabled() { if check_if_heci_present; then ME_OPMODE="$(check_me_op_mode)" if [ $ME_OPMODE == "0" ]; then - echo "ME is not disabled" >> $ERR_LOG_FILE + echo "ME is not disabled" >>$ERR_LOG_FILE return elif [ $ME_OPMODE == "2" ]; then - echo "ME is disabled (HAP/Debug Mode)" >> $ERR_LOG_FILE + echo "ME is disabled (HAP/Debug Mode)" >>$ERR_LOG_FILE ME_DISABLED=1 return elif [ $ME_OPMODE == "3" ]; then - echo "ME is soft disabled (HECI)" >> $ERR_LOG_FILE + echo "ME is soft disabled (HECI)" >>$ERR_LOG_FILE ME_DISABLED=1 return elif [ $ME_OPMODE == "4" ]; then - echo "ME disabled by Security Override Jumper/FDOPS" >> $ERR_LOG_FILE + echo "ME disabled by Security Override Jumper/FDOPS" >>$ERR_LOG_FILE ME_DISABLED=1 return elif [ $ME_OPMODE == "5" ]; then - echo "ME disabled by Security Override MEI Message/HMRFPO" >> $ERR_LOG_FILE + echo "ME disabled by Security Override MEI Message/HMRFPO" >>$ERR_LOG_FILE ME_DISABLED=1 return elif [ $ME_OPMODE == "6" ]; then - echo "ME disabled by Security Override MEI Message/HMRFPO" >> $ERR_LOG_FILE + echo "ME disabled by Security Override MEI Message/HMRFPO" >>$ERR_LOG_FILE ME_DISABLED=1 return elif [ $ME_OPMODE == "7" ]; then - echo "ME disabled (Enhanced Debug Mode) or runs Ignition FW" >> $ERR_LOG_FILE + echo "ME disabled (Enhanced Debug Mode) or runs Ignition FW" >>$ERR_LOG_FILE ME_DISABLED=1 return else print_warning "Unknown ME operation mode, assuming enabled." - echo "Unknown ME operation mode, assuming enabled." >> $ERR_LOG_FILE + echo "Unknown ME operation mode, assuming enabled." >>$ERR_LOG_FILE return fi else # If we are running coreboot, check for status in logs - $CBMEM check_if_me_disabled_mock -1 | grep -q "ME is disabled" && ME_DISABLED=1 && return # HECI (soft) disabled + $CBMEM check_if_me_disabled_mock -1 | grep -q "ME is disabled" && ME_DISABLED=1 && return # HECI (soft) disabled $CBMEM check_if_me_disabled_mock -1 | grep -q "ME is HAP disabled" && ME_DISABLED=1 && return # HAP disabled # TODO: If proprietary BIOS, then also try to check SMBIOS for ME FWSTS # BTW we could do the same in coreboot, expose FWSTS in SMBIOS before it # gets disabled print_warning "Can not determine if ME is disabled, assuming enabled." - echo "Can not determine if ME is disabled, assuming enabled." >> $ERR_LOG_FILE + echo "Can not determine if ME is disabled, assuming enabled." >>$ERR_LOG_FILE fi } force_me_update() { - echo - print_warning "Flashing ME when not in disabled state may cause unexpected power management issues." - print_warning "Recovering from such state may require removal of AC power supply and resetting CMOS battery." - print_warning "Keeping an older version of ME may cause a CPU to perform less efficient, e.g. if upgraded the CPU to a newer generation." - print_warning "You have been warned." - while : ; do + echo + print_warning "Flashing ME when not in disabled state may cause unexpected power management issues." + print_warning "Recovering from such state may require removal of AC power supply and resetting CMOS battery." + print_warning "Keeping an older version of ME may cause a CPU to perform less efficient, e.g. if upgraded the CPU to a newer generation." + print_warning "You have been warned." + while :; do echo read -r -p "Skip ME flashing and proceed with BIOS/firmware flashing/updating? (Y|n) " OPTION echo case ${OPTION} in - yes|y|Y|Yes|YES) - print_warning "Proceeding without ME flashing, because we were asked to." - break - ;; - n|N) - error_exit "Cancelling flashing process..." - ;; - *) - ;; + yes | y | Y | Yes | YES) + print_warning "Proceeding without ME flashing, because we were asked to." + break + ;; + n | N) + error_exit "Cancelling flashing process..." + ;; + *) ;; esac done } @@ -1000,15 +998,15 @@ set_flashrom_update_params() { # We need to read whole binary (or BIOS region), otherwise cbfstool will # return different attributes for CBFS regions echo "Checking flash layout." - $FLASHROM read_flash_layout_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} ${FLASHROM_ADD_OPT_UPDATE} -r $BIOS_DUMP_FILE > /dev/null 2>&1 + $FLASHROM read_flash_layout_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} ${FLASHROM_ADD_OPT_UPDATE} -r $BIOS_DUMP_FILE >/dev/null 2>&1 if [ $? -eq 0 ] && [ -f "$BIOS_DUMP_FILE" ]; then - BOARD_FMAP_LAYOUT=$($CBFSTOOL layout_mock $BIOS_DUMP_FILE layout -w 2> /dev/null) - BINARY_FMAP_LAYOUT=$($CBFSTOOL layout_mock $1 layout -w 2> /dev/null) - diff <(echo "$BOARD_FMAP_LAYOUT") <(echo "$BINARY_FMAP_LAYOUT") > /dev/null 2>&1 + BOARD_FMAP_LAYOUT=$($CBFSTOOL layout_mock $BIOS_DUMP_FILE layout -w 2>/dev/null) + BINARY_FMAP_LAYOUT=$($CBFSTOOL layout_mock $1 layout -w 2>/dev/null) + diff <(echo "$BOARD_FMAP_LAYOUT") <(echo "$BINARY_FMAP_LAYOUT") >/dev/null 2>&1 # If layout is identical, perform standard update using FMAP only if [ $? -eq 0 ]; then # Simply update RW_A fmap region if exists - grep -q "RW_SECTION_A" <<< $BINARY_FMAP_LAYOUT + grep -q "RW_SECTION_A" <<<$BINARY_FMAP_LAYOUT if [ $? -eq 0 ]; then FLASHROM_ADD_OPT_UPDATE="-N --fmap -i RW_SECTION_A -i WP_RO" else @@ -1016,11 +1014,11 @@ set_flashrom_update_params() { FLASHROM_ADD_OPT_UPDATE="-N --fmap -i COREBOOT" fi # If RW_B present, use this variable later to perform 2-step update - grep -q "RW_SECTION_B" <<< $BINARY_FMAP_LAYOUT && BINARY_HAS_RW_B=0 + grep -q "RW_SECTION_B" <<<$BINARY_FMAP_LAYOUT && BINARY_HAS_RW_B=0 fi else print_warning "Could not read the FMAP region" - echo "Could not read the FMAP region" >> $ERR_LOG_FILE + echo "Could not read the FMAP region" >>$ERR_LOG_FILE fi } @@ -1041,7 +1039,7 @@ set_intel_regions_update_params() { else print_error "The firmware binary to be flashed contains Flash Descriptor (FD), but FD is not writable!" print_warning "Proceeding without FD flashing, as it is not critical." - echo "The firmware binary contains Flash Descriptor (FD), but FD is not writable!" >> $ERR_LOG_FILE + echo "The firmware binary contains Flash Descriptor (FD), but FD is not writable!" >>$ERR_LOG_FILE fi fi @@ -1051,12 +1049,12 @@ set_intel_regions_update_params() { if [ $ME_DISABLED -eq 1 ]; then FLASHROM_ADD_OPT_REGIONS+=" -i me" else - echo "The firmware binary to be flashed contains Management Engine (ME), but ME is not disabled!" >> $ERR_LOG_FILE + echo "The firmware binary to be flashed contains Management Engine (ME), but ME is not disabled!" >>$ERR_LOG_FILE print_error "The firmware binary contains Management Engine (ME), but ME is not disabled!" force_me_update fi else - echo "The firmware binary to be flashed contains Management Engine (ME), but ME is not writable!" >> $ERR_LOG_FILE + echo "The firmware binary to be flashed contains Management Engine (ME), but ME is not writable!" >>$ERR_LOG_FILE print_error "The firmware binary contains Management Engine (ME), but ME is not writable!" fi fi @@ -1067,15 +1065,80 @@ handle_fw_switching() { local _can_switch_to_heads=$1 if [ "$_can_switch_to_heads" == "true" ] && [ "$DASHARO_FLAVOR" != "Dasharo (coreboot+heads)" ]; then - while : ; do + while :; do echo read -r -p "Would you like to switch to Dasharo heads firmware? (Y|n) " OPTION echo case ${OPTION} in - yes|y|Y|Yes|YES) - UPDATE_VERSION=$HEADS_REL_VER_DPP + yes | y | Y | Yes | YES) + UPDATE_VERSION=$HEADS_REL_VER_DPP + FLASHROM_ADD_OPT_UPDATE_OVERRIDE=$HEADS_SWITCH_FLASHROM_OPT_OVERRIDE + BIOS_HASH_LINK="${HEADS_HASH_LINK_DPP}" + BIOS_SIGN_LINK="${HEADS_SIGN_LINK_DPP}" + BIOS_LINK="$HEADS_LINK_DPP" + + # Check EC link additionally, not all platforms have Embedded Controllers: + if [ -n "$EC_LINK_DPP" ]; then + EC_LINK=$EC_LINK_DPP + EC_HASH_LINK=$EC_HASH_LINK_DPP + EC_SIGN_LINK=$EC_SIGN_LINK_DPP + elif [ -n "$EC_LINK_COMM" ]; then + EC_LINK=$EC_LINK_COMM + EC_HASH_LINK=$EC_HASH_LINK_COMM + EC_SIGN_LINK=$EC_SIGN_LINK_COMM + fi + + export SWITCHING_TO="heads" + echo + echo "Switching to Dasharo heads firmware v$UPDATE_VERSION" + break + ;; + n | N) + compare_versions $DASHARO_VERSION $UPDATE_VERSION + if [ $? -ne 1 ]; then + error_exit "No update available for your machine" + fi + echo "Will not install Dasharo heads firmware. Proceeding with regular Dasharo firmware update." + break + ;; + *) ;; + esac + done + elif [ -n "$DPP_IS_LOGGED" ] && [ -n "$HEADS_LINK_DPP" ]; then + local _heads_dpp=1 + curl -sfI -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$HEADS_LINK_DPP" -o /dev/null + _heads_dpp=$? + # We are on heads, offer switch back or perform update if DPP gives access to heads + if [ "$DASHARO_FLAVOR" == "Dasharo (coreboot+heads)" ]; then + while :; do + echo + print_warning 'If you are running heads firmware variant and want to update, say "n" here.' + print_warning 'You will be asked for heads update confirmation in a moment.' + print_warning 'Say "Y" only if you want to migrate from heads to UEFI firmware variant.' + read -r -p "Would you like to switch back to the regular (UEFI) Dasharo firmware variant? (Y|n) " OPTION + echo + + case ${OPTION} in + yes | y | Y | Yes | YES) + echo + echo "Switching back to regular Dasharo firmware v$UPDATE_VERSION" + echo FLASHROM_ADD_OPT_UPDATE_OVERRIDE=$HEADS_SWITCH_FLASHROM_OPT_OVERRIDE + export SWITCHING_TO="uefi" + break + ;; + n | N) + if [ $_heads_dpp -ne 0 ]; then + error_exit "No update available for your machine" + fi + UPDATE_VERSION=$HEADS_REL_VER_DPP + compare_versions $DASHARO_VERSION $UPDATE_VERSION + if [ $? -ne 1 ]; then + error_exit "No update available for your machine" + fi + echo "Will not switch back to regular Dasharo firmware. Proceeding with Dasharo heads firmware update to $UPDATE_VERSION." + FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" BIOS_HASH_LINK="${HEADS_HASH_LINK_DPP}" BIOS_SIGN_LINK="${HEADS_SIGN_LINK_DPP}" BIOS_LINK="$HEADS_LINK_DPP" @@ -1091,76 +1154,9 @@ handle_fw_switching() { EC_SIGN_LINK=$EC_SIGN_LINK_COMM fi - export SWITCHING_TO="heads" - echo - echo "Switching to Dasharo heads firmware v$UPDATE_VERSION" break ;; - n|N) - compare_versions $DASHARO_VERSION $UPDATE_VERSION - if [ $? -ne 1 ]; then - error_exit "No update available for your machine" - fi - echo "Will not install Dasharo heads firmware. Proceeding with regular Dasharo firmware update." - break - ;; - *) - ;; - esac - done - elif [ -n "$DPP_IS_LOGGED" ] && [ -n "$HEADS_LINK_DPP" ]; then - local _heads_dpp=1 - curl -sfI -u "$USER_DETAILS" -H "$CLOUD_REQUEST" "$HEADS_LINK_DPP" -o /dev/null - _heads_dpp=$? - # We are on heads, offer switch back or perform update if DPP gives access to heads - if [ "$DASHARO_FLAVOR" == "Dasharo (coreboot+heads)" ]; then - while : ; do - echo - print_warning 'If you are running heads firmware variant and want to update, say "n" here.' - print_warning 'You will be asked for heads update confirmation in a moment.' - print_warning 'Say "Y" only if you want to migrate from heads to UEFI firmware variant.' - read -r -p "Would you like to switch back to the regular (UEFI) Dasharo firmware variant? (Y|n) " OPTION - echo - - case ${OPTION} in - yes|y|Y|Yes|YES) - echo - echo "Switching back to regular Dasharo firmware v$UPDATE_VERSION" - echo - FLASHROM_ADD_OPT_UPDATE_OVERRIDE=$HEADS_SWITCH_FLASHROM_OPT_OVERRIDE - export SWITCHING_TO="uefi" - break - ;; - n|N) - if [ $_heads_dpp -ne 0 ]; then - error_exit "No update available for your machine" - fi - UPDATE_VERSION=$HEADS_REL_VER_DPP - compare_versions $DASHARO_VERSION $UPDATE_VERSION - if [ $? -ne 1 ]; then - error_exit "No update available for your machine" - fi - echo "Will not switch back to regular Dasharo firmware. Proceeding with Dasharo heads firmware update to $UPDATE_VERSION." - FLASHROM_ADD_OPT_UPDATE_OVERRIDE="--ifd -i bios" - BIOS_HASH_LINK="${HEADS_HASH_LINK_DPP}" - BIOS_SIGN_LINK="${HEADS_SIGN_LINK_DPP}" - BIOS_LINK="$HEADS_LINK_DPP" - - # Check EC link additionally, not all platforms have Embedded Controllers: - if [ -n "$EC_LINK_DPP" ]; then - EC_LINK=$EC_LINK_DPP - EC_HASH_LINK=$EC_HASH_LINK_DPP - EC_SIGN_LINK=$EC_SIGN_LINK_DPP - elif [ -n "$EC_LINK_COMM" ]; then - EC_LINK=$EC_LINK_COMM - EC_HASH_LINK=$EC_HASH_LINK_COMM - EC_SIGN_LINK=$EC_SIGN_LINK_COMM - fi - - break - ;; - *) - ;; + *) ;; esac done fi @@ -1174,27 +1170,26 @@ handle_fw_switching() { echo echo "Latest available Dasharo version: $HEADS_REL_VER_DPP" echo - while : ; do + while :; do echo read -r -p "Would you like to switch back to the regular Dasharo firmware? (Y|n) " OPTION echo case ${OPTION} in - yes|y|Y|Yes|YES) - echo - echo "Switching back to regular Dasharo firmware v$UPDATE_VERSION" - echo - FLASHROM_ADD_OPT_UPDATE_OVERRIDE=$HEADS_SWITCH_FLASHROM_OPT_OVERRIDE - export SWITCHING_TO="uefi" - break - ;; - n|N) - print_warning "No update currently possible. Aborting update process..." - exit 0 - break; - ;; - *) - ;; + yes | y | Y | Yes | YES) + echo + echo "Switching back to regular Dasharo firmware v$UPDATE_VERSION" + echo + FLASHROM_ADD_OPT_UPDATE_OVERRIDE=$HEADS_SWITCH_FLASHROM_OPT_OVERRIDE + export SWITCHING_TO="uefi" + break + ;; + n | N) + print_warning "No update currently possible. Aborting update process..." + exit 0 + break + ;; + *) ;; esac done else @@ -1207,7 +1202,7 @@ handle_fw_switching() { sync_clocks() { echo "Waiting for system clock to be synced ..." - chronyc waitsync 10 0 0 5 &> /dev/null + chronyc waitsync 10 0 0 5 &>/dev/null if [[ $? -ne 0 ]]; then print_warning "Failed to sync system clock with NTP server!" print_warning "Some time critical tasks might fail!" @@ -1215,8 +1210,8 @@ sync_clocks() { } print_disclaimer() { -echo -e \ -"Please note that the report is not anonymous, but we will use it only for\r + echo -e \ + "Please note that the report is not anonymous, but we will use it only for\r backup and future improvement of the Dasharo product. Every log is encrypted\r and sent over HTTPS, so security is assured.\r If you still have doubts, you can skip HCL report generation.\r\n @@ -1256,17 +1251,17 @@ show_ram_inf() { # field but ignore "Bank Locator" field, cos it will be included by parent # condition: if [[ $line =~ Bank\ Locator ]]; then - continue # Ignore Bank Locator field. + continue # Ignore Bank Locator field. elif [[ $line =~ Locator: ]]; then - entry="${line#*: }" # Extract the Locator value. + entry="${line#*: }" # Extract the Locator value. elif [[ $line =~ Part\ Number: ]]; then - entry+=": ${NORMAL}${line#*: }" # Concatenate Part Number value with - # Locator and add a colon with yellow - # color termination. + entry+=": ${NORMAL}${line#*: }" # Concatenate Part Number value with + # Locator and add a colon with yellow + # color termination. memory_devices_array+=("$entry") fi fi - done <<< "$data" + done <<<"$data" # Print the extracted values preformatted: for entry in "${memory_devices_array[@]}"; do @@ -1310,7 +1305,7 @@ show_dpp_credentials() { } show_ssh_info() { - if systemctl is-active sshd.service &> /dev/null; then + if systemctl is-active sshd.service &>/dev/null; then local ip="" ip=$(ip -br -f inet a show scope global | grep UP | awk '{ print $3 }' | tr '\n' ' ') # Display "check your connection" in red color in IP field in case no IPV4 @@ -1347,154 +1342,154 @@ show_main_menu() { fi } -main_menu_options(){ +main_menu_options() { local OPTION=$1 case ${OPTION} in - "${HCL_REPORT_OPT}") - print_disclaimer - read -p "Do you want to support Dasharo development by sending us logs with your hardware configuration? [N/y] " - case ${REPLY} in - yes|y|Y|Yes|YES) - export SEND_LOGS="true" - echo "Thank you for contributing to the Dasharo development!" - ;; - *) - export SEND_LOGS="false" - echo "Logs will be saved in root directory." - echo "Please consider supporting Dasharo by sending the logs next time." - ;; - esac - if [ "${SEND_LOGS}" == "true" ]; then - # DEPLOY_REPORT variable is used in dasharo-hcl-report to determine - # which logs should be printed in the terminal, in the future whole - # dts scripting should get some LOGLEVEL and maybe dumping working - # logs to file - export DEPLOY_REPORT="false" - wait_for_network_connection && ${CMD_DASHARO_HCL_REPORT} && LOGS_SENT="1" - else - export DEPLOY_REPORT="false" - ${CMD_DASHARO_HCL_REPORT} - fi - read -p "Press Enter to continue." - - return 0 + "${HCL_REPORT_OPT}") + print_disclaimer + read -p "Do you want to support Dasharo development by sending us logs with your hardware configuration? [N/y] " + case ${REPLY} in + yes | y | Y | Yes | YES) + export SEND_LOGS="true" + echo "Thank you for contributing to the Dasharo development!" + ;; + *) + export SEND_LOGS="false" + echo "Logs will be saved in root directory." + echo "Please consider supporting Dasharo by sending the logs next time." ;; - "${DASHARO_FIRM_OPT}") - if ! check_if_dasharo; then - # flashrom does not support QEMU, but installation depends on flashrom. - # TODO: this could be handled in a better way: - [ "${SYSTEM_VENDOR}" = "QEMU" ] || [ "${SYSTEM_VENDOR}" = "Emulation" ] && return 0 - - if wait_for_network_connection; then - echo "Preparing ..." - if [ -z "${LOGS_SENT}" ]; then - export SEND_LOGS="true" - export DEPLOY_REPORT="true" - if ! ${CMD_DASHARO_HCL_REPORT}; then - echo -e "Unable to connect to cloud.3mdeb.com for submitting the + esac + if [ "${SEND_LOGS}" == "true" ]; then + # DEPLOY_REPORT variable is used in dasharo-hcl-report to determine + # which logs should be printed in the terminal, in the future whole + # dts scripting should get some LOGLEVEL and maybe dumping working + # logs to file + export DEPLOY_REPORT="false" + wait_for_network_connection && ${CMD_DASHARO_HCL_REPORT} && LOGS_SENT="1" + else + export DEPLOY_REPORT="false" + ${CMD_DASHARO_HCL_REPORT} + fi + read -p "Press Enter to continue." + + return 0 + ;; + "${DASHARO_FIRM_OPT}") + if ! check_if_dasharo; then + # flashrom does not support QEMU, but installation depends on flashrom. + # TODO: this could be handled in a better way: + [ "${SYSTEM_VENDOR}" = "QEMU" ] || [ "${SYSTEM_VENDOR}" = "Emulation" ] && return 0 + + if wait_for_network_connection; then + echo "Preparing ..." + if [ -z "${LOGS_SENT}" ]; then + export SEND_LOGS="true" + export DEPLOY_REPORT="true" + if ! ${CMD_DASHARO_HCL_REPORT}; then + echo -e "Unable to connect to cloud.3mdeb.com for submitting the \rHCL report. Please recheck your internet connection." - else - LOGS_SENT="1" - fi + else + LOGS_SENT="1" fi fi + fi - if [ -n "${LOGS_SENT}" ]; then - ${CMD_DASHARO_DEPLOY} install - fi - else - # TODO: This should be placed in dasharo-deploy: - # For NovaCustom TGL laptops with Dasharo version lower than 1.3.0, - # we shall run the ec_transition script instead. See: - # https://docs.dasharo.com/variants/novacustom_nv4x_tgl/releases/#v130-2022-10-18 - if [ "$SYSTEM_VENDOR" = "Notebook" ]; then - case "$SYSTEM_MODEL" in - "NS50_70MU"|"NV4XMB,ME,MZ") - compare_versions $DASHARO_VERSION 1.3.0 - if [ $? -eq 1 ]; then - # For Dasharo version lesser than 1.3.0 - print_warning "Detected NovaCustom hardware with version < 1.3.0" - print_warning "Need to perform EC transition after which the platform will turn off" - print_warning "Then, please power it on and proceed with update again" - print_warning "EC transition procedure will start in 5 seconds" - sleep 5 - ${CMD_EC_TRANSITION} - error_check "Could not perform EC transition" - fi - # Continue with regular update process for Dasharo version - # greater or equal 1.3.0 - ;; - esac - fi - - # Use regular update process for everything else - ${CMD_DASHARO_DEPLOY} update + if [ -n "${LOGS_SENT}" ]; then + ${CMD_DASHARO_DEPLOY} install + fi + else + # TODO: This should be placed in dasharo-deploy: + # For NovaCustom TGL laptops with Dasharo version lower than 1.3.0, + # we shall run the ec_transition script instead. See: + # https://docs.dasharo.com/variants/novacustom_nv4x_tgl/releases/#v130-2022-10-18 + if [ "$SYSTEM_VENDOR" = "Notebook" ]; then + case "$SYSTEM_MODEL" in + "NS50_70MU" | "NV4XMB,ME,MZ") + compare_versions $DASHARO_VERSION 1.3.0 + if [ $? -eq 1 ]; then + # For Dasharo version lesser than 1.3.0 + print_warning "Detected NovaCustom hardware with version < 1.3.0" + print_warning "Need to perform EC transition after which the platform will turn off" + print_warning "Then, please power it on and proceed with update again" + print_warning "EC transition procedure will start in 5 seconds" + sleep 5 + ${CMD_EC_TRANSITION} + error_check "Could not perform EC transition" + fi + # Continue with regular update process for Dasharo version + # greater or equal 1.3.0 + ;; + esac fi - read -p "Press Enter to continue." - return 0 - ;; - "${REST_FIRM_OPT}") - # flashrom does not support QEMU, but restore depends on flashrom. - # TODO: this could be handled in a better way: - [ "${SYSTEM_VENDOR}" = "QEMU" ] || [ "${SYSTEM_VENDOR}" = "Emulation" ] && return 0 + # Use regular update process for everything else + ${CMD_DASHARO_DEPLOY} update + fi + read -p "Press Enter to continue." - if check_if_dasharo; then - ${CMD_DASHARO_DEPLOY} restore - fi - read -p "Press Enter to continue." + return 0 + ;; + "${REST_FIRM_OPT}") + # flashrom does not support QEMU, but restore depends on flashrom. + # TODO: this could be handled in a better way: + [ "${SYSTEM_VENDOR}" = "QEMU" ] || [ "${SYSTEM_VENDOR}" = "Emulation" ] && return 0 + + if check_if_dasharo; then + ${CMD_DASHARO_DEPLOY} restore + fi + read -p "Press Enter to continue." + return 0 + ;; + "${DPP_KEYS_OPT}") + get_dpp_creds + + # Check for Dasharo Firmware for the current platform, continue to + # packages after checking: + check_for_dasharo_firmware + + # Try to log in using available DPP credentials, start loop over if login + # was not successful: + login_to_dpp_server + if [ $? -ne 0 ]; then + print_warning "Your credentials do not have access to DPP packages. If you bought one, check the" + print_warning "credentials you have used, and contact support. If you did not buy any DPP" + print_warning "packages - feel free to continue." + read -p "Press Enter to continue" return 0 - ;; - "${DPP_KEYS_OPT}") - get_dpp_creds - - # Check for Dasharo Firmware for the current platform, continue to - # packages after checking: - check_for_dasharo_firmware - - # Try to log in using available DPP credentials, start loop over if login - # was not successful: - login_to_dpp_server - if [ $? -ne 0 ]; then - print_warning "Your credentials do not have access to DPP packages. If you bought one, check the" - print_warning "credentials you have used, and contact support. If you did not buy any DPP" - print_warning "packages - feel free to continue." - read -p "Press Enter to continue" - return 0 - fi + fi - # Check if there is some packages available to install, start loop over if - # no packages is available: - check_avail_dpp_packages || return 0 + # Check if there is some packages available to install, start loop over if + # no packages is available: + check_avail_dpp_packages || return 0 - # Download and install available packages, start loop over if there is - # no packages to install: - install_all_dpp_packages || return 0 + # Download and install available packages, start loop over if there is + # no packages to install: + install_all_dpp_packages || return 0 - # Parse installed packages for premium submenus: - parse_for_premium_submenu + # Parse installed packages for premium submenus: + parse_for_premium_submenu - read -p "Press Enter to continue." - return 0 - ;; - "${DPP_SUBMENU_OPT}") - [ -f "$DPP_SUBMENU_JSON" ] || return 0 - export DPP_SUBMENU_ACTIVE="true" - return 0 - ;; + read -p "Press Enter to continue." + return 0 + ;; + "${DPP_SUBMENU_OPT}") + [ -f "$DPP_SUBMENU_JSON" ] || return 0 + export DPP_SUBMENU_ACTIVE="true" + return 0 + ;; esac return 1 } -show_footer(){ +show_footer() { echo -e "${BLUE}*********************************************************${NORMAL}" echo -ne "${RED}${REBOOT_OPT_UP}${NORMAL} to reboot ${NORMAL}" echo -ne "${RED}${POWEROFF_OPT_UP}${NORMAL} to poweroff ${NORMAL}" echo -e "${RED}${SHELL_OPT_UP}${NORMAL} to enter shell ${NORMAL}" - if systemctl is-active sshd.service &> /dev/null; then + if systemctl is-active sshd.service &>/dev/null; then echo -ne "${RED}${SSH_OPT_UP}${NORMAL} to stop SSH server ${NORMAL}" else echo -ne "${RED}${SSH_OPT_UP}${NORMAL} to launch SSH server ${NORMAL}" @@ -1512,67 +1507,67 @@ show_footer(){ echo -ne "${YELLOW}\nEnter an option:${NORMAL}" } -footer_options(){ +footer_options() { local OPTION=$1 case ${OPTION} in - "${SSH_OPT_UP}" | "${SSH_OPT_LOW}") - wait_for_network_connection || return 0 + "${SSH_OPT_UP}" | "${SSH_OPT_LOW}") + wait_for_network_connection || return 0 - if systemctl is-active sshd.service> /dev/null 2>&1; then - print_ok "Turning off the SSH server..." - systemctl stop sshd.service - else - print_warning "Starting SSH server!" - print_warning "Now you can log in into the system using root account." - print_warning "Stopping server will not drop all connected sessions." - systemctl start sshd.service - print_ok "Listening on IPs: $(ip -br -f inet a show scope global | grep UP | awk '{ print $3 }' | tr '\n' ' ')" - fi - read -p "Press Enter to continue." + if systemctl is-active sshd.service >/dev/null 2>&1; then + print_ok "Turning off the SSH server..." + systemctl stop sshd.service + else + print_warning "Starting SSH server!" + print_warning "Now you can log in into the system using root account." + print_warning "Stopping server will not drop all connected sessions." + systemctl start sshd.service + print_ok "Listening on IPs: $(ip -br -f inet a show scope global | grep UP | awk '{ print $3 }' | tr '\n' ' ')" + fi + read -p "Press Enter to continue." - return 0 - ;; - "${SHELL_OPT_UP}" | "${SHELL_OPT_LOW}") - clear - echo "Entering shell, to leave type exit and press Enter or press LCtrl+D" - echo "" - send_dts_logs + return 0 + ;; + "${SHELL_OPT_UP}" | "${SHELL_OPT_LOW}") + clear + echo "Entering shell, to leave type exit and press Enter or press LCtrl+D" + echo "" + send_dts_logs + set_verbose "false" + ${CMD_SHELL} + + # If in submenu before going to shell - return to main menu after exiting + # shell: + unset DPP_SUBMENU_ACTIVE + ;; + "${POWEROFF_OPT_UP}" | "${POWEROFF_OPT_LOW}") + send_dts_logs + ${POWEROFF} + ;; + "${REBOOT_OPT_UP}" | "${REBOOT_OPT_LOW}") + send_dts_logs + ${REBOOT} + ;; + "${SEND_LOGS_OPT}" | "${SEND_LOGS_OPT_LOW}") + if [ "${SEND_LOGS_ACTIVE}" == "true" ]; then + unset SEND_LOGS_ACTIVE + else + SEND_LOGS_ACTIVE="true" + fi + ;; + "${VERBOSE_OPT}" | "${VERBOSE_OPT_LOW}") + if [ "${VERBOSE_ACTIVE}" == "true" ]; then set_verbose "false" - ${CMD_SHELL} - - # If in submenu before going to shell - return to main menu after exiting - # shell: - unset DPP_SUBMENU_ACTIVE - ;; - "${POWEROFF_OPT_UP}" | "${POWEROFF_OPT_LOW}") - send_dts_logs - ${POWEROFF} - ;; - "${REBOOT_OPT_UP}" | "${REBOOT_OPT_LOW}") - send_dts_logs - ${REBOOT} - ;; - "${SEND_LOGS_OPT}" | "${SEND_LOGS_OPT_LOW}") - if [ "${SEND_LOGS_ACTIVE}" == "true" ]; then - unset SEND_LOGS_ACTIVE - else - SEND_LOGS_ACTIVE="true" - fi - ;; - "${VERBOSE_OPT}" | "${VERBOSE_OPT_LOW}") - if [ "${VERBOSE_ACTIVE}" == "true" ]; then - set_verbose "false" - else - set_verbose "true" - fi - ;; + else + set_verbose "true" + fi + ;; esac return 1 } -send_dts_logs(){ +send_dts_logs() { if [ "${SEND_LOGS_ACTIVE}" == "true" ]; then echo "Sending logs..." @@ -1582,7 +1577,7 @@ send_dts_logs(){ uuid_string+="_$(dmidecode -s system-product-name)" uuid_string+="_$(dmidecode -s system-manufacturer)" - uuid=`uuidgen -n @x500 -N $uuid_string -s` + uuid=$(uuidgen -n @x500 -N $uuid_string -s) log_dir+="_${uuid}_$(date +'%Y_%m_%d_%H_%M_%S_%N')" log_dir="${log_dir// /_}" @@ -1643,7 +1638,7 @@ check_if_fused() { break fi ((_line_number++)) - done <<< "$_file_content" + done <<<"$_file_content" if [[ -z "$_hfsts6_value" ]]; then print_error "Failed to read HFSTS6 value" @@ -1687,7 +1682,7 @@ check_if_boot_guard_enabled() { _msr_binary=$(echo "ibase=16; obase=2; $_msr_hex" | bc) _binary_length=${#_msr_binary} -arkuszu + arkuszu if [ $_binary_length -lt 64 ]; then _padding=$((64 - $_binary_length)) _zeros=$(printf "%${_padding}s" | tr ' ' "0") diff --git a/include/dts-subscription.sh b/include/dts-subscription.sh index 5f8505bf..319254e2 100644 --- a/include/dts-subscription.sh +++ b/include/dts-subscription.sh @@ -19,9 +19,9 @@ check_for_dasharo_firmware() { # Ignore "SC2154 (warning): DPP_CREDENTIAL_FILE is referenced but not assigned" # for external variable: # shellcheck disable=SC2154 - CLOUDSEND_LOGS_URL=$(sed -n '1p' < ${DPP_CREDENTIAL_FILE} | tr -d '\n') - CLOUDSEND_DOWNLOAD_URL=$(sed -n '2p' < ${DPP_CREDENTIAL_FILE} | tr -d '\n') - CLOUDSEND_PASSWORD=$(sed -n '3p' < ${DPP_CREDENTIAL_FILE} | tr -d '\n') + CLOUDSEND_LOGS_URL=$(sed -n '1p' <${DPP_CREDENTIAL_FILE} | tr -d '\n') + CLOUDSEND_DOWNLOAD_URL=$(sed -n '2p' <${DPP_CREDENTIAL_FILE} | tr -d '\n') + CLOUDSEND_PASSWORD=$(sed -n '3p' <${DPP_CREDENTIAL_FILE} | tr -d '\n') USER_DETAILS="$CLOUDSEND_DOWNLOAD_URL:$CLOUDSEND_PASSWORD" # Check the board information: @@ -84,17 +84,17 @@ get_dpp_creds() { # Export DPP creds to a file for future use. Currently these are being used # for both: MinIO (and its mc CLI) and cloudsend (deprecated, all DPP # sibscribtions will be megrated to MinIO): - echo ${TMP_CLOUDSEND_LOGS_URL} > ${DPP_CREDENTIAL_FILE} - echo ${TMP_CLOUDSEND_DOWNLOAD_URL} >> ${DPP_CREDENTIAL_FILE} - echo ${TMP_CLOUDSEND_PASSWORD} >> ${DPP_CREDENTIAL_FILE} + echo ${TMP_CLOUDSEND_LOGS_URL} >${DPP_CREDENTIAL_FILE} + echo ${TMP_CLOUDSEND_DOWNLOAD_URL} >>${DPP_CREDENTIAL_FILE} + echo ${TMP_CLOUDSEND_PASSWORD} >>${DPP_CREDENTIAL_FILE} print_ok "Dasharo DPP credentials have been saved" } -login_to_dpp_server(){ +login_to_dpp_server() { # Check if the user is already logged in, log in if not: if [ -z "$(mc alias list | grep ${CLOUDSEND_DOWNLOAD_URL})" ]; then - if ! mc alias set $DPP_SERVER_USER_ALIAS $DPP_SERVER_ADDRESS $CLOUDSEND_DOWNLOAD_URL $CLOUDSEND_PASSWORD >> $ERR_LOG_FILE 2>&1 ; then + if ! mc alias set $DPP_SERVER_USER_ALIAS $DPP_SERVER_ADDRESS $CLOUDSEND_DOWNLOAD_URL $CLOUDSEND_PASSWORD >>$ERR_LOG_FILE 2>&1; then return 1 fi fi @@ -102,7 +102,7 @@ login_to_dpp_server(){ return 0 } -subscription_routine(){ +subscription_routine() { # This function contains Subscription-related code which needs to be executed # several times. Currently it is called only in /usr/sbin/dts script at every # start of menu rendering loop. @@ -117,9 +117,9 @@ subscription_routine(){ # Each time the main menu is rendered, check for DPP credentials and export # them, if file exists if [ -e "${DPP_CREDENTIAL_FILE}" ]; then - CLOUDSEND_LOGS_URL=$(sed -n '1p' < ${DPP_CREDENTIAL_FILE} | tr -d '\n') - CLOUDSEND_DOWNLOAD_URL=$(sed -n '2p' < ${DPP_CREDENTIAL_FILE} | tr -d '\n') - CLOUDSEND_PASSWORD=$(sed -n '3p' < ${DPP_CREDENTIAL_FILE} | tr -d '\n') + CLOUDSEND_LOGS_URL=$(sed -n '1p' <${DPP_CREDENTIAL_FILE} | tr -d '\n') + CLOUDSEND_DOWNLOAD_URL=$(sed -n '2p' <${DPP_CREDENTIAL_FILE} | tr -d '\n') + CLOUDSEND_PASSWORD=$(sed -n '3p' <${DPP_CREDENTIAL_FILE} | tr -d '\n') export USER_DETAILS="$CLOUDSEND_DOWNLOAD_URL:$CLOUDSEND_PASSWORD" export DPP_IS_LOGGED="true" else @@ -136,17 +136,17 @@ subscription_routine(){ return 0 } -check_dasharo_package_env(){ +check_dasharo_package_env() { [ -d $DPP_PACKAGE_MANAGER_DIR ] || mkdir -p $DPP_PACKAGE_MANAGER_DIR [ -d $DPP_PACKAGES_SCRIPTS_PATH ] || mkdir -p $DPP_PACKAGES_SCRIPTS_PATH return 0 } -update_package_list(){ +update_package_list() { check_dasharo_package_env - mc find --json --name "*.rpm" $DPP_SERVER_USER_ALIAS > $DPP_AVAIL_PACKAGES_LIST + mc find --json --name "*.rpm" $DPP_SERVER_USER_ALIAS >$DPP_AVAIL_PACKAGES_LIST if [ $? -ne 0 ]; then print_error "Unable to get package list!" @@ -155,7 +155,7 @@ update_package_list(){ return 0 } -download_dpp_package(){ +download_dpp_package() { local package_name=$1 # Make sure all paths exist: @@ -183,7 +183,7 @@ download_dpp_package(){ return 0 } -install_dpp_package(){ +install_dpp_package() { local package_name=$1 check_dasharo_package_env @@ -210,7 +210,7 @@ install_dpp_package(){ return 0 } -install_all_dpp_packages(){ +install_all_dpp_packages() { echo "Installing available DPP packages..." update_package_list || return 1 @@ -235,7 +235,7 @@ install_all_dpp_packages(){ return 0 } -check_avail_dpp_packages(){ +check_avail_dpp_packages() { echo "Checking for available DPP packages..." AVAILABLE_PACKAGES=$(mc find --name "*.rpm" $DPP_SERVER_USER_ALIAS) @@ -268,26 +268,26 @@ parse_for_premium_submenu() { # Create the JSON file only if any script have been found, this will be a # signal to render premium submenu: - [ -f "$DPP_SUBMENU_JSON" ] || echo '[]' > "$DPP_SUBMENU_JSON" + [ -f "$DPP_SUBMENU_JSON" ] || echo '[]' >"$DPP_SUBMENU_JSON" local script_name script_name=$(basename "$script") # Add a new entry to the JSON file json_data=$(jq --arg name "$script_name" --argjson pos "$position" \ - '. += [{"file_name": $name, "file_menu_position": $pos}]' <<< "$json_data") + '. += [{"file_name": $name, "file_menu_position": $pos}]' <<<"$json_data") # Increment highest position for next script position=$((position + 1)) done # Save updated JSON data - [ -f "$DPP_SUBMENU_JSON" ] && echo "$json_data" | jq '.' > "$DPP_SUBMENU_JSON" + [ -f "$DPP_SUBMENU_JSON" ] && echo "$json_data" | jq '.' >"$DPP_SUBMENU_JSON" return 0 } -show_dpp_submenu(){ +show_dpp_submenu() { # This menu is being rendered dynamically by parsing scripts from # DPP_PACKAGES_SCRIPTS_PATH. These scripts are being installed by DPP # packages. @@ -308,21 +308,21 @@ show_dpp_submenu(){ # Iterate over each JSON object: while IFS= read -r item; do local script_name - script_name=$(jq -r '.file_name' <<< "$item") - file_menu_position=$(jq -r '.file_menu_position' <<< "$item") + script_name=$(jq -r '.file_name' <<<"$item") + file_menu_position=$(jq -r '.file_menu_position' <<<"$item") local script_path="$DPP_PACKAGES_SCRIPTS_PATH/$script_name" bash "$script_path" menu_point "$file_menu_position" - done <<< "$json_data" + done <<<"$json_data" echo -e "${BLUE}**${YELLOW} ${BACK_TO_MAIN_MENU_UP})${BLUE} Return to main menu${NORMAL}" return 0 } -dpp_submenu_options(){ +dpp_submenu_options() { local OPTION=$1 local file_menu_position local script @@ -344,7 +344,7 @@ dpp_submenu_options(){ [ -z "$script" ] && return 1 local script_name - script_name=$(jq -r '.file_name' <<< "$script") + script_name=$(jq -r '.file_name' <<<"$script") local script_path="$DPP_PACKAGES_SCRIPTS_PATH/$script_name" diff --git a/include/hal/common-mock-func.sh b/include/hal/common-mock-func.sh index 75158d79..39c0eaa8 100644 --- a/include/hal/common-mock-func.sh +++ b/include/hal/common-mock-func.sh @@ -3,26 +3,26 @@ ################################################################################ # Helper functions used in this script: ################################################################################ -parse_for_arg_return_next(){ -# This function parses a list of arguments (given as a second argument), looks -# for a specified argument (given as a first argument). In case the specified -# argument has been found in the list - this function returns (to stdout) the -# argument, which is on the list after specified one, and a return value 0, -# otherwise nothing is being printed to stdout and the return value is 1. -# Arguments: -# 1. The argument you are searching for like -r for flashrom; -# 2. Space-separated list of arguments to search in. +parse_for_arg_return_next() { + # This function parses a list of arguments (given as a second argument), looks + # for a specified argument (given as a first argument). In case the specified + # argument has been found in the list - this function returns (to stdout) the + # argument, which is on the list after specified one, and a return value 0, + # otherwise nothing is being printed to stdout and the return value is 1. + # Arguments: + # 1. The argument you are searching for like -r for flashrom; + # 2. Space-separated list of arguments to search in. local _arg="$1" shift while [[ $# -gt 0 ]]; do case $1 in - "$_arg") - [ -n "$2" ] && echo "$2" + "$_arg") + [ -n "$2" ] && echo "$2" - return 0 + return 0 ;; - *) + *) shift ;; esac @@ -37,9 +37,9 @@ parse_for_arg_return_next(){ ################################################################################ # Common mocking function ################################################################################ -common_mock(){ -# This mocking function is being called for all cases where mocking is needed, -# but the result of mocking function execution is not important. +common_mock() { + # This mocking function is being called for all cases where mocking is needed, + # but the result of mocking function execution is not important. local _tool="$1" echo "${FUNCNAME[0]}: using ${_tool}..." @@ -60,10 +60,10 @@ TEST_BOARD_HAS_GBE_REGION="${TEST_BOARD_HAS_GBE_REGION:-true}" TEST_BOARD_GBE_REGION_RW="${TEST_BOARD_GBE_REGION_RW:-true}" TEST_BOARD_GBE_REGION_LOCKED="${TEST_BOARD_GBE_REGION_LOCKED:-}" TEST_COMPATIBLE_EC_VERSINO="${TEST_COMPATIBLE_EC_VERSINO:-}" -TEST_FLASH_CHIP_SIZE="${TEST_FLASH_CHIP_SIZE:-$((2*1024*1024))}" +TEST_FLASH_CHIP_SIZE="${TEST_FLASH_CHIP_SIZE:-$((2 * 1024 * 1024))}" -flashrom_check_flash_lock_mock(){ -# For flash lock testing, for more inf. check check_flash_lock func.: +flashrom_check_flash_lock_mock() { + # For flash lock testing, for more inf. check check_flash_lock func.: if [ "$TEST_FLASH_LOCK" = "true" ]; then echo "PR0: Warning:.TEST is read-only" 1>&2 echo "SMM protection is enabled" 1>&2 @@ -74,25 +74,25 @@ flashrom_check_flash_lock_mock(){ return 0 } -flashrom_flash_chip_name_mock(){ -# For flash chip name check emulation, for more inf. check check_flash_chip -# func.: - echo "Test Flash Chip" +flashrom_flash_chip_name_mock() { + # For flash chip name check emulation, for more inf. check check_flash_chip + # func.: + echo "Test Flash Chip" - return 0 + return 0 } -flashrom_flash_chip_size_mock(){ -# For flash chip size check emulation, for more inf. check check_flash_chip -# func.. +flashrom_flash_chip_size_mock() { + # For flash chip size check emulation, for more inf. check check_flash_chip + # func.. echo "$TEST_FLASH_CHIP_SIZE" return 0 } -flashrom_check_intel_regions_mock(){ -# For flash regions check emulation, for more inf. check check_intel_regions -# func.: +flashrom_check_intel_regions_mock() { + # For flash regions check emulation, for more inf. check check_intel_regions + # func.: if [ "$TEST_BOARD_HAS_FD_REGION" = "true" ]; then echo -n "Flash Descriptor region (0x00000000-0x00000fff)" @@ -132,36 +132,36 @@ flashrom_check_intel_regions_mock(){ return 0 } -flashrom_read_flash_layout_mock(){ -# For checking flash layout for further flashrom arguments selection, for more -# inf. check set_flashrom_update_params function. -# -# TODO: this one can be deleted in future and replaced with read_firm_mock, -# which will create a binary with needed bytes appropriately set. +flashrom_read_flash_layout_mock() { + # For checking flash layout for further flashrom arguments selection, for more + # inf. check set_flashrom_update_params function. + # + # TODO: this one can be deleted in future and replaced with read_firm_mock, + # which will create a binary with needed bytes appropriately set. # For -r check flashrom man page: local _file_to_write_into _file_to_write_into=$(parse_for_arg_return_next "-r" "$@") - [ -f "$_file_to_write_into" ] || echo "Testing..." > "$_file_to_write_into" + [ -f "$_file_to_write_into" ] || echo "Testing..." >"$_file_to_write_into" return 0 } -flashrom_read_firm_mock(){ -# Emulating dumping of the firmware the platform currently uses. Currently it is -# writing into text file, that should be changed to binary instead (TODO). +flashrom_read_firm_mock() { + # Emulating dumping of the firmware the platform currently uses. Currently it is + # writing into text file, that should be changed to binary instead (TODO). # For -r check flashrom man page: local _file_to_write_into _file_to_write_into=$(parse_for_arg_return_next "-r" "$@") - [ -f "$_file_to_write_into" ] || echo "Test flashrom read." > "$_file_to_write_into" + [ -f "$_file_to_write_into" ] || echo "Test flashrom read." >"$_file_to_write_into" return 0 } -flashrom_get_ec_firm_version_mock(){ -# Emulating wrong EC firmware version, check deploy_ec_firmware func. and -# ec_transition script for more inf.: +flashrom_get_ec_firm_version_mock() { + # Emulating wrong EC firmware version, check deploy_ec_firmware func. and + # ec_transition script for more inf.: if [ -n "$TEST_COMPATIBLE_EC_VERSION" ]; then echo "Mainboard EC Version: $COMPATIBLE_EC_FW_VERSION" else @@ -177,9 +177,9 @@ flashrom_get_ec_firm_version_mock(){ TEST_USING_OPENSOURCE_EC_FIRM="${TEST_USING_OPENSOURCE_EC_FIRM:-}" TEST_NOVACUSTOM_MODEL="${TEST_NOVACUSTOM_MODEL:-}" -dasharo_ectool_check_for_opensource_firm_mock(){ -# Emulating opensource EC firmware presence, check check_for_opensource_firmware -# for more inf.: +dasharo_ectool_check_for_opensource_firm_mock() { + # Emulating opensource EC firmware presence, check check_for_opensource_firmware + # for more inf.: if [ "$TEST_USING_OPENSOURCE_EC_FIRM" = "true" ]; then return 0 fi @@ -187,7 +187,7 @@ dasharo_ectool_check_for_opensource_firm_mock(){ return 1 } -novacustom_check_sys_model_mock(){ +novacustom_check_sys_model_mock() { if [ -n "$TEST_NOVACUSTOM_MODEL" ]; then echo "Dasharo EC Tool Mock - Info Command" echo "-----------------------------------" @@ -212,69 +212,69 @@ TEST_BIOS_VENDOR="${TEST_BIOS_VENDOR:-}" TEST_SYSTEM_UUID="${TEST_SYSTEM_UUID:-}" TEST_BASEBOARD_SERIAL_NUMBER="${TEST_BASEBOARD_SERIAL_NUMBER:-}" -dmidecode_common_mock(){ -# Emulating dumping dmidecode inf.: +dmidecode_common_mock() { + # Emulating dumping dmidecode inf.: echo "${FUNCNAME[0]}: using dmidecode..." return 0 } -dmidecode_dump_var_mock(){ -# Emulating dumping specific dmidecode fields, this is the place where the value -# of the fields are being replaced by those defined by testsuite: +dmidecode_dump_var_mock() { + # Emulating dumping specific dmidecode fields, this is the place where the value + # of the fields are being replaced by those defined by testsuite: local _option_to_read _option_to_read=$(parse_for_arg_return_next "-s" "$@") case "$_option_to_read" in - system-manufacturer) + system-manufacturer) [ -z "$TEST_SYSTEM_VENDOR" ] && return 1 echo "$TEST_SYSTEM_VENDOR" ;; - system-product-name) + system-product-name) [ -z "$TEST_SYSTEM_MODEL" ] && return 1 echo "$TEST_SYSTEM_MODEL" ;; - baseboard-version) + baseboard-version) [ -z "$TEST_BOARD_MODEL" ] && return 1 echo "$TEST_BOARD_MODEL" ;; - baseboard-product-name) + baseboard-product-name) [ -z "$TEST_BOARD_MODEL" ] && return 1 echo "$TEST_BOARD_MODEL" ;; - processor-version) + processor-version) [ -z "$TEST_CPU_VERSION" ] && return 1 echo "$TEST_CPU_VERSION" ;; - bios-vendor) + bios-vendor) [ -z "$TEST_BIOS_VENDOR" ] && return 1 echo "$TEST_BIOS_VENDOR" ;; - bios-version) + bios-version) [ -z "$TEST_BIOS_VERSION" ] && return 1 echo "$TEST_BIOS_VERSION" ;; - system-uuid) + system-uuid) [ -z "$TEST_SYSTEM_UUID" ] && return 1 echo "$TEST_SYSTEM_UUID" ;; - baseboard-serial-number) + baseboard-serial-number) [ -z "$TEST_BASEBOARD_SERIAL_NUMBER" ] && return 1 @@ -290,9 +290,9 @@ dmidecode_dump_var_mock(){ ################################################################################ TEST_ME_OFFSET="${TEST_ME_OFFSET:-}" -ifdtool_check_blobs_in_binary_mock(){ -# Emulating ME offset value check, check check_blobs_in_binary func. for more -# inf.: +ifdtool_check_blobs_in_binary_mock() { + # Emulating ME offset value check, check check_blobs_in_binary func. for more + # inf.: echo "Flash Region 2 (Intel ME): $TEST_ME_OFFSET" return 0 @@ -303,9 +303,9 @@ ifdtool_check_blobs_in_binary_mock(){ ################################################################################ TEST_ME_DISABLED="${TEST_ME_DISABLED:-true}" -cbmem_check_if_me_disabled_mock(){ -# Emulating ME state checked in Coreboot table, check check_if_me_disabled func. -# for more inf.: +cbmem_check_if_me_disabled_mock() { + # Emulating ME state checked in Coreboot table, check check_if_me_disabled func. + # for more inf.: if [ "$TEST_ME_DISABLED" = "true" ]; then echo "ME is disabled" echo "ME is HAP disabled" @@ -323,8 +323,8 @@ TEST_VBOOT_ENABLED="${TEST_VBOOT_ENABLED:-}" TEST_ROMHOLE_MIGRATION="${TEST_ROMHOLE_MIGRATION:-}" TEST_DIFFERENT_FMAP="${TEST_DIFFERENT_FMAP:-}" -cbfstool_layout_mock(){ -# Emulating some fields in Coreboot Files System layout table: +cbfstool_layout_mock() { + # Emulating some fields in Coreboot Files System layout table: local _file_to_check="$1" echo "This image contains the following sections that can be accessed with this tool:" @@ -338,29 +338,29 @@ cbfstool_layout_mock(){ return 0 } -cbfstool_read_romhole_mock(){ -# Emulating reading ROMHOLE section from dumped firmware, check -# romhole_migration func for more inf.: - local _file_to_write_into - _file_to_write_into=$(parse_for_arg_return_next "-f" "$@") +cbfstool_read_romhole_mock() { + # Emulating reading ROMHOLE section from dumped firmware, check + # romhole_migration func for more inf.: + local _file_to_write_into + _file_to_write_into=$(parse_for_arg_return_next "-f" "$@") - [ -f "$_file_to_write_into" ] || echo "Testing..." > "$_file_to_write_into" + [ -f "$_file_to_write_into" ] || echo "Testing..." >"$_file_to_write_into" - return 0 + return 0 } -cbfstool_read_bios_conffile_mock(){ -# Emulating reading bios configuration and some fields inside it. +cbfstool_read_bios_conffile_mock() { + # Emulating reading bios configuration and some fields inside it. local _file_to_write_into _file_to_write_into=$(parse_for_arg_return_next "-f" "$@") if [ "$TEST_VBOOT_ENABLED" = "true" ]; then - # Emulating VBOOT presence, check firmware_pre_installation_routine and - # firmware_pre_updating_routine funcs for more inf.: - echo "CONFIG_VBOOT=y" > "$_file_to_write_into" + # Emulating VBOOT presence, check firmware_pre_installation_routine and + # firmware_pre_updating_routine funcs for more inf.: + echo "CONFIG_VBOOT=y" >"$_file_to_write_into" fi - echo "" >> "$_file_to_write_into" + echo "" >>"$_file_to_write_into" return 0 } @@ -370,9 +370,9 @@ cbfstool_read_bios_conffile_mock(){ ################################################################################ TEST_TOUCHPAD_ENABLED=${TEST_TOUCHPAD_ENABLED:-} -dmesg_i2c_hid_detect_mock(){ -# Emulating touchpad presence and name detection, check touchpad-info script for -# more inf.: +dmesg_i2c_hid_detect_mock() { + # Emulating touchpad presence and name detection, check touchpad-info script for + # more inf.: if [ "$TEST_TOUCHPAD_ENABLED" = "true" ]; then echo "hid-multitouch: I2C HID Test" fi @@ -385,9 +385,9 @@ dmesg_i2c_hid_detect_mock(){ ################################################################################ TEST_DIFFERENT_VBOOT_KEYS=${TEST_DIFFERENT_VBOOT_KEYS:-} -futility_dump_vboot_keys(){ -# Emulating VBOOT keys difference to trigger GBB region migration, check -# check_vboot_keys func. for more inf.: +futility_dump_vboot_keys() { + # Emulating VBOOT keys difference to trigger GBB region migration, check + # check_vboot_keys func. for more inf.: _local _file_to_check _file_to_check=$(parse_for_arg_return_next show "$@") if [ "$TEST_DIFFERENT_VBOOT_KEYS" = "true" ]; then @@ -407,10 +407,10 @@ TEST_AC_PRESENT="${TEST_AC_PRESENT:-}" TEST_MEI_CONF_PRESENT="${TEST_MEI_CONF_PRESENT:-true}" TEST_INTEL_FUSE_STATUS="${TEST_INTEL_FUSE_STATUS:-0}" -fsread_tool_common_mock(){ -# This functionn emulates read hardware specific file system resources or its -# metadata. It redirects flow into a tool-specific mocking function, which then -# does needed work. e.g. fsread_tool_test_mock for test tool. +fsread_tool_common_mock() { + # This functionn emulates read hardware specific file system resources or its + # metadata. It redirects flow into a tool-specific mocking function, which then + # does needed work. e.g. fsread_tool_test_mock for test tool. local _tool="$1" shift @@ -419,7 +419,7 @@ fsread_tool_common_mock(){ return $? } -fsread_tool_test_mock(){ +fsread_tool_test_mock() { local _arg_d local _arg_f local _arg_e @@ -428,50 +428,50 @@ fsread_tool_test_mock(){ _arg_e="$(parse_for_arg_return_next -e "$@")" if [ "$_arg_d" = "/sys/class/pci_bus/0000:00/device/0000:00:16.0" ]; then - # Here we emulate the HCI hardware presence checked by function - # check_if_heci_present in dts-hal.sh. Currently it is assumed the HCI is - # assigned to a specific sysfs path (check the condition above): + # Here we emulate the HCI hardware presence checked by function + # check_if_heci_present in dts-hal.sh. Currently it is assumed the HCI is + # assigned to a specific sysfs path (check the condition above): [ "$TEST_HCI_PRESENT" = "true" ] && return 0 fi if [ "$_arg_f" = "/sys/class/mei/mei0/fw_status" ]; then - # Here we emulate MEI controller status file presence, check check_if_fused - # func for more inf.: + # Here we emulate MEI controller status file presence, check check_if_fused + # func for more inf.: [ "$TEST_MEI_CONF_PRESENT" = "true" ] && return 0 fi if [ "$_arg_e" = "/sys/class/power_supply/AC/online" ]; then - # Emulating AC status file presence, check check_if_ac func. for more inf.: + # Emulating AC status file presence, check check_if_ac func. for more inf.: [ "$TEST_AC_PRESENT" = "true" ] && return 0 fi return 1 } -fsread_tool_cat_mock(){ +fsread_tool_cat_mock() { local _file_to_cat _file_to_cat="$1" # Note, Test folder here comes from dmesg_i2c_hid_detect_mock, which is being # called before fsread_tool_cat_mock in touchpad-info script: if [ "$_file_to_cat" = "/sys/bus/i2c/devices/Test/firmware_node/hid" ] && [ -n "$TEST_TOUCHPAD_HID" ]; then - # Used in touchpad-info script. + # Used in touchpad-info script. echo "$TEST_TOUCHPAD_HID" # Note, Test folder here comes from dmesg_i2c_hid_detect_mock, which is being # called before fsread_tool_cat_mock in touchpad-info script: elif [ "$_file_to_cat" = "/sys/bus/i2c/devices/Test/firmware_node/path" ] && [ -n "$TEST_TOUCHPAD_PATH" ]; then - # Used in touchpad-info script. + # Used in touchpad-info script. echo "$TEST_TOUCHPAD_PATH" elif [ "$_file_to_cat" = "/sys/class/power_supply/AC/online" ]; then - # Emulating AC adadpter presence, used in check_if_ac func.: + # Emulating AC adadpter presence, used in check_if_ac func.: if [ "$TEST_AC_PRESENT" = "true" ]; then echo "1" else echo "0" fi elif [ "$_file_to_cat" = "/sys/class/mei/mei0/fw_status" ] && [ "$TEST_MEI_CONF_PRESENT" = "true" ]; then - # Emulating MEI firmware status file, for more inf., check check_if_fused - # func.: + # Emulating MEI firmware status file, for more inf., check check_if_fused + # func.: echo "smth" echo "smth" echo "smth" @@ -495,9 +495,9 @@ fsread_tool_cat_mock(){ ################################################################################ TEST_ME_OP_MODE="${TEST_ME_OP_MODE:-0}" -setpci_check_me_op_mode_mock(){ -# Emulating current ME operation mode, check functions check_if_me_disabled and -# check_me_op_mode: +setpci_check_me_op_mode_mock() { + # Emulating current ME operation mode, check functions check_if_me_disabled and + # check_me_op_mode: echo "0$TEST_ME_OP_MODE" return 0 @@ -508,9 +508,9 @@ setpci_check_me_op_mode_mock(){ ################################################################################ TEST_CPU_MODEL="${TEST_CPU_MODEL:-test}" -lscpu_common_mock(){ -# Emulating CPU model, check update_workflow function. The model should look -# like i5-13409: +lscpu_common_mock() { + # Emulating CPU model, check update_workflow function. The model should look + # like i5-13409: echo "12th Gen Intel(R) Core(TM) $TEST_CPU_MODEL" return 0 @@ -522,7 +522,7 @@ TEST_MSR_CAN_BE_READ="${TEST_MSR_CAN_BE_READ:-true}" TEST_FPF_PROGRAMMED="${TEST_FPF_PROGRAMMED:-0}" TEST_VERIFIED_BOOT_ENABLED="${TEST_VERIFIED_BOOT_ENABLED:-0}" -rdmsr_boot_guard_status_mock(){ +rdmsr_boot_guard_status_mock() { local _bits_8_5="0" # Emulating MSR accessibility, for more inf. check # check_if_boot_guard_enabled func.: diff --git a/include/hal/dts-hal.sh b/include/hal/dts-hal.sh index 69e3e45f..cafbfe63 100644 --- a/include/hal/dts-hal.sh +++ b/include/hal/dts-hal.sh @@ -60,42 +60,42 @@ RDMSR="tool_wrapper rdmsr" ################################################################################ # Tools wrapper. ################################################################################ -tool_wrapper(){ -# Usage: tool_wrapper TOOL_NAME MOCK_FUNC_NAME TOOL_ARGS -# -# TOOL_NAME: the name of the tool being wrapped -# MOCK_FUNC_NAME: the name of mocking function (optional, check comments -# below for more inf.) -# TOOL_ARGS: the arguments that the tool gets if being called, for example -# for dmidecode -s system-vendor it will be "-s system-vendor". -# -# This function is a bridge between common DTS logic and hardware-specific DTS -# logic or functions. There is two paths a call to this function can be -# redirected to: real HAL for running on real platform and Tests HAL for testing -# on QEMU (depends on whether the var. DTS_TESTING is set or not). -# -# The real HAL are the real tools e.g. cbfstool, etc.. The testing HAL are the -# mocking functions. There are several types of mocking functions, with every -# type having a specific name syntax: -# -# FUNCTIONNAME_mock(){...}: mocking functions specific for every platform, those -# are stored in $DTS_MOCK_PLATFORM file which is sourced at the beginning of -# this file. -# TOOLNAME_FUNCTIONNAME_mock(){...}: mocking functions common for all platforms -# but specific for some tool, those are stored in $DTS_MOCK_COMMON file, which -# is being sourced at the beginning of this file. -# TOOLNAME_common_mock(){...}: standard mocking functions for every tool that -# are common for all platforms, those are stored in $DTS_MOCK_COMMON file, which -# is being sourced at the beginning of this file. -# common_mock(){...}: common mocking function, in case we need to use mocking -# function for a tool but we do not care about its output. -# -# This tool wrapper should only be used with tools which communicate with -# hardware or firmware (read or write, etc.). -# -# TODO: this wrapper deals with arguments as well as with stdout, stderr, and $? -# redirection, but it does not read and redirect stdin (this is not used in any -# mocking functions or tools right now). +tool_wrapper() { + # Usage: tool_wrapper TOOL_NAME MOCK_FUNC_NAME TOOL_ARGS + # + # TOOL_NAME: the name of the tool being wrapped + # MOCK_FUNC_NAME: the name of mocking function (optional, check comments + # below for more inf.) + # TOOL_ARGS: the arguments that the tool gets if being called, for example + # for dmidecode -s system-vendor it will be "-s system-vendor". + # + # This function is a bridge between common DTS logic and hardware-specific DTS + # logic or functions. There is two paths a call to this function can be + # redirected to: real HAL for running on real platform and Tests HAL for testing + # on QEMU (depends on whether the var. DTS_TESTING is set or not). + # + # The real HAL are the real tools e.g. cbfstool, etc.. The testing HAL are the + # mocking functions. There are several types of mocking functions, with every + # type having a specific name syntax: + # + # FUNCTIONNAME_mock(){...}: mocking functions specific for every platform, those + # are stored in $DTS_MOCK_PLATFORM file which is sourced at the beginning of + # this file. + # TOOLNAME_FUNCTIONNAME_mock(){...}: mocking functions common for all platforms + # but specific for some tool, those are stored in $DTS_MOCK_COMMON file, which + # is being sourced at the beginning of this file. + # TOOLNAME_common_mock(){...}: standard mocking functions for every tool that + # are common for all platforms, those are stored in $DTS_MOCK_COMMON file, which + # is being sourced at the beginning of this file. + # common_mock(){...}: common mocking function, in case we need to use mocking + # function for a tool but we do not care about its output. + # + # This tool wrapper should only be used with tools which communicate with + # hardware or firmware (read or write, etc.). + # + # TODO: this wrapper deals with arguments as well as with stdout, stderr, and $? + # redirection, but it does not read and redirect stdin (this is not used in any + # mocking functions or tools right now). # Gets toolname, e.g. poweroff, dmidecode. etc.: local _tool="$1" # Gets mocking function name: @@ -103,7 +103,7 @@ tool_wrapper(){ # It checks if _mock_func contains smth with _mock at the end, if not - # mocking function is not provided and some common mocking func. will be used # instead: - if ! echo "$_mock_func" | grep "_mock" &> /dev/null; then + if ! echo "$_mock_func" | grep "_mock" &>/dev/null; then unset _mock_func shift 1 else @@ -111,7 +111,7 @@ tool_wrapper(){ fi # Other arguments for this function are the arguments which are sent to a tool # e.g. -s system-vendor for dmidecode, etc.: - local _arguments=( "$@" ) + local _arguments=("$@") if [ -n "$DTS_TESTING" ]; then # This is the order of calling mocking functions: @@ -119,11 +119,11 @@ tool_wrapper(){ # 2) TOOLNAME_FUNCTIONNAME_mock; # 3) TOOLNAME_common_mock; # 4) common_mock - last resort. - if [ -n "$_mock_func" ] && type $_mock_func &> /dev/null; then + if [ -n "$_mock_func" ] && type $_mock_func &>/dev/null; then $_mock_func "${_arguments[@]}" - elif type ${_tool}_${_mock_func} &> /dev/null; then + elif type ${_tool}_${_mock_func} &>/dev/null; then ${_tool}_${_mock_func} "${_arguments[@]}" - elif type ${_tool}_common_mock &> /dev/null; then + elif type ${_tool}_common_mock &>/dev/null; then ${_tool}_common_mock "${_arguments[@]}" else common_mock $_tool @@ -141,24 +141,23 @@ tool_wrapper(){ ################################################################################ # Other funcs. ################################################################################ -check_for_opensource_firmware() -{ +check_for_opensource_firmware() { echo "Checking for Open Source Embedded Controller firmware..." - $DASHARO_ECTOOL check_for_opensource_firm_mock info > /dev/null 2>&1 + $DASHARO_ECTOOL check_for_opensource_firm_mock info >/dev/null 2>&1 return $? } -fsread_tool(){ -# This func is an abstraction for proper handling of fs hardware-specific (e.g. -# checking devtmpfs, or sysfs, or some other fs that changes its state due to -# changes in hardware and/or firmware) reads by tool_wrapper. -# -# This function does not have arguments in common understanding, it takes a -# command, that is reading smth from some fs, and its arguments as an only -# argument. E.g. if you want to check tty1 device presence: -# -# fsread_tool test -f /dev/tty1 +fsread_tool() { + # This func is an abstraction for proper handling of fs hardware-specific (e.g. + # checking devtmpfs, or sysfs, or some other fs that changes its state due to + # changes in hardware and/or firmware) reads by tool_wrapper. + # + # This function does not have arguments in common understanding, it takes a + # command, that is reading smth from some fs, and its arguments as an only + # argument. E.g. if you want to check tty1 device presence: + # + # fsread_tool test -f /dev/tty1 local _command="$1" shift @@ -167,30 +166,30 @@ fsread_tool(){ return $? } -cap_upd_tool(){ -# This func is an abstraction for proper handling of UEFI Capsule Update driver -# writing by the tool_wrapper. arguments: capsule update file path, e.g.: -# -# capsule_update_tool /tmp/firm.cap +cap_upd_tool() { + # This func is an abstraction for proper handling of UEFI Capsule Update driver + # writing by the tool_wrapper. arguments: capsule update file path, e.g.: + # + # capsule_update_tool /tmp/firm.cap local _capsule="$1" - cat "$_capsule" > "$CAP_UPD_DEVICE" + cat "$_capsule" >"$CAP_UPD_DEVICE" return $? } -check_if_heci_present(){ -# FIXME: what if HECI is not device 16.0? +check_if_heci_present() { + # FIXME: what if HECI is not device 16.0? $FSREAD_TOOL test_mock test -d /sys/class/pci_bus/0000:00/device/0000:00:16.0 return $? } -check_me_op_mode(){ -# Checks ME Current Operation Mode at offset 0x40 bits 19:16: +check_me_op_mode() { + # Checks ME Current Operation Mode at offset 0x40 bits 19:16: local _mode - _mode="$($SETPCI check_me_op_mode_mock -s 00:16.0 42.B 2> /dev/null | cut -c2-)" + _mode="$($SETPCI check_me_op_mode_mock -s 00:16.0 42.B 2>/dev/null | cut -c2-)" echo "$_mode" diff --git a/tests/compare_version.sh b/tests/compare_version.sh index 71bc1df4..c10ed834 100644 --- a/tests/compare_version.sh +++ b/tests/compare_version.sh @@ -4,51 +4,51 @@ DTS_ENV=/dev/null source "$DTS_FUNCS" test_compare() { - local -n array=$1 - local expected_value=$2 + local -n array=$1 + local expected_value=$2 - for pair_str in "${array[@]}"; do - read -ra pair <<< "$pair_str" - compare_versions "${pair[0]}" "${pair[1]}" - compare=$? - if [ $compare -ne "$expected_value" ]; then - echo "ERROR: compare_versions ${pair[0]} ${pair[1]} returned $compare instead of $expected_value" - fi - done + for pair_str in "${array[@]}"; do + read -ra pair <<<"$pair_str" + compare_versions "${pair[0]}" "${pair[1]}" + compare=$? + if [ $compare -ne "$expected_value" ]; then + echo "ERROR: compare_versions ${pair[0]} ${pair[1]} returned $compare instead of $expected_value" + fi + done } # array of versions in format "ver1 ver2", where ver1 is less to ver2 # shellcheck disable=SC2034 less=( - "2.0.0 3.0.0" - "2.0.0 2.0.1" - "2.0.2 2.1.0" - "2.0.0-rc 2.0.0" - "2.0.0-rc1 2.0.0" - "2.0.0-rc1 2.0.1" - "2.0.0-rc1 2.0.0-rc2" - "2.0.0-rc2 2.0.0-rc12" - "2.0.0-rc2 2.0.1-rc1" - "2.0.0-rc.1 2.0.0-rc2" - "2.0.0-rc1 2.0.0-rc.2" - "2.0.0-rc.1 2.0.0-rc.2" - "2.0.0-rc.2 2.0.0-rc12" - "2.0.0-rc2 2.0.0-rc.12" - ) + "2.0.0 3.0.0" + "2.0.0 2.0.1" + "2.0.2 2.1.0" + "2.0.0-rc 2.0.0" + "2.0.0-rc1 2.0.0" + "2.0.0-rc1 2.0.1" + "2.0.0-rc1 2.0.0-rc2" + "2.0.0-rc2 2.0.0-rc12" + "2.0.0-rc2 2.0.1-rc1" + "2.0.0-rc.1 2.0.0-rc2" + "2.0.0-rc1 2.0.0-rc.2" + "2.0.0-rc.1 2.0.0-rc.2" + "2.0.0-rc.2 2.0.0-rc12" + "2.0.0-rc2 2.0.0-rc.12" +) # shellcheck disable=SC2034 greater_or_equal=( - "2.0.0 2.0.0" - "2.0.0-rc1 2.0.0-rc1" - "2.0.0-rc.1 2.0.0-rc1" - "2.0.0-rc1 2.0.0-rc.1" - "3.0.0 2.0.0" - "2.0.1 2.0.0" - "2.0.1-rc1 2.0.0-rc2" - "2.0.0-rc12 2.0.0-rc2" - "2.0.0-rc.12 2.0.0-rc2" - "2.0.0-rc12 2.0.0-rc.2" - ) + "2.0.0 2.0.0" + "2.0.0-rc1 2.0.0-rc1" + "2.0.0-rc.1 2.0.0-rc1" + "2.0.0-rc1 2.0.0-rc.1" + "3.0.0 2.0.0" + "2.0.1 2.0.0" + "2.0.1-rc1 2.0.0-rc2" + "2.0.0-rc12 2.0.0-rc2" + "2.0.0-rc.12 2.0.0-rc2" + "2.0.0-rc12 2.0.0-rc.2" +) echo "Starting test..." test_compare less 1