Skip to content

Commit

Permalink
recipes-go: 3mdeb-rtectrl: flash.sh: add
Browse files Browse the repository at this point in the history
Add flash.sh script from 3mdeb/RteCtrl#22.
For more inf. check #80.

Signed-off-by: Daniil Klimuk <[email protected]>
  • Loading branch information
DaniilKl committed Nov 7, 2024
1 parent abdb99e commit 52c9645
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 0 deletions.
148 changes: 148 additions & 0 deletions recipes-go/3mdeb-rtectrl/3mdeb-rtectrl/flash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/bin/sh

errorExit() {
errorMessage="$1"
echo "$errorMessage"
exit 1
}

errorCheck() {
errorCode=$?
errorMessage="$1"
[ "$errorCode" -ne 0 ] && errorExit "$errorMessage : ($errorCode)"
}

usage() {
echo "${0} command [FILE]"
echo "Available commands:"
echo " - probe - probe flash"
echo " - read FILE - read flash to FILE"
echo " - write FILE - write flash from FILE"
echo "For example:"
echo "${0} probe"
echo "${0} read flash.rom"
echo "${0} write flash.rom"
exit 0
}

SPI_DEV="/dev/spidev1.0"
SPI_SPEED="16000"
FLASHROM_PROGRAMMER="linux_spi:dev=$SPI_DEV,spispeed=$SPI_SPEED"

CHIP_THINKPAD_SPI1="MX25L6406E/MX25L6408E"
CHIP_THINKPAD_SPI2="MX25L3206E/MX25L3208E"
CHIP_PROTECTLI_FW6="MX25L6436E/MX25L6445E/MX25L6465E"

# FLASHROM_CHIP="-c $CHIP_PROTECTLI_FW6"

WP_RANGE="0,0x00800000"

[ $# -eq 0 ] && usage

spiON() {
echo "set SPI Vcc to 3.3V"
# 0 - 1.8V , 1 - 3.3V
echo 1 > /sys/class/gpio/gpio517/value
sleep 1
echo "SPI lines ON"
echo 1 > /sys/class/gpio/gpio516/value
sleep 1
echo "SPI Vcc ON"
echo 1 > /sys/class/gpio/gpio518/value
sleep 2
}

spiOFF() {
echo "SPI Vcc OFF"
echo 0 > /sys/class/gpio/gpio518/value
echo "SPI lines OFF"
echo 0 > /sys/class/gpio/gpio516/value
echo 0 > /sys/class/gpio/gpio517/value
}

CMD="$1"
FILE="$2"

case "$CMD" in
"probe")
spiON
echo "Probing ..."
flashrom -p "$FLASHROM_PROGRAMMER" $FLASHROM_CHIP
sleep 1
spiOFF
;;
"read")
[ -z "$FILE" ] && errorExit "FILE not given"
spiON
echo "Reading ..."
flashrom -p "$FLASHROM_PROGRAMMER" -r "$FILE" $FLASHROM_CHIP -V
sleep 1
spiOFF
;;
"write")
[ -z "$FILE" ] && errorExit "FILE not given"
spiON
echo "Writing ..."
flashrom -p "$FLASHROM_PROGRAMMER" -w "$FILE" $FLASHROM_CHIP
sleep 1
spiOFF
;;
"wp-list")
spiON
echo "Checking WP list ..."
flashrom -p "$FLASHROM_PROGRAMMER" --wp-list $FLASHROM_CHIP
sleep 1
spiOFF
;;
"wp-status")
spiON
echo "Checking WP status ..."
flashrom -p "$FLASHROM_PROGRAMMER" --wp-status $FLASHROM_CHIP
sleep 1
spiOFF
;;
"wp-enable")
spiON
echo "Setting WP region ..."
flashrom -p "$FLASHROM_PROGRAMMER" --wp-range="$WP_RANGE" $FLASHROM_CHIP
sleep 1
echo "Enabling WP region ..."
flashrom -p "$FLASHROM_PROGRAMMER" --wp-enable $FLASHROM_CHIP
sleep 1
spiOFF
;;
"wp-disable")
spiON
echo "Disabling WP protection ..."
flashrom -p "$FLASHROM_PROGRAMMER" --wp-disable $FLASHROM_CHIP
sleep 1
echo "Clearing WP region ..."
flashrom -p "$FLASHROM_PROGRAMMER" --wp-range=0,0 $FLASHROM_CHIP
sleep 1
spiOFF
;;
"erase")
spiON
echo "Erasing chip ..."
flashrom -p "$FLASHROM_PROGRAMMER" -E $FLASHROM_CHIP
sleep 1
spiOFF
;;
"wp-high")
echo "Setting WP pin HIGH ..."
echo "out" > /sys/class/gpio/gpio514/direction
# deassert WP pin to disable hardware protection of status registers
echo "1" > /sys/class/gpio/gpio514/value
;;
"wp-low")
echo "Setting WP pin LOW ..."
echo "out" > /sys/class/gpio/gpio514/direction
# assert WP pin to enable hardware protection of status registers
echo "0" > /sys/class/gpio/gpio514/value
;;
*)
echo "Command \"$CMD\" is not supported"
usage
;;
esac

5 changes: 5 additions & 0 deletions recipes-go/3mdeb-rtectrl/3mdeb-rtectrl_git.bbappend
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
SRC_URI:append = " \
file://RteCtrl.cfg \
file://RteCtrl.service \
file://flash.sh \
"

FILES:${PN} += " \
${sysconfdir}/RteCtrl.cfg \
${systemd_unitdir}/system/RteCtrl.service \
${sbindir}/flash.sh \
"

do_install:append() {
Expand All @@ -17,6 +19,9 @@ do_install:append() {

install -d ${D}${systemd_unitdir}/system/
install -m 0644 ${WORKDIR}/RteCtrl.service ${D}${systemd_unitdir}/system/

install -d ${D}${sbindir}
install -m 0755 ${WORKDIR}/flash.sh ${D}${sbindir}/
}

SYSTEMD_PACKAGES = "${PN}"
Expand Down

0 comments on commit 52c9645

Please sign in to comment.