Skip to content

Commit

Permalink
integrate HAL
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Klimuk <[email protected]>
  • Loading branch information
DaniilKl committed Oct 10, 2024
1 parent 6df9a3c commit 6327fbb
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 169 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ install:
install -m 0755 include/dts-environment.sh $(DESTDIR)$(SBINDIR)
install -m 0755 include/dts-functions.sh $(DESTDIR)$(SBINDIR)
install -m 0755 include/dts-subscription.sh $(DESTDIR)$(SBINDIR)
install -m 0755 include/hal/dts-hal.sh $(DESTDIR)$(SBINDIR)
install -m 0755 include/hal/common-mock-func.sh $(DESTDIR)$(SBINDIR)

install -m 0755 scripts/cloud_list $(DESTDIR)$(SBINDIR)
install -m 0755 scripts/dasharo-deploy $(DESTDIR)$(SBINDIR)
Expand Down
26 changes: 13 additions & 13 deletions include/dts-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# SPDX-License-Identifier: Apache-2.0

# shellcheck disable=SC2034
# shellcheck source=../include/hal/dts-hal.sh
source $DTS_HAL

# Text colors:
NORMAL='\033[0m'
Expand Down Expand Up @@ -50,15 +52,15 @@ VERBOSE_OPT="V"
VERBOSE_OPT_LOW="$(echo $VERBOSE_OPT | awk '{print tolower($0)}')"

# Hardware variables:
SYSTEM_VENDOR="${SYSTEM_VENDOR:-$(dmidecode -s system-manufacturer)}"
SYSTEM_MODEL="${SYSTEM_MODEL:-$(dmidecode -s system-product-name)}"
BOARD_VENDOR="${BOARD_VENDOR:-$(dmidecode -s system-manufacturer)}"
BOARD_MODEL="${BOARD_MODEL:-$(dmidecode -s baseboard-product-name)}"
CPU_VERSION="$(dmidecode -s processor-version)"
SYSTEM_VENDOR="${SYSTEM_VENDOR:-$($DMIDECODE -s system-manufacturer)}"
SYSTEM_MODEL="${SYSTEM_MODEL:-$($DMIDECODE -s system-product-name)}"
BOARD_VENDOR="${BOARD_VENDOR:-$($DMIDECODE -s system-manufacturer)}"
BOARD_MODEL="${BOARD_MODEL:-$($DMIDECODE -s baseboard-product-name)}"
CPU_VERSION="$($DMIDECODE -s processor-version)"

# Firmware variables
BIOS_VENDOR="${BIOS_VENDOR:-$(dmidecode -s bios-vendor)}"
BIOS_VERSION="${BIOS_VERSION:-$(dmidecode -s bios-version)}"
BIOS_VENDOR="${BIOS_VENDOR:-$($DMIDECODE -s bios-vendor)}"
BIOS_VERSION="${BIOS_VERSION:-$($DMIDECODE -s bios-version)}"
DASHARO_VERSION="$(echo $BIOS_VERSION | cut -d ' ' -f 3 | tr -d 'v')"
DASHARO_FLAVOR="$(echo $BIOS_VERSION | cut -d ' ' -f 1,2)"

Expand Down Expand Up @@ -91,17 +93,15 @@ FLASH_INFO_FILE="/tmp/flash_info"
OS_VERSION_FILE="/etc/os-release"
KEYS_DIR="/tmp/devkeys"

# Paths to system commands
CMD_POWEROFF="/sbin/poweroff"
CMD_REBOOT="/sbin/reboot"
CMD_SHELL="/bin/bash"
# Paths to system commands:
SHELL="bash"

# Paths to DTS commands:
CMD_DASHARO_HCL_REPORT="/usr/sbin/dasharo-hcl-report"
CMD_NCMENU="/usr/sbin/novacustom_menu"
CMD_DASHARO_DEPLOY="/usr/sbin/dasharo-deploy"
CMD_CLOUD_LIST="/usr/sbin/cloud_list"
CMD_EC_TRANSITION="/usr/sbin/ec_transition"
DASHARO_ECTOOL="${DASHARO_ECTOOL:-dasharo_ectool}"
FLASHROM="${FLASHROM:-flashrom}"

# Configuration variables declaration and default values (see dts-functions.sh/
# board_config function for more inf.):
Expand Down
79 changes: 39 additions & 40 deletions include/dts-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
source $DTS_ENV
# shellcheck source=../include/dts-subscription.sh
source $DTS_SUBS
# shellcheck source=../include/hal/dts-hal.sh
source $DTS_HAL

