The full sequence has not been repeated on a second, clean device. This describes how the working tablet was built, so expect to adapt it. You do this at your own risk.
You need a Linux computer, an ARM cross compiler, a USB keyboard, a USB drive and the Surface 2. All files are in the archive on the project page.
0. Prepare to roll back
Do this before changing anything.
- Create a bootable recovery USB drive.
- Back up the whole boot partition.
- Test every kernel and device tree with a one-time boot that restores the previous settings by itself. Only then make it permanent.
1. Unlock the boot
The Surface 2 only boots signed code until Secure Boot is bypassed. This step is not our work and is covered by the Open Surface RT guides:
Our tablet boots boot.efi from /boot/firmware, reads cmdline.txt, and takes the device tree from the dtb= parameter.
2. Base system
We used Raspbian 12 Bookworm armhf with GNOME 50. Other 32-bit ARM distributions should work, but the services in the archive assume this layout.
3. Build the kernel
sudo apt install gcc-arm-linux-gnueabihf bison flex libssl-dev bc
git clone https://github.com/Open-Surface-RT/grate-linux
cd grate-linux
git checkout ba70522fd65244fae81d48838119cd77e39d7140
patch -p1 < ../linux-on-surface-2-kit-1.0.0/kernel/kernel-avp5.diff
cp ../linux-on-surface-2-kit-1.0.0/kernel/config-avp5 .config
export ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
make olddefconfig
make -j"$(nproc)" zImage dtbs modulesThe config sets -surface-avp5 in the kernel name, and the Wi-Fi service checks for it.
4. Wi-Fi and Bluetooth
Get the firmware using the guide, then patch mwifiex and build the modules:
cd drivers/net/wireless/marvell/mwifiex
patch -p1 < .../kit/wifi/0001-wifi-mwifiex-sdio-fix-reset-deadlock-and-hard-reset-.patch
patch -p1 < .../kit/wifi/0002-wifi-mwifiex-support-SD8797-14.62-firmware-Windows-B.patch
cd -
make -j"$(nproc)" M=drivers/net/wireless/marvell/mwifiex modulesCompile camera/dts/surface-avp-safe-cameras-vi-mclk-bthsuart.dts with dtc. There UART-D uses nvidia,tegra30-hsuart.
On the tablet, place the files and enable the services. Distribution files stay unchanged: firmware and modules are mounted over them, so disabling the service undoes everything at once.
sudo install -d /opt/surface-bt /etc/surface-bt
sudo cp out/sd8797-fp62win7-btuart.bin /opt/surface-bt/fw-win7.bin
sudo cp mwifiex.ko /opt/surface-bt/mwifiex-win7.ko
sudo cp mwifiex_sdio.ko /opt/surface-bt/mwifiex_sdio-win7.ko
cd /opt/surface-bt
sudo sh -c 'sha256sum fw-win7.bin mwifiex-win7.ko mwifiex_sdio-win7.ko > SHA256SUMS'
sudo install -m 755 .../kit/bluetooth/overlay.sh /opt/surface-bt/
sudo install -m 644 .../kit/bluetooth/surface-bt-*.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable surface-bt-overlay.service surface-bt-attach.service
sudo touch /etc/surface-bt/enabledTurn Wi-Fi power saving off with tools/surface-wifi-ps.sh, as the firmware can hang with it on.
Check after a reboot:
dmesg | grep 'driver_version' # 14.62.17.p215
hciconfig -a # hci0 UP RUNNING
iw dev mlan0 link5. Cameras
make -C /path/to/kernel M=$PWD/modules/tegra-video modules
make -C /path/to/kernel M=$PWD/modules/sensors modules- Add
cma=384Mtocmdline.txt. Lower values starve the stream of memory. - Load
tegra-videowithmc_api=1. - Apply
camera/libcamera/*.patchto libcamera and installcamera/libcamera-configuration.yaml. - Module settings are in
camera/surface-camera.conf.
Check:
cam -l
cam -c 1 --capture=106. GPU, video and clocks
- Apply
gpu/patchesin order onto Mesa 22.2.4 with the Grate driver. modules/surface-v4l2andmodules/avpprovide hardware decoding and need the NVIDIA files.modules/dvfscontrols clocks.surface-emcneeds a table from your own device.
Start clock changes only after boot, with a guard that disables them after a failed start. Never lower VDD_CORE below 1100 mV at EMC 792 MHz.
Lessons from practice
- Do not read FUSE registers through
/dev/memwhile their clock is off: the bus hangs. - Do not run
perf record -aon this kernel: the tablet hangs. - Do not enable C7 cpuidle without a way to cut power: the tablet stops responding.
- Back up before every firmware or device tree change, and keep a working boot option at hand.
Rolling back Wi-Fi and Bluetooth
sudo rm /etc/surface-bt/enabled
sudo systemctl disable surface-bt-overlay.service surface-bt-attach.service
sudo reboot