commit b7bad3828545ead251264f607ecb68b41127b875
parent 96a6bbb544eba4a72e244896ad359812644e052e
Author: smeeb <smeeb@web>
Date: Thu, 19 Nov 2026 13:30:34 +0100
Diffstat:
| M | unbrick01.mdwn | | | 624 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 624 insertions(+), 0 deletions(-)
diff --git a/unbrick01.mdwn b/unbrick01.mdwn
@@ -1,3 +1,627 @@
+# unbrick01 on the Samsung Galaxy SIII
+
+In this how-to guide we replace Android with Nura on a Samsung Galaxy SIII. After this we compile Pure Data (Pd) on it and run the `unbrick01` patch, which turn touches on the screen and presses on the buttons into sound. We do this in the following steps
+
+### Installation steps
+
+1. Build Nura system image for the SIII with `pmbootstrap`
+2. Flash that image to the phone over USB with `heimdall`.
+3. Log in to the phone from the computer over a usb cable with `ssh`, and share the computer's internet with the phone.
+4. install `pd` and the `unbrick01` scripts on the phone.
+
+### Prerequisites
+
+1. A Samsung Galaxy SIII (`GT-i9300` or `GT-i9305`)
+2. Computer with Debian 13 as the operating system
+3. Micro usb cable to connect the phone to the computer
+
+## Chapter 1: set up and installing tools
+
+### 1.1: giving your user `sudo` rights
+
+Many commands in this tutorial need root rights. With `sudo` you can run a single command as root by putting `sudo` in front of it. Write the following commands one by one in your computer its terminal application. You will need to do the same for all the other commands in this how-to guide.
+
+```bash
+su
+sudo visudo
+```
+
+Add this line at the end of the file:
+
+```
+user ALL=(ALL:ALL) ALL
+```
+
+This means: the user `user` may run any command after typing their password. If your username isn't `user`, put your own username there. Save and close the editor (in nano: `Ctrl+O`, `Enter`, `Ctrl+X`), then type `exit` to leave the root shell.
+### 1.2: installing packages
+
+```bash
+sudo apt install git heimdall-flash puredata pipewire-jack build-essential zlib1g-dev iptables fonts-terminus
+```
+
+#### What each package is for
+
+| Package | Why we need it |
+| ----------------- | -------------------------------------------------------------------------------- |
+| `git` | can download source code from online repositories |
+| `heimdall-flash` | writes (flashes) software to Samsung phones over usb |
+| `puredata` | Pd on the computer to test the sound and work on patches |
+| `pipewire-jack` | Lets programs that use JACK, like Pd, play sound through PipeWire |
+| `build-essential` | Compiler and `make` needed to build `simg2img` in chapter 1.3 |
+| `zlib1g-dev` | compression library that `simg2img` needs to compile |
+| `iptables` | routing tool we use in chapter 4 to share the computer's internet with the phone |
+### 1.3: `simg2img` and `img2simg`
+
+Android phones are usually flashed with a sparse image. `android-simg2img` has two small tools: `img2simg` turns a image into a sparse one and `simg2img` does the opposite. We need `img2simg` in chapter 3. Write the following commands one by one on in your computer its terminal application.
+
+```bash
+git clone https://github.com/anestisb/android-simg2img/
+cd android-simg2img
+make
+sudo cp img2simg /usr/local/bin
+```
+
+- `git clone` downloads the source code, and `cd` moves us into a folder
+- `make` compiles the tools
+- `sudo cp img2simg /usr/local/bin` copies the tool into `/usr/local/bin` so we can run `img2simg` from anywhere
+
+### 1.4: `pmbootstrap`
+
+`pmbootstrap` is Nura's tool for building an image for a specific phone. It downloads the right packages and puts together a complete linux system for the phone
+
+```bash
+git clone https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git --depth 1
+cd pmbootstrap
+mkdir -p ~/.local/bin
+sudo ln -s "$PWD/pmbootstrap.py" /usr/local/bin/pmbootstrap
+pmbootstrap --version ## should print 3.12.1
+```
+
+- `--depth 1` downloads only the latest version instead of the whole project its history
+- `ln -s` makes a shortcut (symlink) in the folder so you can type `pmbootstrap` from anywhere
+- `pmbootstrap --version` checks if it works and shows you the current version
+
+## Chapter 2: building a Nura image
+
+### 2.1: configure the build
+
+The command `pmbootstrap init` asks a series of questions about the phone and the system you want
+
+```bash
+pmbootstrap init
+```
+
+The answers we use and why:
+
+| Question | Answer | Why |
+| -------------------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------- |
+| work path | *enter* (default) | the folder where pmbootstrap builds everything |
+| pmaports path | *enter* (default) | the folder for the packages |
+| channel | `v25.12` | the previos stable release. `v26.06` doesnt seem to work and `edge` changes frequently which can cause things to break |
+| vendor | `samsung` | |
+| device codename | `m0` | the codename nura uses for the Galaxy SIII |
+| username | *Enter* (`user`) | your login name on the phone |
+| audio backend | *Enter* (default) | we drive the sound card directly with JACK later, so this doesn't matter much |
+| WiFi backend | *Enter* (default) | we use the usb cable for the network |
+| usb-moded profile | *Enter* (`developer`) | always turns on networking over usb which we need to log in to the phone |
+| user interface | `none` | no graphical interface |
+| service manager | `openrc` | a simple service manager |
+| change additional options? | *Enter* (`n`) | the defaults are fine |
+| extra packages | `openssh` | an `ssh` server so we can log in to the phone over usb. you can add more if you want like `vim` or `nano` |
+| use host timezone? | *Enter* (`y`) | the phone gets the same timezone as your computer |
+| locale | *Enter* (`en_US`) | language settings |
+| device hostname | `unbrick01` | the phones name, which shows in the prompt when you're logged in |
+| build outdated packages? | *Enter* (`y`) | |
+This is what the output of a complete `pmbootstrap init` looks like:
+
+```bash
+user@macdebian:~/pmbootstrap$ pmbootstrap init
+[16:15:27] Location of the 'work' path. Multiple chroots (native, device arch, device rootfs) will be created in there.
+[16:15:27] Work path [/home/user/.local/var/pmbootstrap]:
+[16:16:21] Location of the 'pmaports' path, containing package definitions.
+[16:16:21] pmaports path [/home/user/.local/var/pmbootstrap/cache_git/pmaports]:
+[16:16:23] Setting up the native chroot and cloning the package build recipes (pmaports)...
+[16:16:23] Clone git repository: https://gitlab.postmarketos.org/postmarketOS/pmaports.git
+Cloning into '/home/user/.local/var/pmbootstrap/cache_git/pmaports'...
+warning: redirecting to https://gitlab.nura.eco/postmarketOS/pmaports.git/
+[16:21:15] Choose the postmarketOS release channel.
+[16:21:15] Available (14):
+[16:21:15] * edge: Rolling release / Most devices / Occasional breakage: https://nura.eco/edge
+[16:21:15] * v26.06: Latest release / Recommended for best stability
+[16:21:15] * v25.12: Old release (unsupported)
+[16:21:15] Channel [edge]: v25.12
+[16:25:23] Currently checked out branch 'main' of pmaports.git is on channel 'edge'.
+[16:25:23] Switching to branch 'v25.12' on channel 'v25.12'...
+[16:25:23] Branch v25.12 doesn't exist, attempting to fetch it
+warning: redirecting to https://gitlab.nura.eco/postmarketOS/pmaports.git/
+From https://gitlab.postmarketos.org/postmarketOS/pmaports
+ * [new branch] v25.12 -> v25.12
+Switched to branch 'v25.12'
+[16:25:26] Choose your target device vendor (either an existing one, or a new one for porting).
+[16:25:26] Available vendors (75): acer, alcatel, amediatech, amlogic, apple, ark, arrow, asus, ayaneo, ayn, bananapi, barnesnoble, beelink, blackberry, bq, cubietech, dell, epson, fairphone, fxtec, generic, goclever, google, hp, htc, huawei, inet, jolla, khadas, kobo, lark, lenovo, lg, librecomputer, linksys, lynx, microsoft, mnt, motorola, nokia, nothing, nvidia, odroid, oneplus, pine64, pocketbook, postmarketos, powkiddy, purism, qcom, qemu, qualcomm, radxa, realme, rockchip, samsung, shift, sipeed, solidrun, sony, sourceparts, starway, surftab, thundercomm, tolino, trekstor, valve, vivo, volla, wd, wileyfox, xiaomi, xunlong, zhihe, zte
+[16:25:26] Vendor [qemu]: samsung
+[16:25:35] Devices are categorised as follows, from best to worst:
+* Main: ports where mostly everything works.
+* Community: often mostly usable, but may lack important functionality.
+* Testing: anything from "just boots in some sense" to almost fully functioning ports.
+* Downstream: ports that use a downstream kernel — very limited functionality. Not recommended.
+
+Available devices by codename (57): a3 (testing), a5 (testing), a6lte (testing), a6plte (testing), a7 (testing), chagallwifi (testing), codina (testing), codina-tmo (testing), coreprimevelte (community), e7 (testing), espresso10 (community), espresso7 (community), expressatt (testing), exynos7 (testing), fortuna (testing), fortunaltezt (testing), gavini (testing), golden (testing), grandmax (testing), grandpplte (testing), gt510 (testing), gt58 (testing), gtelwifiue (testing), heatqlte (testing), hlte (testing), i9100 (testing), i927 (testing), j3ltetw (testing), j5 (testing), j5x (testing), j5y17lte (testing), janice (testing), klimtlte (testing), klte (testing), kona (testing), kyle (testing), loganrelte (testing), lt01 (testing), lt03lte (testing), m0 (community), m3 (testing), matisselte (testing), matisseve (testing), milletwifi (testing), n1awifi (testing), n2awifi (testing), on7 (testing), p4note (testing), p4wifi (testing), rossa (testing), serranove (testing), skomer (testing), starqltechn (community), t03g (testing), t0lte (testing), v1awifi (testing), w767 (testing)
+[16:25:35] Device codename: m0
+[16:25:44] Username [user]:
+[16:25:45] Available providers for postmarketos-base-ui-audio-backend (2):
+[16:25:45] * pulseaudio: Use pulseaudio as the audio backend. (default)
+[16:25:45] * pipewire: Use pipewire as the audio backend. (but may not work with all devices)
+[16:25:45] Provider [default]:
+[16:26:05] Available providers for postmarketos-base-ui-wifi (2):
+[16:26:05] * wpa_supplicant: Use wpa_supplicant as the WiFi backend. (default)
+[16:26:05] * iwd: Use iwd as the WiFi backend (but may not work with all devices)
+[16:26:05] Provider [default]:
+[16:26:09] Available providers for postmarketos-usb-moded-default-profile (2):
+[16:26:09] * developer: Make 'developer mode' the default usb-moded profile (always enables usb networking) (default)
+[16:26:09] * charging: Make 'charging mode' the default usb-moded profile (usb networking must be manually enabled)
+[16:26:09] Provider [default]:
+[16:26:21] Available user interfaces (23):
+[16:26:21] * none: Bare minimum OS image for testing and manual customization. The "console" UI should be selected if a graphical UI is not desired.
+[16:26:21] * buffyboard: Plain framebuffer console with modern touchscreen keyboard support
+[16:26:21] * cage: (Wayland) Kiosk WM
+[16:26:21] * console: Console environment, with no graphical/touch UI
+[16:26:21] * fbkeyboard: Plain framebuffer console with touchscreen keyboard support
+[16:26:21] * gnome: (Wayland) Gnome Shell
+[16:26:21] * gnome-mobile: (Wayland) Gnome Shell patched to adapt better to phones (Experimental)
+[16:26:21] * i3wm: (X11) Tiling WM (keyboard required)
+[16:26:21] * kodi: (GBM) 10-foot UI useful on TV's
+[16:26:21] * lxqt: (X11) Lightweight Qt Desktop Environment (stylus recommended)
+[16:26:21] * mate: (X11) MATE Desktop Environment, fork of GNOME2 (stylus recommended)
+[16:26:21] * moonlight: (Wayland) Open Source PC client for NVIDIA GameStream, as used by the NVIDIA Shield
+[16:26:21] * openbox: (X11) A highly configurable and lightweight X11 window manager (keyboard required)
+[16:26:21] * os-installer: UI for installing postmarketOS
+[16:26:21] * phosh: (Wayland) Mobile UI using GNOME components and apps
+[16:26:21] * plasma-desktop: (Wayland) KDE Desktop Environment (works well with tablets)
+[16:26:21] * plasma-mobile: (Wayland) Mobile variant of KDE Plasma
+[16:26:21] * retroarch: RetroArch in KMS mode
+[16:26:21] * sway: (Wayland) Tiling WM, drop-in replacement for i3wm
+[16:26:21] * sxmo-de-dwm: Simple Mobile: Mobile environment based on SXMO and running on dwm
+[16:26:21] * sxmo-de-i3: Simple Mobile: Mobile environment based on SXMO and running on i3
+[16:26:21] * sxmo-de-sway: Simple Mobile: Mobile environment based on SXMO and running on sway
+[16:26:21] * weston: (Wayland) Reference compositor (demo, not a phone interface)
+[16:26:21] * xfce4: (X11) Lightweight desktop (stylus recommended)
+[16:26:21] User interface [console]: none
+[16:26:53] Based on your UI selection, 'default' will result in choosing systemd.
+[16:26:53] Which service manager should be used? (default/openrc/systemd) [default]: openrc
+[16:27:16] Additional options: extra free space: 0 MB, boot partition size: 512 MB, parallel jobs: 4, ccache per arch: 5G, sudo timer: False, mirror: http://mirror.postmarketos.org/postmarketos/
+[16:27:16] Change them? (y/n) [n]:
+[16:27:32] Additional packages that will be installed to rootfs. Specify them in a comma separated list (e.g.: vim,file) or "none"
+[16:27:32] Extra packages [none]: openssh
+[16:27:41] Your host timezone: Europe/Amsterdam
+[16:27:41] Use this timezone instead of GMT? (y/n) [y]:
+[16:27:44] Choose your preferred locale, like e.g. en_US. Only UTF-8 is supported, it gets appended automatically. Use tab-completion if needed.
+[16:27:44] Locale [en_US]:
+[16:27:45] Device hostname (short form, e.g. 'foo') [samsung-m0]: unbrick01
+[16:28:12] NOTE: No SSH public keys found to copy to the device.
+[16:28:12] See https://postmarketos.org/ssh-key-glob for more information.
+[16:28:12] After pmaports are changed, the binary packages may be outdated. If you want to install postmarketOS without changes, reply 'n' for a faster installation.
+[16:28:12] Build outdated packages during 'pmbootstrap install'? (y/n) [y]:
+[16:28:16] DONE!
+```
+
+### 2.2: build the image
+
+```bash
+pmbootstrap install
+```
+
+When asked choose `147147`as the password for the user `user`. You need this password to log in to the phone and to use `sudo` on it. We use the same password on every phone so anyone in the workshop can log in to any phone.
+
+At the end `pmbootstrap` suggests flashing with `pmbootstrap flasher`. We don't do this. Instead we use the alternative it mentions, `pmbootstrap export` and flash with `heimdall` in chapter 3.
+
+```bash
+user@macdebian:~/pmbootstrap$ pmbootstrap install
+Choose a password for the user 'user':
+Confirm password for 'user':
+[16:31:42] *** (1/4) PREPARE NATIVE CHROOT ***
+[16:31:43] Update package index for x86_64 (3 file(s))
+[16:31:48] Download http://cdn.alpinelinux.org/v3.24/main/x86_64/apk-tools-static-3.0.9-r0.apk
+[16:31:50] (native) Creating chroot
+[16:31:58] (native) install cryptsetup util-linux parted
+[16:32:01] *** (2/4) CREATE DEVICE ROOTFS ("samsung-m0") ***
+[16:32:03] (native) install qemu-arm
+[16:32:05] Register qemu binfmt (arm)
+[16:32:05] (rootfs_samsung-m0) Creating chroot
+[16:32:05] Update package index for armv7 (3 file(s))
+[16:32:16] (rootfs_samsung-m0) install postmarketos-base device-samsung-m0 device-samsung-m0-nonfree-firmware openssh postmarketos-base-nofde sudo-rs
+[16:33:29] (rootfs_samsung-m0) install postmarketos-mkinitfs
+[16:33:30] (rootfs_samsung-m0) mkinitfs
+[16:33:42] *** SET LOGIN PASSWORD FOR: 'user' ***
+[16:33:46] *** (3/4) PREPARE INSTALL BLOCKDEVICE ***
+[16:33:47] (native) create samsung-m0.img (709M)
+[16:33:47] (native) mount /dev/install (samsung-m0.img)
+[16:33:47] (native) partition /dev/install (boot: 512M)
+[16:33:48] Mounting partitions of /dev/loop0 inside the chroot
+[16:33:48] (native) install e2fsprogs
+[16:33:49] (native) format /dev/installp2 (pmOS_root, ext4)
+[16:33:49] (native) mount /dev/installp2 to /mnt/install
+[16:33:50] (native) install e2fsprogs
+[16:33:50] (native) format /dev/installp1 (pmOS_boot, ext2)
+[16:33:51] (native) create /etc/fstab
+[16:33:51] (rootfs_samsung-m0) mkinitfs
+[16:34:05] *** (4/4) FILL INSTALL BLOCKDEVICE ***
+[16:34:05] (native) copy rootfs_samsung-m0 to /mnt/install/
+[16:34:12] (native) make sparse rootfs
+[16:34:12] (native) install android-tools-img2simg
+[16:34:36]
+[16:34:36] *** FLASHING INFORMATION ***
+[16:34:36] Run the following to flash your installation to the target device:
+[16:34:36] * pmbootstrap flasher flash_rootfs
+[16:34:36] Flashes the generated rootfs image to your device:
+[16:34:36] /home/user/.local/var/pmbootstrap/chroot_native/home/pmos/rootfs/samsung-m0.img
+[16:34:36] (NOTE: This file has a partition table, which contains /boot and / subpartitions. That way we don't need to change the partition layout on your device.)
+[16:34:36] * pmbootstrap flasher flash_kernel
+[16:34:36] Flashes the kernel + initramfs to your device:
+[16:34:36] /home/user/.local/var/pmbootstrap/chroot_rootfs_samsung-m0/boot
+[16:34:36] * If the above steps do not work, you can also create symlinks to the generated files with 'pmbootstrap export' and flash outside of pmbootstrap.
+[16:34:36]
+[16:34:36] *** SSH DAEMON INFORMATION ***
+[16:34:36] SSH daemon is enabled (disable with --no-sshd).
+[16:34:36] Login as 'user' with the password given during installation.
+[16:34:36]
+[16:34:36] *** FIREWALL INFORMATION ***
+[16:34:36] Firewall is enabled, but may not work (couldn't determine if kernel supports nftables).
+[16:34:36] For more information: https://postmarketos.org/firewall
+[16:34:36]
+[16:34:36] NOTE: chroot is still active (use 'pmbootstrap shutdown' as necessary)
+[16:34:36] DONE!
+```
+
+## Chapter 3: flashing the phone
+
+### 3.1: download mode
+
+Download Mode is a mode of the Samsung bootloader where the phone waits to receive new software over usb.
+
+Hold the `Volume down` + `Home` + `Power` keys while connecting the device to your computer with a usb cable. A warning screen appears. Press `Volume up` to enter Download Mode.
+
+If the phone starts normally, unplug it, take the battery out and put it back and try again. hold the keys first, then plug in the cable. This process can take a few tries!
+### 3.2: export Nura image
+
+```bash
+pmbootstrap export
+```
+
+This command export images and creates links the the images in the `/tmp/postmarketOS-export` folder. There are two images we need: the system image `samsung-m0.img` and the boot image `boot.img`.
+
+### 3.3: convert to a sparse image
+
+```bash
+img2simg /tmp/postmarketOS-export/samsung-m0.img nura-sparse.img
+```
+
+`img2simg` takes the image from the export folder and writes a sparse version named `nura-sparse.img` in the folder you are currently in
+
+### 3.4: flash the system to the USERDATA partition
+
+Make sure your Samsung SIII is still in Download Mode then flash the new `nura-sparse.img` with `heimdall` into the user data partition
+
+```bash
+heimdall flash --USERDATA nura-sparse.img
+```
+
+The phone's internal storage is divided into partitions (sections). `USERDATA` is where Android keeps your apps and files. That is where we are flashing Nura. You should get an output similar as this
+
+```bash
+Heimdall v2.1.0
+
+Copyright (c) 2010-2017 Benjamin Dobell, Glass Echidna https://glassechidna.com.au
+Copyright (c) 2021-2024 Henrik Grimler
+This software is provided free of charge. Copying and redistribution is encouraged.
+
+Initialising connection...
+Detecting device...
+Claiming interface...
+Initialising protocol...
+Resetting device...
+Protocol initialisation successful.
+
+Beginning session...
+
+Some devices may take up to 2 minutes to respond.
+Please be patient!
+
+Session begun.
+
+Downloading device's PIT file...
+PIT file download successful.
+
+Uploading USERDATA
+100%
+USERDATA upload successful
+
+Ending session...
+Rebooting device...
+Releasing device interface...
+```
+
+Flashing takes around 5 minutes. Be patient and don't unplug the usb cable while it's uploading, even when it looks like it's stuck!
+
+### 3.5: flash the kernel to the BOOT partition
+
+When uploading the system is done, the phone reboots. We need it in Download Mode again for this step, so switch the phone off completely. Take out the battery and upload the cable. Then put the battery back and enter Download Mode again
+
+Flash the `BOOT` partition
+
+```bash
+heimdall flash --BOOT /tmp/postmarketOS-export/boot.img
+```
+
+The `BOOT` partition holds what starts the phone. You should see something like the output below
+
+```bash
+Heimdall v2.1.0
+
+Copyright (c) 2010-2017 Benjamin Dobell, Glass Echidna https://glassechidna.com.au
+Copyright (c) 2021-2024 Henrik Grimler
+This software is provided free of charge. Copying and redistribution is encouraged.
+
+Initialising connection...
+Detecting device...
+ Manufacturer: "SAMSUNG"
+ Product: "Gadget Serial"
+
+ length: 18
+ device class: 2
+ S/N: 0
+ VID:PID: 04E8:685D
+ bcdDevice: 021B
+ iMan:iProd:iSer: 1:2:0
+ nb confs: 1
+
+interface[0].altsetting[0]: num endpoints = 1
+ Class.SubClass.Protocol: 02.02.01
+ endpoint[0].address: 83
+ max packet size: 0010
+ polling interval: 09
+
+interface[1].altsetting[0]: num endpoints = 2
+ Class.SubClass.Protocol: 0A.00.00
+ endpoint[0].address: 81
+ max packet size: 0200
+ polling interval: 00
+ endpoint[1].address: 02
+ max packet size: 0200
+ polling interval: 00
+Claiming interface...
+Initialising protocol...
+Resetting device...
+Protocol initialisation successful.
+
+Beginning session...
+
+Some devices may take up to 2 minutes to respond.
+Please be patient!
+
+Session begun.
+
+Downloading device's PIT file...
+WARNING: Empty bulk transfer after receiving packet failed. Continuing anyway...
+PIT file download successful.
+
+Uploading BOOT
+100%
+BOOT upload successful
+
+Ending session...
+Rebooting device...
+Releasing device interface...
+```
+
+After this, your Samsung SIII finally reboots into Nura!
+
+## Chapter 4: connecting to the phone
+
+### 4.1: `ssh` into the phone over usb
+
+Keep the phone connected to the computer with the USB cable. Nura sets up a small network over the cable so the computer and the phone can talk to each other as if they were on the same network. We will use it to log in to the phone with `ssh`
+
+To see the new network connection:
+
+```bash
+ip a
+```
+
+Look for a network interface with a random name like `enx72c89eafced9`. Its `inet` line should say `172.16.42.2`. That's your computer's address on the usb network. The phone always has the address `172.16.42.1` so you log in to the phone with:
+
+```
+ssh user@172.16.42.1
+```
+
+Type the password (we set `147147`). The first time, `ssh` asks whether you trust this device's key: type `yes` and press the `Enter` key
+
+You should now see a new shell prompt: `unbrick01:~$`. This means you are now working on the phone!
+
+Next we install all the software and scripts that `unbrick01` needs. But first the phone needs internet.
+
+### 4.2: sharing internet with the phone
+
+The phone's only connection is the usb cable to your computer. So we turn the computer into a router. The phone sends its internet traffic to the computer and the computer passes it on to its internet connection
+#### on the computer
+
+Find the name of your WiFi interface with `ip a`. In my case it's `wlp2s0b1`. WiFi interfaces usually start with `wl`. Use your own interface name in the second command. both settings are lost when the computer reboots
+
+```bash
+sudo sysctl net.ipv4.ip_forward=1
+sudo iptables -t nat -A POSTROUTING -o wlp2s0b1 -j MASQUERADE
+```
+
+- `net.ipv4.ip_forward=1` allows the computer to share network traffic from one interface to another
+- The `iptables` rule makes the phone's traffic look like it comes from the computer
+
+#### on the phone
+
+```bash
+sudo ip route add default via 172.16.42.2 # resets on boot
+echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf # or 9.9.9.9 (eduroam doesnt like 9.9.9.9)
+```
+
+- `ip route add default via 172.16.42.2` tells the phone to send all traffic to the computer
+- The `nameserver` line sets the DNS server. `eduroam` blocks `9.9.9.9` so we use `8.8.8.8`
+
+Now the phone should share the computer its interenet connection. `ping` a website to check that your message arrives and you get a response. Press `ctrl+c` to stop.
+
+```bash
+ping nura.eco
+```
+
+### 4.3: enable `localhost` on the phone
+
+software on the phone also need to reach each other through the phone's own internal network address, `127.0.0.1` (`localhost`). For example `touch2pd.py` is sending touch and button events to Pd. In our image this internal network isn't switched on automatically.
+
+```bash
+printf 'auto lo\niface lo inet loopback\n\n' | sudo tee -a /etc/network/interfaces
+```
+
+Then start the networking service, and enable it at boot (put `sudo` in front if you get a permission error):
+
+```bash
+rc-service networking start
+rc-update add networking boot
+```
+
+`ping` `127.0.0.1` to test it. Press `ctrl+c` to stop.
+
+```bash
+ping 127.0.0.1
+```
+
+### Chapter 5: installing software on the phone
+
+Now we have internet we can install some software. Every command in this chapter runs on the phone.
+
+### 5.1: install packages
+
+```bash
+sudo apk add git tmux python3 py3-evdev alsa-utils jack chrony build-base autoconf automake libtool alsa-lib-dev jack-dev
+```
+
+| Package | Why we need it |
+| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
+| `git` | downloads Pd source code and the `unbrick01` scripts |
+| `tmux` | runs several programs side by side in one `ssh` session, and keeps them running if the connection drops |
+| `python3`, `py3-evdev` | running Python scripts. `evdev` lets Python read touchscreen and button events |
+| `alsa-utils` | sound tools: `alsaucm`, `amixer` and `speaker-test` |
+| `jack` | the JACK audio server (`jackd`), which gives Pd access to the sound card |
+| `chrony` | keeps the phone's clock in sync |
+| `build-base`, `autoconf`, `automake`, `libtool` | compiler and build tools to compile Pd |
+| `alsa-lib-dev`, `jack-dev` | Let Pd be compiled with ALSA and JACK support |
+### 5.2: sync the clock
+
+Start the `chronyd` service to sync the time
+
+```bash
+sudo rc-service chronyd start && sudo rc-update add chronyd boot
+```
+
+The phone's clock is usually wrong. Secure `https` connections check the dates on certificates so with a wrong clock `git clone` fails. `chronyd` sets the clock from the internet and `rc-update add chronyd boot` makes it do that at every startup of the phone.
+
+### 5.3: compile Pd
+
+We build Pd from the source code on the phone because there is no package for it available on `apk`
+
+```bash
+git clone https://github.com/pure-data/pure-data
+cd pure-data
+./autogen.sh
+LIBS="`pkg-config -libs jack alsa`" ./configure --enable-alsa --enable-jack
+make -j$(nproc)
+sudo make install
+```
+
+- `./autogen.sh` prepares the build scripts
+- `./configure --enable-alsa --enable-jack` enables ALSA and JACK support
+- `make -j$(nproc)` compiles using all processor cores
+- `sudo make install` installs `pd` so you can start it from anywhere
+
+### Chapter 6: setting up sound
+
+The Galaxy SIII sound chip has many switches that decide where sound goes. Out of the bot they are not set up for the 3.5mm headphone jack so we need to set them manually
+
+```bash
+alsaucm -c 0 set _verb HiFi set _enadev Speaker
+amixer -c 0 cset numid=70 off # mute speaker
+amixer -c 0 cset numid=142 on # enable headphone jack
+amixer -c 0 cset numid=75 60 # increase volume
+```
+
+Plug in the headphones (watch out for your ears) and test with
+
+```bash
+speaker-test -D plughw:0,0 -c 2 -t sine -f 440
+```
+
+This plays a 440 Hz sine tone on the phone's sound card `plughw:0,0`. Press `ctrl+c` to stop. These settings are lost on a reboot of the phone. We will set this up automatically later in chapter 7.6.
+### Chapter 7: running `unbrick01`
+
+### 7.1: getting the scripts
+
+```bash
+git clone https://git.xpub.nl/ugrnm/unbrick01.git
+```
+
+Three programs work together:
+
+1. `jackd`: the audio server
+2. `touch2pd.py`: reads the touchscreen and buttons and sends the data to Pd
+3. `pd`: runs the patch that turns those events into sound
+
+The easiest way to run them side by side is with a program called `tmux`. Type `tmux` to start it, `ctrl+b` then `c` to open a new window and `ctrl+b` and then `n` to switch to the next window. You can also open three separate `ssh` connections from the computer.
+
+### 7.2: starting JACK
+
+Run `jackd` before starting `pd`, because Pd sends its sound to JACK.
+
+```bash
+JACK_NO_AUDIO_RESERVATION=1 /usr/bin/jackd -d alsa -S -p 128
+```
+
+- `-d alsa` uses ALSA to talk to the sound card
+- `-S` uses 16-bit samples instead of 32-bit.
+- `-p 128` processes sound in parts of 128 samples. Small parts mean low latency
+
+### 7.3: starting the touch script
+
+In a new `tmux` window or separate `ssh` session, run this Python script. It sends button presses and touchscreen data to Pd
+
+```bash
+cd ~/unbrick01/pd/startup
+python3 touch2pd.py
+```
+
+### 7.4: starting the Pd patch
+
+In another new `tmux` window or seperate `ssh` session run the Pd patch.
+
+```bash
+cd ~/unbrick01/pd/unstable
+pd -nogui -stderr -jack chkahichdahk.pd
+```
+
+- `-nogui` runs Pd without windows since the phone has no graphical interface
+- `-stderr` prints Pd messages in the terminal so you can see errors.
+- `-jack` uses JACK for audio
+- `chkahichdahk.pd` is the patch to open
+
+Now touch the screen and press the buttons. You should hear sound coming out of your headpones!
+
+### Chapter 8: automatically starting everything
+
+Everything we have done in chapter 6 and chapter 7 we will have to redo when the phone reboots. To start everything automatically at every reboot run the install script:
+
+```bash
+cd ~/unbrick01
+sudo ./install
+```
+
+The `install` script needs `sudo` because it changes the phone's startup settings. After this, the phone works as a standalone instrument. Reboot it, plug in headphones and test it out!
+
# Installing pmOS on the Samsung A52 4G
## Unlocking the bootloader