diff --git a/CHANGES.txt b/CHANGES.txt index b427d11..e6ee8d2 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,16 @@ +v3.2.68 +- Updated so E10M20-T1, M2D20, M2D18 and M2D17 now work in models that use device tree and are using: + - DSM 7.2 Update 2 and 3, 7.2.1, 7.2.1 Update 1, 2 and 3. Issue #132, #148 +- Now edits model.dtb instead of downloading a pre-edited version. +- Improvements to --restore option. +- Fix for Unknown vendor causing "Unsupported firmware version" warning. Issue #161 +- Now supports NVMe drives that show as Unknown brand in storage manager: Issue #161 + - ADATA, Corsair, Gigabyte, HS/MAXIO, MSI, Netac, Phison, PNY + - SK Hynix, Solidigm, SPCC/Lexar, TEAMGROUP, UMIS, ZHITAI +- Fixed bug where memory was shown in MB but with GB unit. +- Removed -i, --immutable option. +- Minor bug fixes. + v3.1.65 - Bug fix for NVMe drives with / in the model name for non-device tree Synology models. Issue #154 diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index df629a9..c9e5a62 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -4,12 +4,6 @@ # Github: https://github.com/007revad/Synology_HDD_db # Script verified at https://www.shellcheck.net/ # -# Easiest solution: -# Edit /etc.defaults/synoinfo.conf and change support_disk_compatibility="yes" to "no" and reboot. -# Then all drives can be used without error messages. -# -# But lets do this the proper way by adding our drive models to the appropriate .db file. -# # To run in task manager as root (manually or scheduled): # /volume1/scripts/syno_hdd_db.sh # replace /volume1/scripts/ with path to script # @@ -21,206 +15,24 @@ # sudo -i /volume1/scripts/syno_hdd_db.sh -force -showedits #-------------------------------------------------------------------------------------------------- -# TODO -# Maybe also edit the other disk compatibility db in synoboot, used during boot time. -# It's also parsed and checked and probably in some cases it could be more critical to patch that one instead. -# -# Solve issue of --restore option restoring files that were backed up with older DSM version. -# Change how synoinfo.conf is backed up and restored to prevent issue #73 - -# DONE -# Bug fix for NVMe drives with / in the model name for non-device tree Synology models. -# -# Bug fix for script not updating itself if .sh file had been renamed. -# -# Bug fix for missing executable permissions if .sh file had been renamed. -# -# Bug fix to prevent update loop if script's .tar.gz file already exists in /tmp. -# -# Bug fix to prevent update failing if script's temp folder already exists in /tmp. -# -# Now only copies CHANGES.txt to script location if script is located on a volume, -# to prevent putting CHANGES.txt on system partition (/usr/bin, /usr/sbin, /root etc.) -# -# Added -e --email option to disable coloured output to make task scheduler emails easier to read. -# -# -# Added support to disable unsupported memory warnings on DVA models. -# -# Fixed bug where newly connected expansion units weren't found until up to 24 hours later. #124 -# -# Added enabling E10M20-T1, M2D20 and M2D18 for DS1821+, DS1621+ and DS1520+. -# Added enabling M2D18 for RS822RP+, RS822+, RS1221RP+ and RS1221+ with older DSM version. -# -# Fixed enabling E10M20-T1, M2D20 and M2D18 cards in models that don't officially support them. -# -# Fixed bugs where the calculated amount of installed memory could be incorrect: -# - If last memory socket was empty an invalid unit of bytes could be used. Issue #106 -# - When dmidecode returned MB for one ram module and GB for another ram module. Issue #107 -# -# Fixed bug displaying the max memory setting if total installed memory was less than the max memory. Issue #107 -# -# Fixed bug where sata1 drive firmware version was wrong if there was a sata10 drive. -# -# Minor bug fix for checking amount of installed memory. -# -# Now enables any installed Synology M.2 PCIe cards for models that don't officially support them. -# -# Added -i, --immutable option to enable immutable snapshots on models older than '20 series running DSM 7.2. -# -# Changed help to show that -r, --ram also sets max memory to the amount of installed memory. -# -# Changed the "No M.2 cards found" to "No M.2 PCIe cards found" to make it clearer. -# -# Added "You may need to reboot" message when NVMe drives were detected. -# -# Fixed HDD/SSD firmware versions always being 4 characters long (for DSM 7.2 and 6.2.4 Update 7). -# -# Fixed detecting the amount of installed memory (for DSM 7.2 which now reports GB instead of MB). -# -# Fixed USB drives sometimes being detected as internal drives (for DSM 7.2). -# -# Fixed error if /run/synostorage/disks/nvme0n1/m2_pool_support doesn't exist yet (for DSM 7.2). -# -# Fixed drive db update still being disabled in /etc/synoinfo.conf after script run without -n or --noupdate option. -# -# Fixed drive db update still being disabled in /etc/synoinfo.conf after script run with --restore option. -# -# Fixed permissions on restored files being incorrect after script run with --restore option. -# -# Fixed permissions on backup files. -# -# Now skips checking the amount of installed memory in DSM 6 (because it was never working). -# -# Now the script reloads itself after updating. -# -# Added --autoupdate=AGE option to auto update synology_hdd_db x days after new version released. -# Autoupdate logs update success or errors to DSM system log. -# -# Added -w, --wdda option to disable WDDA -# https://kb.synology.com/en-us/DSM/tutorial/Which_Synology_NAS_supports_WDDA -# https://www.youtube.com/watch?v=cLGi8sPLkLY -# https://community.synology.com/enu/forum/1/post/159537 -# -# Added --restore info to --help -# -# Updated restore option to download the latest db files from Synology -# -# Now warns you if you try to run it in sh with "sh scriptname.sh" -# -# Fixed DSM 6 bug where the drives were being duplicated in the .db files each time the script was run. -# -# Fixed DSM 6 bug where the .db files were being duplicated as .dbr each time the db files were edited. -# -# Fixed bug where expansion units ending in RP or II were not detected. -# -# Added a --restore option to undo all changes. -# -# Now looks for and edits both v7 and non-v7 db files to solve issue #11 for RS '21 models running DSM 6.2.4. -# This will also ensure the script still works if: -# Synology append different numbers to the db file names in DSM 8 etc. -# The detected NAS model name does not match the .db files' model name. -# -# Now backs up the .db.new files (as well as the .db files). -# -# Now shows max memory in GB instead of MB. -# -# Now shows status of "Support disk compatibility" setting even if it wasn't changed. -# -# Now shows status of "Support memory compatibility" setting even if it wasn't changed. -# -# Improved shell output when editing max memory setting. -# -# Changed method of checking if drive is a USB drive to prevent ignoring internal drives on RS models. -# -# Changed to not run "synostgdisk --check-all-disks-compatibility" in DSM 6.2.3 (which has no synostgdisk). -# -# Now edits max supported memory to match the amount of memory installed, if greater than the current max memory setting. -# -# Now allows creating M.2 storage pool and volume all from Storage Manager +# CHANGES +# Updated so E10M20-T1, M2D20, M2D18 and M2D17 now work in models that use devicetree +# and are using DSM 7.2 Update 2 or 3, 7.2.1, 7.2.1 Update 1, 2 or 3. # -# Now always shows your drive entries in the host db file if -s or --showedits used, -# instead of only db file was edited during that run. +# Now edits model.dtb instead of downloading a pre-edited version. # -# Changed to show usage if invalid long option used instead of continuing. +# Fix for Unknown vendor causing "Unsupported firmware version" warning. Issue #161 # -# Fixed bug inserting firmware version for already existing model. +# Now supports NVMe drives that show as Unknown brand in storage manager: Issue #161 +# - ADATA, Corsair, Gigabyte, HS/MAXIO, MSI, Netac, Phison, PNY +# - SK Hynix, Solidigm, SPCC/Lexar, TEAMGROUP, UMIS, ZHITAI # -# Changed to add drives' firmware version to the db files (to support data deduplication). -# See https://github.com/007revad/Synology_enable_Deduplication +# Fixed bug where memory was shown in MB but with GB unit. # -# Changed to be able to edit existing drive entries in the db files to add the firmware version. -# -# Now supports editing db files that don't currently have any drives listed. -# -# Fixed bug where the --noupdate option was coded as --nodbupdate. Now either will work. -# -# Fixed bug in re-enable drive db updates -# -# Fixed "download new version" failing if script was run via symlink or ./ -# -# Changed to show if no M.2 cards were found, if M.2 drives were found. -# -# Changed latest version check to download to /tmp and extract files to the script's location, -# replacing the existing .sh and readme.txt files. -# -# Added a timeouts when checking for newer script version in case github is down or slow. -# -# Added option to disable incompatible memory notifications. -# -# Now finds your expansion units' model numbers and adds your drives to their db files. -# -# Now adds your M.2 drives to your M.2 PCI cards db files (M2Dxx and E10M20-T1 and future models). -# -# Improved flags/options checking and added usage help. -# -# Can now download the latest script version for you (if you have user home service enabled in DSM). -# -# Now adds 'support_m2_pool="yes"' line for models that don't have support_m2_pool in synoinfo.conf -# to (hopefully) prevent losing your SSH created M2 volume when running this script on models -# that DSM 7.2 Beta does not list as supported for creating M2 volumes. -# -# Changed Synology model detection to be more reliable (for models that came in different variations). -# -# Changed checking drive_db_test_url setting to be more durable. -# -# Added removal of " 00Y" from end of Samsung/Lenovo SSDs to fix issue #13. -# -# Fixed bug where removable drives were being detected and added to drive database. -# -# Fixed bug where "M.2 volume support already enabled" message appeared when NAS had no M.2 drives. -# -# Added check that M.2 volume support is enabled (on supported models). -# -# Added support for M.2 SATA drives. -# -# Can now skip processing M.2 drives by running script with the -m2 flag. -# -# Changed method of getting drive and firmware version so script is faster and easier to maintain. -# - No longer using smartctl or hdparm. -# -# Changed SAS drive firmware version detection to support SAS drives that hdparm doesn't work with. -# -# Removed error message and aborting if *.db.new not found (clean DSM installs don't have a *.db.new). -# -# Force DSM to check disk compatibility so reboot not needed (DSM 6 may still need a reboot). -# -# Fixed DSM 6 issue when DSM 6 has the old db file format. -# -# Add support for SAS drives. -# -# Get HDD/SSD/SAS drive model number with smartctl instead of hdparm. -# -# Check if there is a newer script version available. -# -# Add support for NVMe drives. -# -# Prevent DSM auto updating the drive database. -# -# Optionally disable "support_disk_compatibility". +# Bug fixes and improvements to --restore option. -scriptver="v3.1.65" +scriptver="v3.2.68" script=Synology_HDD_db repo="007revad/Synology_HDD_db" @@ -233,11 +45,11 @@ fi #echo -e "bash version: $(bash --version | head -1 | cut -d' ' -f4)\n" # debug -ding(){ +ding(){ printf \\a } -usage(){ +usage(){ cat <&2 + echo -e "Contact 007revad to get your drive added.\n" >&2 + ;; + esac +} + +set_vendor(){ + # Add missing vendors to /usr/syno/etc.defaults/pci_vendor_ids.conf + if [[ $vendor ]]; then + if ! grep "$vid" "$vidfile" >/dev/null; then + synosetkeyvalue "$vidfile" "${vid,,}" "$vendor" + val=$(synogetkeyvalue "$vidfile" "${vid,,}") + if [[ $val == "${vendor}" ]]; then + echo "Added $vendor to pci_vendor_ids" >&2 + else + echo "Failed to add $vendor to pci_vendor_ids!" >&2 + fi + fi + if ! grep "$vid" "$vidfile2" >/dev/null; then + synosetkeyvalue "$vidfile2" "${vid,,}" "$vendor" + fi + fi +} + +get_vid(){ + # $1 is /dev/nvme0n1 etc + if [[ $1 ]]; then + vid=$(nvme id-ctrl "$1" | grep -E ^vid | awk '{print $NF}') + if [[ $vid ]]; then + val=$(synogetkeyvalue "$vidfile" "${vid,,}") + if [[ -z $val ]]; then + vendor_from_id "$vid" && set_vendor + fi + fi + fi +} + +vidfile="/usr/syno/etc.defaults/pci_vendor_ids.conf" +vidfile2="/usr/syno/etc/pci_vendor_ids.conf" + +fixdrivemodel(){ # Remove " 00Y" from end of Samsung/Lenovo SSDs # Github issue #13 - if [[ $1 =~ MZ.*" 00Y" ]]; then + if [[ $1 =~ MZ.*' 00Y' ]]; then hdmodel=$(printf "%s" "$1" | sed 's/ 00Y.*//') fi # Brands that return "BRAND " and need "BRAND " removed. - if [[ $1 =~ ^[A-Za-z]{1,7}" ".* ]]; then + if [[ $1 =~ ^[A-Za-z]{3,7}' '.* ]]; then # See Smartmontools database in /var/lib/smartmontools/drivedb.db hdmodel=${hdmodel#"WDC "} # Remove "WDC " from start of model name hdmodel=${hdmodel#"HGST "} # Remove "HGST " from start of model name @@ -739,11 +665,13 @@ fixdrivemodel(){ hdmodel=${hdmodel#"Hitachi "} # Remove "Hitachi " from start of model name hdmodel=${hdmodel#"SAMSUNG "} # Remove "SAMSUNG " from start of model name hdmodel=${hdmodel#"FUJISTU "} # Remove "FUJISTU " from start of model name + elif [[ $1 =~ ^'APPLE HDD '.* ]]; then + # Old drive brands hdmodel=${hdmodel#"APPLE HDD "} # Remove "APPLE HDD " from start of model name fi } -getdriveinfo(){ +getdriveinfo(){ # $1 is /sys/block/sata1 etc # Skip USB drives @@ -772,7 +700,7 @@ getdriveinfo(){ fi } -getm2info(){ +getm2info(){ # $1 is /sys/block/nvme0n1 etc nvmemodel=$(cat "$1/device/model") nvmemodel=$(printf "%s" "$nvmemodel" | xargs) # trim leading and trailing white space @@ -788,7 +716,7 @@ getm2info(){ fi } -getcardmodel(){ +getcardmodel(){ # Get M.2 card model (if M.2 drives found) # $1 is /dev/nvme0n1 etc if [[ ${#nvmelist[@]} -gt "0" ]]; then @@ -815,7 +743,8 @@ getcardmodel(){ fi } -m2_pool_support(){ +m2_pool_support(){ + # M.2 drives in M2 adaptor card do not support storage pools if [[ -f /run/synostorage/disks/"$(basename -- "$1")"/m2_pool_support ]]; then # GitHub issue #86, 87 echo 1 > /run/synostorage/disks/"$(basename -- "$1")"/m2_pool_support fi @@ -839,6 +768,11 @@ for d in /sys/block/*; do nvme*) if [[ $d =~ nvme[0-9][0-9]?n[0-9][0-9]?$ ]]; then if [[ $m2 != "no" ]]; then + # Fix unknown vendor id if needed. GitHub issue #161 + # "Failed to get disk vendor" from synonvme --vendor-get + # causes "Unsupported firmware version" warning. + get_vid "/dev/$(basename -- "${d}")" + getm2info "$d" "nvme" # Get M.2 card model if in M.2 card getcardmodel "/dev/$(basename -- "${d}")" @@ -1006,7 +940,7 @@ fi # Don't check .db.new as new installs don't have a .db.new file -getdbtype(){ +getdbtype(){ # Detect drive db type if grep -F '{"disk_compatbility_info":' "$1" >/dev/null; then # DSM 7 drive db files start with {"disk_compatbility_info": @@ -1022,16 +956,21 @@ getdbtype(){ } -backupdb(){ +backupdb(){ # Backup database file if needed if [[ ! -f "$1.bak" ]]; then if [[ $(basename "$1") == "synoinfo.conf" ]]; then echo "" >&2 # Formatting for stdout fi + if [[ $2 == "long" ]]; then + fname="$1" + else + fname=$(basename -- "${1}") + fi if cp -p "$1" "$1.bak"; then - echo -e "Backed up $(basename -- "${1}")" >&2 + echo -e "Backed up ${fname}" >&2 else - echo -e "${Error}ERROR 5${Off} Failed to backup $(basename -- "${1}")!" >&2 + echo -e "${Error}ERROR 5${Off} Failed to backup ${fname}!" >&2 return 1 fi fi @@ -1062,7 +1001,7 @@ done #------------------------------------------------------------------------------ # Edit db files -editcount(){ +editcount(){ # Count drives added to host db files if [[ $1 =~ .*\.db$ ]]; then db1Edits=$((db1Edits +1)) @@ -1072,7 +1011,7 @@ editcount(){ } -editdb7(){ +editdb7(){ if [[ $1 == "append" ]]; then # model not in db file #if sed -i "s/}}}/}},\"$hdmodel\":{$fwstrng$default/" "$2"; then # append if sed -i "s/}}}/}},\"${hdmodel//\//\\/}\":{$fwstrng$default/" "$2"; then # append @@ -1102,12 +1041,11 @@ editdb7(){ echo -e "\n${Error}ERROR 6c${Off} Failed to update $(basename -- "$2")${Off}" #exit 6 fi - fi } -updatedb(){ +updatedb(){ hdmodel=$(printf "%s" "$1" | cut -d"," -f 1) fwrev=$(printf "%s" "$1" | cut -d"," -f 2) @@ -1132,17 +1070,18 @@ updatedb(){ default="$default":\"support\",\"fw_dsm_update_status_notify\":false,\"barebone_installable\":true}]}}} if grep '"disk_compatbility_info":{}' "$2" >/dev/null; then - # Replace "disk_compatbility_info":{} with "disk_compatbility_info":{"WD40PURX-64GVNY0":{"80.00A80":{ ... }}},"default":{ ... }}}} + # Replace "disk_compatbility_info":{} with + # "disk_compatbility_info":{"WD40PURX-64GVNY0":{"80.00A80":{ ... }}},"default":{ ... }}}} #echo "Edit empty db file:" # debug editdb7 "empty" "$2" elif grep '"'"$hdmodel"'":' "$2" >/dev/null; then - # Replace "WD40PURX-64GVNY0":{ with "WD40PURX-64GVNY0":{"80.00A80":{ ... }}}, + # Replace "WD40PURX-64GVNY0":{ with "WD40PURX-64GVNY0":{"80.00A80":{ ... }}}, #echo "Insert firmware version:" # debug editdb7 "insert" "$2" else - # Add "WD40PURX-64GVNY0":{"80.00A80":{ ... }}},"default":{ ... }}} + # Add "WD40PURX-64GVNY0":{"80.00A80":{ ... }}},"default":{ ... }}} #echo "Append drive and firmware:" # debug editdb7 "append" "$2" fi @@ -1228,26 +1167,34 @@ done #------------------------------------------------------------------------------ # Enable unsupported Synology M2 PCIe cards -# DS1821+, DS1621+ and DS1520+ also need edited device tree blob file -# /etc.defaults/model.dtb -# RS822RP+, RS822+, RS1221RP+ and RS1221+ with DSM older than 7.2 need -# device tree blob file from DSM 7.2 to support M2D18 - -enable_card(){ +enable_card(){ # $1 is the file # $2 is the section # $3 is the card model and mode if [[ -f $1 ]] && [[ -n $2 ]] && [[ -n $3 ]]; then + backupdb "$adapter_cards" long + backupdb "$adapter_cards2" long + # Check if section exists if ! grep '^\['"$2"'\]$' "$1" >/dev/null; then echo -e "Section [$2] not found in $(basename -- "$1")!" >&2 return fi # Check if already enabled - val=$(get_section_key_value "$1" "$2" "$modelname") + # + # No idea if "cat /proc/sys/kernel/syno_hw_version" returns upper or lower case RP + # "/usr/syno/etc.defaults/adapter_cards.conf" uses lower case rp but upper case RS + # So we'll convert RP to rp when needed. + # + modelrplowercase=${modelname//RP/rp} + val=$(get_section_key_value "$1" "$2" "$modelrplowercase") if [[ $val != "yes" ]]; then - if set_section_key_value "$1" "$2" "$modelname" yes; then + # /usr/syno/etc.defaults/adapter_cards.conf + if set_section_key_value "$1" "$2" "$modelrplowercase" yes; then + # /usr/syno/etc/adapter_cards.conf + set_section_key_value "$adapter_cards2" "$2" "$modelrplowercase" yes echo -e "Enabled ${Yellow}$3${Off} for ${Cyan}$modelname${Off}" >&2 + rebootmsg=yes else echo -e "${Error}ERROR 9${Off} Failed to enable $3 for ${modelname}!" >&2 fi @@ -1257,103 +1204,231 @@ enable_card(){ fi } -check_modeldtb(){ +dts_m2_card(){ +# $1 is the card model +# $2 is the dts file + +# Remove last }; so we can append to dts file +sed -i '/^};/d' "$2" + +# Append PCIe M.2 card node to dts file +if [[ $1 == E10M20-T1 ]] || [[ $1 == M2D20 ]]; then + cat >> "$2" <> "$2" <; + }; + + nvme { + pcie_postfix = "00.0,04.0,00.0"; + port_type = "ssdcache"; + }; + }; + + m2_card@2 { + + ahci { + pcie_postfix = "00.0,03.0,00.0"; + ata_port = <0x01>; + }; + + nvme { + pcie_postfix = "00.0,05.0,00.0"; + port_type = "ssdcache"; + }; + }; + }; +}; +EOM2D18 + +elif [[ $1 == M2D17 ]]; then + cat >> "$2" <; + }; + }; + + m2_card@2 { + + ahci { + pcie_postfix = "00.0,03.0,00.0"; + ata_port = <0x01>; + }; + }; + }; +}; +EOM2D17 + +fi +} + +install_binfile(){ + # install_binfile + # example: + # file_url="https://raw.githubusercontent.com/${repo}/main/bin/dtc" + # install_binfile dtc "$file_url" /usr/bin/bc a+x bin/dtc + + if [[ -f "${scriptpath}/$5" ]]; then + binfile="${scriptpath}/$5" + echo -e "\nInstalling ${1}" + elif [[ -f "${scriptpath}/$(basename -- "$5")" ]]; then + binfile="${scriptpath}/$(basename -- "$5")" + echo -e "\nInstalling ${1}" + else + # Download binfile + if [[ $autoupdate == "yes" ]]; then + reply=y + else + echo -e "\nNeed to download ${1}" + echo -e "${Cyan}Do you want to download ${1}?${Off} [y/n]" + read -r -t 30 reply + fi + if [[ ${reply,,} == "y" ]]; then + echo -e "\nDownloading ${1}" + if ! curl -kL -m 30 --connect-timeout 5 "$2" -o "/tmp/$1"; then + echo -e "${Error}ERROR${Off} Failed to download ${1}!" + return + fi + binfile="/tmp/${1}" + + printf "Downloaded md5: " + md5sum -b "$binfile" | awk '{print $1}' + + md5=$(md5sum -b "$binfile" | awk '{print $1}') + if [[ $md5 != "$6" ]]; then + echo "Expected md5: $6" + echo -e "${Error}ERROR${Off} Downloaded $1 md5 hash does not match!" + exit 1 + fi + else + echo -e "${Error}ERROR${Off} Cannot add M2 PCIe card without ${1}!" + exit 1 + fi + fi + + # Set binfile executable + chmod "$4" "$binfile" + + # Copy binfile to destination + cp -p "$binfile" "$3" +} + +edit_modeldtb(){ # $1 is E10M20-T1 or M2D20 or M2D18 or M2D17 - if [[ -f /etc.defaults/model.dtb ]]; then - if ! grep --text "$1" /etc.defaults/model.dtb >/dev/null; then - if [[ $modelname == "DS1821+" ]] || [[ $modelname == "DS1621+" ]] ||\ - [[ $modelname == "DS1520+" ]] || [[ $modelname == "RS822rp+" ]] ||\ - [[ $modelname == "RS822+" ]] || [[ $modelname == "RS1221rp+" ]] ||\ - [[ $modelname == "RS1221+" ]]; - then - echo "" >&2 - if [[ -f ./dtb/${modelname}_model.dtb ]]; then - # Edited device tree blob exists in dtb folder with script - blob="./dtb/${modelname}_model.dtb" - elif [[ -f ./${modelname}_model.dtb ]]; then - # Edited device tree blob exists with script - blob="./${modelname}_model.dtb" - else - # Download edited device tree blob model.dtb from github - if cd /var/services/tmp; then - echo -e "Downloading ${modelname}_model.dtb" >&2 - repo=https://github.com/007revad/Synology_HDD_db - url=${repo}/raw/main/dtb/${modelname}_model.dtb - curl -LJO -m 30 --connect-timeout 5 "$url" - echo "" >&2 - cd "$scriptpath" || echo -e "${Error}ERROR${Off} Failed to cd to script location!" - else - echo -e "${Error}ERROR${Off} /var/services/tmp does not exist!" >&2 - fi + if [[ -f /etc.defaults/model.dtb ]]; then # Is device tree model + # Check if dtc exists and is executable + if [[ ! -x $(which dtc) ]]; then + md5hash="01381dabbe86e13a2f4a8017b5552918" + branch="main" + file_url="https://raw.githubusercontent.com/${repo}/${branch}/bin/dtc" + # install_binfile + install_binfile dtc "$file_url" /usr/sbin/dtc "a+x" bin/dtc "$md5hash" + fi - # Check we actually downloaded the file - if [[ -f /var/services/tmp/${modelname}_model.dtb ]]; then - blob="/var/services/tmp/${modelname}_model.dtb" - else - echo -e "${Error}ERROR${Off} Failed to download ${modelname}_model.dtb!" >&2 - fi - fi - if [[ -f $blob ]]; then - # Backup model.dtb - if ! backupdb "/etc.defaults/model.dtb"; then - echo -e "${Error}ERROR${Off} Failed to backup /etc.defaults/model.dtb!" >&2 - else - # Move and rename downloaded model.dtb - if mv "$blob" "/etc.defaults/model.dtb"; then - echo -e "Enabled ${Yellow}$1${Off} in ${Cyan}model.dtb${Off}" >&2 - else - echo -e "${Error}ERROR${Off} Failed to add support for ${1}" >&2 - fi + # Check again if dtc exists and is executable + if [[ -x /usr/sbin/dtc ]]; then - # Fix permissions if needed - octal=$(stat -c "%a %n" "/etc.defaults/model.dtb" | cut -d" " -f1) - if [[ ! $octal -eq 644 ]]; then - chmod 644 "/etc.defaults/model.dtb" - fi - fi + # Backup model.dtb + backupdb "$dtb_file" long + + # Output model.dtb to model.dts + dtc -q -I dtb -O dts -o "$dts_file" "$dtb_file" # -q Suppress warnings + chmod 644 "$dts_file" + + # Edit model.dts + for c in "${cards[@]}"; do + # Edit model.dts if needed + if ! grep "$c" "$dtb_file" >/dev/null; then + dts_m2_card "$c" "$dts_file" + echo -e "Added ${Yellow}$c${Off} to ${Cyan}model${hwrev}.dtb${Off}" >&2 else - #echo -e "${Error}ERROR${Off} Missing file ${modelname}_model.dtb" >&2 - echo -e "${Error}ERROR${Off} Missing file $blob" >&2 + echo -e "${Yellow}$c${Off} already exists in ${Cyan}model${hwrev}.dtb${Off}" >&2 fi - else - echo -e "\n${Cyan}Contact 007revad to get an edited model.dtb file for your model.${Off}" >&2 - fi + done + + # Compile model.dts to model.dtb + dtc -q -I dts -O dtb -o "$dtb_file" "$dts_file" # -q Suppress warnings + + # Set owner and permissions for model.dtb + chmod a+r "$dtb_file" + chown root:root "$dtb_file" + cp -pu "$dtb_file" "$dtb2_file" # Copy dtb file to /etc + rebootmsg=yes else - echo -e "${Yellow}$1${Off} already enabled in ${Cyan}model.dtb${Off}" >&2 + echo -e "${Error}ERROR${Off} Missing /usr/sbin/dtc or not executable!" >&2 fi fi } for c in "${m2cards[@]}"; do - #echo "" - m2cardconf="/usr/syno/etc.defaults/adapter_cards.conf" case "$c" in E10M20-T1) - backupdb "$m2cardconf" echo "" - enable_card "$m2cardconf" E10M20-T1_sup_nic "E10M20-T1 NIC" - enable_card "$m2cardconf" E10M20-T1_sup_nvme "E10M20-T1 NVMe" - enable_card "$m2cardconf" E10M20-T1_sup_sata "E10M20-T1 SATA" - check_modeldtb "$c" + enable_card "$adapter_cards" E10M20-T1_sup_nic "E10M20-T1 NIC" + enable_card "$adapter_cards" E10M20-T1_sup_nvme "E10M20-T1 NVMe" + #enable_card "$adapter_cards" E10M20-T1_sup_sata "E10M20-T1 SATA" + cards=(E10M20-T1) && edit_modeldtb ;; M2D20) - backupdb "$m2cardconf" echo "" - enable_card "$m2cardconf" M2D20_sup_nvme "M2D20 NVMe" - check_modeldtb "$c" + enable_card "$adapter_cards" M2D20_sup_nvme "M2D20 NVMe" + cards=(M2D20) && edit_modeldtb ;; M2D18) - backupdb "$m2cardconf" echo "" - enable_card "$m2cardconf" M2D18_sup_nvme "M2D18 NVMe" - enable_card "$m2cardconf" M2D18_sup_sata "M2D18 SATA" - check_modeldtb "$c" + enable_card "$adapter_cards" M2D18_sup_nvme "M2D18 NVMe" + enable_card "$adapter_cards" M2D18_sup_sata "M2D18 SATA" + cards=(M2D18) && edit_modeldtb ;; M2D17) - backupdb "$m2cardconf" echo "" - enable_card "$m2cardconf" M2D17_sup_sata "M2D17 SATA" + enable_card "$adapter_cards" M2D17_sup_sata "M2D17 SATA" + cards=(M2D17) && edit_modeldtb ;; *) echo "Unknown M2 card type: $c" @@ -1429,7 +1504,7 @@ if [[ ${model:0:3} != "dva" ]]; then fi fi -# Optionally disable SynoMemCheck.service for DVA models +# Disable SynoMemCheck.service for DVA models if [[ ${model:0:3} == "dva" ]]; then memcheck="/usr/lib/systemd/system/SynoMemCheck.service" if [[ $(synogetkeyvalue "$memcheck" ExecStart) == "/usr/syno/bin/syno_mem_check" ]]; then @@ -1476,7 +1551,7 @@ if [[ $dsm -gt "6" ]]; then # DSM 6 as has no /proc/meminfo if [[ $ramtotal == "$setting" ]]; then #echo -e "\nSet max memory to $ramtotal MB." ramgb=$((ramtotal / 1024)) - echo -e "\nSet max memory to $ramtotal GB." + echo -e "\nSet max memory to $ramgb GB." else echo -e "\n${Error}ERROR${Off} Failed to change max memory!" fi @@ -1490,7 +1565,7 @@ if [[ $dsm -gt "6" ]]; then # DSM 6 as has no /proc/meminfo if [[ $settingbak == "$setting" ]]; then #echo -e "\nSet max memory to $ramtotal MB." ramgb=$((ramtotal / 1024)) - echo -e "\nRestored max memory to $ramtotal GB." + echo -e "\nRestored max memory to $ramgb GB." else echo -e "\n${Error}ERROR${Off} Failed to restore max memory!" fi @@ -1511,33 +1586,66 @@ if [[ $dsm -gt "6" ]]; then # DSM 6 as has no /proc/meminfo fi -# Enable m2 volume support -if [[ $m2 != "no" ]]; then - if [[ $m2exists == "yes" ]]; then - # Check if m2 volume support is enabled - smp=support_m2_pool - setting="$(get_key_value $synoinfo ${smp})" +# Enable nvme support +if ls /dev | grep nvme >/dev/null ; then + if [[ $m2 != "no" ]]; then + # Check if nvme support is enabled + setting="$(get_key_value $synoinfo supportnvme)" enabled="" if [[ ! $setting ]]; then - # Add support_m2_pool="yes" - #echo 'support_m2_pool="yes"' >> "$synoinfo" - synosetkeyvalue "$synoinfo" "$smp" "yes" + # Add supportnvme="yes" + synosetkeyvalue "$synoinfo" supportnvme "yes" enabled="yes" elif [[ $setting == "no" ]]; then - # Change support_m2_pool="no" to "yes" - synosetkeyvalue "$synoinfo" "$smp" "yes" + # Change supportnvme="no" to "yes" + synosetkeyvalue "$synoinfo" supportnvme "yes" enabled="yes" elif [[ $setting == "yes" ]]; then - echo -e "\nM.2 volume support already enabled." + echo -e "\nNVMe support already enabled." fi - # Check if we enabled m2 volume support - setting="$(get_key_value $synoinfo ${smp})" + # Check if we enabled nvme support + setting="$(get_key_value $synoinfo supportnvme)" if [[ $enabled == "yes" ]]; then if [[ $setting == "yes" ]]; then - echo -e "\nEnabled M.2 volume support." + echo -e "\nEnabled NVMe support." else - echo -e "\n${Error}ERROR${Off} Failed to enable m2 volume support!" + echo -e "\n${Error}ERROR${Off} Failed to enable NVMe support!" + fi + fi + fi +fi + + +# Enable m2 volume support +if ls /dev | grep nv[em] >/dev/null ; then + if [[ $m2 != "no" ]]; then + if [[ $m2exists == "yes" ]]; then + # Check if m2 volume support is enabled + smp=support_m2_pool + setting="$(get_key_value $synoinfo ${smp})" + enabled="" + if [[ ! $setting ]]; then + # Add support_m2_pool="yes" + #echo 'support_m2_pool="yes"' >> "$synoinfo" + synosetkeyvalue "$synoinfo" "$smp" "yes" + enabled="yes" + elif [[ $setting == "no" ]]; then + # Change support_m2_pool="no" to "yes" + synosetkeyvalue "$synoinfo" "$smp" "yes" + enabled="yes" + elif [[ $setting == "yes" ]]; then + echo -e "\nM.2 volume support already enabled." + fi + + # Check if we enabled m2 volume support + setting="$(get_key_value $synoinfo ${smp})" + if [[ $enabled == "yes" ]]; then + if [[ $setting == "yes" ]]; then + echo -e "\nEnabled M.2 volume support." + else + echo -e "\n${Error}ERROR${Off} Failed to enable m2 volume support!" + fi fi fi fi @@ -1608,22 +1716,6 @@ if [[ $wdda == "no" ]]; then fi -# Optionally enable "support_worm" (immutable snapshots) -setting="$(get_key_value $synoinfo support_worm)" -if [[ $immutable == "yes" ]]; then - if [[ $setting != "yes" ]]; then - # Disable support_memory_compatibility - synosetkeyvalue "$synoinfo" support_worm "yes" - setting="$(get_key_value "$synoinfo" support_worm)" - if [[ $setting == "yes" ]]; then - echo -e "\nEnabled Immutable Snapshots." - fi - elif [[ $setting == "no" ]]; then - echo -e "\nImmutable Snapshots already enabled." - fi -fi - - #------------------------------------------------------------------------------ # Finished