crossystem.sh 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/bin/bash
  2. # Mutable values path (needs to be writable and persistent across boots - try /mnt/stateful_partition)
  3. mutablepath="/mnt/stateful_partition/mwtrollinggoogleforfakemurk"
  4. #mutablepath="./mwtrollinggoogleforfakemurk"
  5. ##################################################
  6. # PASTE (FORMATTED) OUTPUT OF `crossystem` HERE! #
  7. ##################################################
  8. # Remove comments, put any text & hex in quotes, remove spaces
  9. ##############################################################################################################################################################################
  10. # YOU SHOULD NOT NEED TO MODIFY THIS PART OF THE SCRIPT IF YOU ARE JUST A CONSUMER! BELOW IS THE INTERNAL LOGIC! #
  11. ##############################################################################################################################################################################
  12. # make sure the mutable crossystem file exists lol
  13. touch $mutablepath
  14. # just in case
  15. chmod a+rw $mutablepath
  16. # load values from mutable crossystem
  17. # shellcheck disable=SC1090 # crossystem needs to source an external file for mutable values
  18. source $mutablepath 2>/dev/null
  19. #__SED_REPLACEME_CROSSYSTEM_VALUES#
  20. ################################################
  21. # v3 now autopopulates this for you. be happy! #
  22. ################################################
  23. read -r -d '' cwossystem <<EOM
  24. arch = $arch # [RO/str] Platform architecture
  25. backup_nvram_request = $backup_nvram_request # [RW/int] Backup the nvram somewhere at the next boot. Cleared on success.
  26. battery_cutoff_request = $battery_cutoff_request # [RW/int] Cut off battery and shutdown on next boot
  27. block_devmode = $block_devmode # [RW/int] Block all use of developer mode
  28. clear_tpm_owner_done = $clear_tpm_owner_done # [RW/int] Clear TPM owner done
  29. clear_tpm_owner_request = $clear_tpm_owner_request # [RW/int] Clear TPM owner on next boot
  30. cros_debug = $cros_debug # [RO/int] OS should allow debug features
  31. dbg_reset = $dbg_reset # [RW/int] Debug reset mode request
  32. debug_build = $debug_build # [RO/int] OS image built for debug features
  33. dev_boot_legacy = $dev_boot_legacy # [RW/int] Enable developer mode boot Legacy OSes
  34. dev_boot_signed_only = $dev_boot_signed_only # [RW/int] Enable developer mode boot only from official kernels
  35. dev_boot_usb = $dev_boot_usb # [RW/int] Enable developer mode boot from USB/SD
  36. dev_default_boot = $dev_default_boot # [RW/str] Default boot from disk, legacy or usb
  37. dev_enable_udc = $dev_enable_udc # [RW/int] Enable USB Device Controller
  38. devsw_boot = $devsw_boot # [RO/int] Developer switch position at boot
  39. devsw_cur = $devsw_cur # [RO/int] Developer switch current position
  40. disable_alt_os_request = $disable_alt_os_request # [RW/int] Disable Alt OS mode on next boot (writable)
  41. disable_dev_request = $disable_dev_request # [RW/int] Disable virtual dev-mode on next boot
  42. ecfw_act = $ecfw_act # [RO/str] Active EC firmware
  43. enable_alt_os_request = $enable_alt_os_request # [RW/int] Enable Alt OS mode on next boot (writable)
  44. post_ec_sync_delay = $post_ec_sync_delay # [RW/int] Short delay after EC software sync (persistent, writable, eve only)
  45. alt_os_enabled = $alt_os_enabled # [RO/int] Alt OS state (1 if enabled, 0 if disabled)
  46. fmap_base = $fmap_base # [RO/int] Main firmware flashmap physical address
  47. fw_prev_result = $fw_prev_result # [RO/str] Firmware result of previous boot (vboot2)
  48. fw_prev_tried = $fw_prev_tried # [RO/str] Firmware tried on previous boot (vboot2)
  49. fw_result = $fw_result # [RW/str] Firmware result this boot (vboot2)
  50. fw_tried = $fw_tried # [RO/str] Firmware tried this boot (vboot2)
  51. fw_try_count = $fw_try_count # [RW/int] Number of times to try fw_try_next
  52. fw_try_next = $fw_try_next # [RW/str] Firmware to try next (vboot2)
  53. fw_vboot2 = $fw_vboot2 # [RO/int] 1 if firmware was selected by vboot2 or 0 otherwise
  54. fwb_tries = $fwb_tries # [RW/int] Try firmware B count
  55. fwid = $fwid # [RO/str] Active firmware ID
  56. fwupdate_tries = $fwupdate_tries # [RW/int] Times to try OS firmware update (inside kern_nv)
  57. hwid = $hwid # [RO/str] Hardware ID
  58. inside_vm = $inside_vm # [RO/int] Running in a VM?
  59. kern_nv = $kern_nv # [RO/int] Non-volatile field for kernel use
  60. kernel_max_rollforward = $kernel_max_rollforward # [RW/int] Max kernel version to store into TPM
  61. kernkey_vfy = $kernkey_vfy # [RO/str] Type of verification done on kernel key block
  62. loc_idx = $loc_idx # [RW/int] Localization index for firmware screens
  63. mainfw_act = $mainfw_act # [RO/str] Active main firmware
  64. mainfw_type = $mainfw_type # [RO/str] Active main firmware type
  65. nvram_cleared = $nvram_cleared # [RW/int] Have NV settings been lost? Write 0 to clear
  66. oprom_needed = $oprom_needed # [RW/int] Should we load the VGA Option ROM at boot?
  67. phase_enforcement = $phase_enforcement # [RO/int] Board should have full security settings applied
  68. recovery_reason = $recovery_reason # [RO/int] Recovery mode reason for current boot
  69. recovery_request = $recovery_request # [RW/int] Recovery mode request
  70. recovery_subcode = $recovery_subcode # [RW/int] Recovery reason subcode
  71. recoverysw_boot = $recoverysw_boot # [RO/int] Recovery switch position at boot
  72. recoverysw_cur = $recoverysw_cur # [RO/int] Recovery switch current position
  73. recoverysw_ec_boot = $recoverysw_ec_boot # [RO/int] Recovery switch position at EC boot
  74. recoverysw_is_virtual = $recoverysw_is_virtual # [RO/int] Recovery switch is virtual
  75. ro_fwid = $ro_fwid # [RO/str] Read-only firmware ID
  76. tpm_attack = $tpm_attack # [RW/int] TPM was interrupted since this flag was cleared
  77. tpm_fwver = $tpm_fwver # [RO/int] Firmware version stored in TPM
  78. tpm_kernver = $tpm_kernver # [RO/int] Kernel version stored in TPM
  79. tpm_rebooted = $tpm_rebooted # [RO/int] TPM requesting repeated reboot (vboot2)
  80. tried_fwb = $tried_fwb # [RO/int] Tried firmware B before A this boot
  81. try_ro_sync = $try_ro_sync # [RO/int] try read only software sync
  82. vdat_flags = $vdat_flags # [RO/int] Flags from VbSharedData
  83. vdat_timers = $vdat_timers # [RO/str] Timer values from VbSharedData
  84. wipeout_request = $wipeout_request # [RW/int] Firmware requested factory reset (wipeout)
  85. wpsw_boot = $wpsw_boot # [RO/int] Firmware write protect hardware switch position at boot
  86. wpsw_cur = $wpsw_cur # [RO/int] Firmware write protect hardware switch current position
  87. EOM
  88. parse1arg() {
  89. if [[ $1 == *"?"* ]]; then
  90. # comparison mode
  91. aft="${1#*\?}" # value to check for
  92. bef="${1%\?*}" # key
  93. if [[ "${!bef}" == *"$aft"* ]]; then
  94. return 0
  95. fi
  96. return 1
  97. elif [[ $1 == *"="* ]]; then
  98. # mutable crossystem mode (NEW)
  99. aft="${1#*\=}" # value to set
  100. bef="${1%\=*}" # key
  101. # check if value exists in mutable file
  102. containsvalue=$(
  103. source $mutablepath
  104. [[ -z "${!aft}" ]] && echo 1 || echo 0
  105. )
  106. if [[ $containsvalue -eq 0 ]]; then # crossystem.sh: line 181: 0: command not found
  107. sed -i "s/${bef}.*/${bef}=${aft}/" $mutablepath
  108. else
  109. echo "${bef}=${aft}" >>$mutablepath
  110. fi
  111. else
  112. # get value mode
  113. echo -n "${!1//$'\n'/}"
  114. fi
  115. }
  116. logicor() {
  117. if [[ $1 -eq 1 ]]; then
  118. return 1
  119. elif [[ $2 -eq 1 ]]; then
  120. return 1
  121. else
  122. return 0
  123. fi
  124. }
  125. if [[ $# -eq 0 ]]; then
  126. echo -e "$cwossystem"
  127. elif [[ $# -eq 1 ]]; then
  128. parse1arg "$1"
  129. exit $?
  130. else
  131. for arg in "$@"; do
  132. parse1arg "$arg"
  133. excode="$?"
  134. logicor "$current_excode" "$excode"
  135. current_excode=$?
  136. echo -n " "
  137. done
  138. exit "$current_excode"
  139. fi