2 # SPDX-License-Identifier: BSD-3-Clause
5 declare -i NEW_SPEED
="$2"
7 readonly EFS_SIG_DWORD
="55aa55aa"
8 readonly FAST_SPEED_NEW_F15_MOD_60_6F_OFFSET
=0x41
9 readonly SPI_FASTSPEED_F17_MOD_00_2F_OFFSET
=0x44
10 readonly SPI_FASTSPEED_F17_MOD_30_3F_OFFSET
=0x48
12 # print out the very simple usage
14 echo "Usage: $0 <ROM> <Speed>"
15 echo " Speed must be between 0 & 5"
24 # Validate the input parameters
25 if [[ $# -ne 2 ||
! -f "${ROM}" || "${NEW_SPEED}" -lt 0 || "${NEW_SPEED}" -gt 5 ]]; then
30 # Read a 32, 16, or 8 bit value from a location in a binary file
35 if [[ ${length} -eq 1 ]]; then
36 dd "if=${ROM}" bs=1 "skip=${location}" "count=${length}" 2>/dev
/null |
hexdump -v -e '1/1 "%02x\n"'
37 elif [[ ${length} -eq 2 ]]; then
38 dd "if=${ROM}" bs=1 "skip=${location}" "count=${length}" 2>/dev
/null |
hexdump -v -e '1/2 "%04x\n"'
39 elif [[ ${length} -eq 4 ]]; then
40 dd "if=${ROM}" bs=1 "skip=${location}" "count=${length}" 2>/dev
/null |
hexdump -v -e '1/4 "%08x\n"'
42 echo "Error: invalid value"
47 # Update a location in a binary
48 # Note that the passed in value must be formatted correctly:
49 # Each byte needs to be specified as "\\xXX" where X is a hex digit
55 # shellcheck disable=SC2059
56 if ! printf "$hexval" |
dd "of=${ROM}" bs=1 "seek=${location}" "count=${length}" conv
=notrunc status
=none
; then
57 echo "Error: Could not write to ${ROM}"
62 # Print the speed associated with the passed-in value
66 0 |
00) echo "0: 66.66Mhz" ;;
67 1 |
01) echo "1: 33.33MHz" ;;
68 2 |
02) echo "2: 22.22MHz" ;;
69 3 |
03) echo "3: 16.66MHz" ;;
70 4 |
04) echo "4: 100MHz" ;;
71 5 |
05) echo "5: 800KHz" ;;
72 ff
) echo "Error: Speed not set" ;;
73 *) echo "Error: Unknown speed (${speedval})" ;;
77 # Locate the SPI speed data and update it to the new speed
82 for speed_offset
in FAST_SPEED_NEW_F15_MOD_60_6F_OFFSET SPI_FASTSPEED_F17_MOD_00_2F_OFFSET SPI_FASTSPEED_F17_MOD_30_3F_OFFSET
; do
84 local speed_loc
=$
((location
+ speed_offset
))
85 speed_val
=$
(getval
"${speed_loc}" "1")
87 if [[ "${speed_val}" != "ff" ]]; then
88 printf "Found speed value of %s at %#06x\n" "$(showspeed "${speed_val}")" "${speed_loc}"
90 setval
"${speed_loc}" "1" "\\x0${NEW_SPEED}"
91 speed_val
=$
(getval
"${speed_loc}" "1")
92 printf "New speed value: %s\n" "$(showspeed "${speed_val}")"
96 if [[ ${updated_speed} -eq 0 ]]; then
97 echo "Error: Could not find speed value to update."
102 # Find the EFS location and update the speed
108 location
="$((0xffffff - (0x80000 << i) + 0x20000 + 1))"
109 val
="$(getval "${location}" 4 )"
110 if [[ "${val}" == "${EFS_SIG_DWORD}" ]]; then
111 printf "EFS found at %#06x\n" "${location}"
112 update_efs
"${location}"
117 echo "Error: EFS not found in ${ROM}."