### Color functions:
function echo_green() {
Expand Down Expand Up @@ -53,7 +55,7 @@ check_if_ac() {
fi

while true; do
ac_status=$(cat ${_ac_file})
ac_status=$($FSREAD_TOOL check_if_ac_mock cat ${_ac_file})

if [ "$ac_status" -eq 1 ]; then
echo "AC adapter is connected. Continuing with firmware update."
Expand Down Expand Up @@ -121,28 +123,28 @@ it5570_i2ec() {
# TODO: Use /dev/port instead of iotools

# Address high byte
iotools io_write8 0x2e 0x2e
iotools io_write8 0x2f 0x11
iotools io_write8 0x2e 0x2f
iotools io_write8 0x2f $(($2>>8 & 0xff))
$IOTOOLS io_write8 0x2e 0x2e
$IOTOOLS io_write8 0x2f 0x11
$IOTOOLS io_write8 0x2e 0x2f
$IOTOOLS io_write8 0x2f $(($2>>8 & 0xff))

# Address low byte
iotools io_write8 0x2e 0x2e
iotools io_write8 0x2f 0x10
iotools io_write8 0x2e 0x2f
iotools io_write8 0x2f $(($2 & 0xff))
$IOTOOLS io_write8 0x2e 0x2e
$IOTOOLS io_write8 0x2f 0x10
$IOTOOLS io_write8 0x2e 0x2f
$IOTOOLS io_write8 0x2f $(($2 & 0xff))

# Data
iotools io_write8 0x2e 0x2e
iotools io_write8 0x2f 0x12
iotools io_write8 0x2e 0x2f
$IOTOOLS io_write8 0x2e 0x2e
$IOTOOLS io_write8 0x2f 0x12
$IOTOOLS io_write8 0x2e 0x2f

case $1 in
"r")
iotools io_read8 0x2f
$IOTOOLS io_read8 0x2f
;;
"w")
iotools io_write8 0x2f "$3"
$IOTOOLS io_write8 0x2f "$3"
;;
esac
}
Expand Down Expand Up @@ -356,11 +358,11 @@ board_config() {
"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 -s baseboard-version)"
elif ! dasharo_ectool info 2>/dev/null; then
BOARD_MODEL="$($DMIDECODE -s baseboard-version)"
elif ! $DASHARO_ECTOOL novacustom_check_sys_model_mock info 2>/dev/null; then
ask_for_model V540TU V560TU
else
BOARD_MODEL=$(dasharo_ectool info | grep "board:" |
BOARD_MODEL=$($DASHARO_ECTOOL novacustom_check_sys_model_mock info | grep "board:" |
sed -r 's|.*novacustom/(.*)|\1|' | awk '{print toupper($1)}')
fi

Expand Down Expand Up @@ -394,7 +396,7 @@ board_config() {
;;
"V5xTNC_TND_TNE")
if check_if_dasharo; then
BOARD_MODEL="$(dmidecode -s baseboard-version)"
BOARD_MODEL="$($DMIDECODE -s baseboard-version)"
else
ask_for_model V540TNx V560TNx
fi
Expand Down Expand Up @@ -718,7 +720,7 @@ board_config() {
}

check_flash_lock() {
$FLASHROM -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} > /tmp/check_flash_lock 2> /tmp/check_flash_lock.err
$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
Expand All @@ -731,22 +733,22 @@ check_flash_lock() {

check_flash_chip() {
echo "Gathering flash chip and chipset information..."
$FLASHROM -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 -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 -p "$PROGRAMMER_BIOS" -c "$flash_name" --flash-name >> "$FLASH_INFO_FILE" 2>> "$ERR_LOG_FILE"
$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 -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
Expand Down Expand Up @@ -900,7 +902,7 @@ verify_artifacts() {

check_intel_regions() {

FLASH_REGIONS=$($FLASHROM -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} 2>&1)
FLASH_REGIONS=$($FLASHROM check_intel_regions_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} 2>&1)
BOARD_HAS_FD_REGION=0
BOARD_FD_REGION_RW=0
BOARD_HAS_ME_REGION=0
Expand Down Expand Up @@ -928,7 +930,7 @@ 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 -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
BINARY_HAS_FD=1
Expand Down Expand Up @@ -958,11 +960,8 @@ check_if_me_disabled() {
return
fi

# Check if HECI present
# FIXME: what if HECI is not device 16.0?
if [ -d /sys/class/pci_bus/0000:00/device/0000:00:16.0 ]; then
# Check ME Current Operation Mode at offset 0x40 bits 19:16
ME_OPMODE="$(setpci -s 00:16.0 42.B 2> /dev/null | cut -c2-)"
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
return
Expand Down Expand Up @@ -997,8 +996,8 @@ check_if_me_disabled() {
fi
else
# If we are running coreboot, check for status in logs
cbmem -1 | grep -q "ME is disabled" && ME_DISABLED=1 && return # HECI (soft) disabled
cbmem -1 | grep -q "ME is HAP disabled" && ME_DISABLED=1 && return # HAP 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
Expand Down Expand Up @@ -1043,10 +1042,10 @@ 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 -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} ${FLASHROM_ADD_OPT_UPDATE} -r /tmp/bios.bin > /dev/null 2>&1
$FLASHROM check_flash_layout_mock -p "$PROGRAMMER_BIOS" ${FLASH_CHIP_SELECT} ${FLASHROM_ADD_OPT_UPDATE} -r /tmp/bios.bin > /dev/null 2>&1
if [ $? -eq 0 ] && [ -f "/tmp/bios.bin" ]; then
BOARD_FMAP_LAYOUT=$(cbfstool /tmp/bios.bin layout -w 2> /dev/null)
BINARY_FMAP_LAYOUT=$(cbfstool $1 layout -w 2> /dev/null)
BOARD_FMAP_LAYOUT=$($CBFSTOOL layout_mock /tmp/bios.bin 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
Expand Down Expand Up @@ -1183,7 +1182,7 @@ handle_fw_switching() {
esac
done
fi
elif [ ! -v DPP_IS_LOGGED ] && [ "$DASHARO_FLAVOR" == "Dasharo (coreboot+heads)" ]; then
elif [ -z "$DPP_IS_LOGGED" ] && [ "$DASHARO_FLAVOR" == "Dasharo (coreboot+heads)" ]; then
# Not logged with DPP and we are on heads, offer switch back
compare_versions $DASHARO_VERSION $HEADS_REL_VER_DPP
if [ $? -eq 1 ]; then
Expand Down Expand Up @@ -1251,7 +1250,7 @@ You can find more info about HCL in docs.dasharo.com/glossary\r"
show_ram_inf() {
# Get the data:
local data=""
data=$(dmidecode)
data=$($DMIDECODE)

# Initialize an empty array to store the extracted values:
local -a memory_devices_array
Expand Down Expand Up @@ -1548,19 +1547,19 @@ footer_options(){
send_dts_logs
set +x
unset VERBOSE_ACTIVE
${CMD_SHELL}
${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
${CMD_POWEROFF}
${POWEROFF}
;;
"${REBOOT_OPT_UP}" | "${REBOOT_OPT_LOW}")
send_dts_logs
${CMD_REBOOT}
${REBOOT}
;;
"${SEND_LOGS_OPT}" | "${SEND_LOGS_OPT_LOW}")
if [ "${SEND_LOGS_ACTIVE}" == "true" ]; then
Expand Down
2 changes: 1 addition & 1 deletion include/dts-subscription.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ check_for_dasharo_firmware() {
TEST_LOGS_URL="https://cloud.3mdeb.com/index.php/s/${CLOUDSEND_LOGS_URL}/authenticate/showShare"

# If board_config function has not set firmware links - exit with warning:
if [ ! -v BIOS_LINK_DPP ] && [ ! -v HEADS_LINK_DPP ] && [ ! -v BIOS_LINK_DPP_SEABIOS ]; then
if [ -z "$BIOS_LINK_DPP" ] && [ -z "$HEADS_LINK_DPP" ] && [ -z "$BIOS_LINK_DPP_SEABIOS" ] && [ -z "$BIOS_LINK_DPP_CAP" ]; then
print_warning "There is no Dasharo Firmware available for your platform."
return 1
fi
Expand Down
2 changes: 1 addition & 1 deletion include/hal/common-mock-func.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dasharo_ectool_update_ec_firmware_mock(){
# TODO
}

dasharo_ectool_novacustom_check_sys_model_mock(){
novacustom_check_sys_model_mock(){
# TODO
}

Expand Down
3 changes: 1 addition & 2 deletions include/hal/dts-hal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
# shellcheck source=./dts-hal-common.sh
source $DTS_ENV
# shellcheck source=./dts-hal-common.sh
source $DTS_HAL_COMMON
source $DTS_HAL_PLAT
source $DTS_MOCK_COMMON

# Set tools wrappers:
DASHARO_ECTOOL="tool_wrapper dasharo_ectool"
Expand Down
Loading

0 comments on commit 6327fbb

Please sign in to comment.