Pi Zero W Flashrom and USB Gadget Debug

 

dd Raspbian image to microsd:

dd bs=4M if=2017-03-02-raspbian-jessie.img of=/dev/sdb status=progress

Boot from SD (Pi Zero will not start without it).
Connect to wireless.
Enable SSH on startup:

sudo systemctl enable ssh
sudo systemctl start ssh

Flashrom:

Log in over SSH and enable the SPI:

sudo vim /boot/config.txt

and uncomment:

dtparam=spi=on

Then reboot.

Install libraries necessary to compile ChromeOS Flashrom:

sudo apt install libpci-dev libfdt-dev libusb-dev libusb-1.0-0-dev

Clone ChromeOS Flashrom master:

git clone https://chromium.googlesource.com/chromiumos/third_party/flashrom

Build it:

make CONFIG_SATAMV=0 CONFIG_LINUX_I2C=yes NOWARNERROR=yes CONFIG_LINUX_SPI=yes

Test with:

flashrom/flashrom -V -r backup.rom -p linux_spi:dev=/dev/spidev1.0

USB Debug Gadget

The usual update routine:

sudo apt-get update -y
sudo apt-get upgrade -y

Update the kernel:

sudo rpi-update

Get rpi-source:

sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/bin/rpi-source

Make it executable:

sudo chmod +x /usr/bin/rpi-source

Tell the update mechanism that this is the latest version of the script:

/usr/bin/rpi-source -q --tag-update

Get the kernel files thingies:

rpi-source
cd linux

Enable g_dbgp in menuconfig as a module – Device Drivers -> USB Support -> USB Gadget Support -> EHCI Debug Device Gadget:

make menuconfig

Prepare the newly selected module(s) for actual building:

make modules_prepare

Apply updated 4.x EHCI debug patches:

tar -xJf debug_patches.tar.xz
patch -p0 < dbgp.patch
patch -p0 < gadget.patch
patch -p0 < u_serial.patch

Make the modules:

make M=drivers/usb/dwc2
make M=drivers/usb/gadget

Copy them to the relevant places:

sudo for f in $(find drivers/usb/gadget/ -name *.ko); do sudo cp $f /lib/modules/$(uname -r)/kernel/drivers/usb/gadget/ ; done
sudo for f in $(find drivers/usb/dwc2/ -name *.ko); do sudo cp $f /lib/modules/$(uname -r)/kernel/drivers/usb/dwc2/ ; done
sudo for f in $(find drivers/usb/gadget/function -name *.ko); do sudo cp $f /lib/modules/$(uname -r)/kernel/drivers/usb/gadget/function ; done

Run depmod so the modules work:

sudo depmod -a

Enable the dwc2 USB controller driver:

echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt

Reboot. Load the module:

sudo modprobe g_dbgp

Configure the virtual serial device to strip out CR/LF’s to sanitise output:

stty -icrnl -inlcr -F /dev/ttyGS0

Cat that serial device good:

cat /dev/ttyGS0

Switch on the Intel based Chromebook, or other device with coreboot compatible USB debug.

Done. With thanks to Kyösti Mälkki for actually getting the damned thing working. :)

Sources in no particular order:

https://www.coreboot.org/EHCI_Gadget_Debug

http://raspberrypi.stackexchange.com/questions/39845/how-compile-a-loadable-kernel-module-without-recompiling-kernel

https://github.com/raspberrypi/linux/issues/1907

https://gist.github.com/gbaman/50b6cca61dd1c3f88f41

 

 

Leave a comment