|
| 1 | +# NextThingCo C.H.I.P / PocketCHIP |
| 2 | + |
| 3 | +```nix |
| 4 | +{ |
| 5 | + inputs.nixpkgs.url = "https://nixos.org/channels/nixos-25.11/nixexprs.tar.xz"; |
| 6 | + inputs.nixos-hardware.url = "github:NixOS/nixos-hardware"; |
| 7 | + outputs = { nixpkgs, nixos-hardware, ... }: { |
| 8 | + nixosConfigurations.ntcchip = nixpkgs.lib.nixosSystem { |
| 9 | + modules = [ |
| 10 | + # If you are using C.H.I.P without PocketCHIP |
| 11 | + # nixos-hardware.nixosModules.nextthing-chip |
| 12 | +
|
| 13 | + # If you are using PocketCHIP |
| 14 | + nixos-hardware.nixosModules.nextthing-chip-pocketchip |
| 15 | +
|
| 16 | + { |
| 17 | + # Cross compilation build architecture |
| 18 | + nixpkgs.buildPlatform.system = "x86_64-linux"; |
| 19 | +
|
| 20 | + # Don't lock yourself out! |
| 21 | + services.openssh.enable = true; |
| 22 | + users.users.root = { |
| 23 | + initialPassword = "INSECURE CHANGE ME LATER"; |
| 24 | + openssh.authorizedKeys.keys = [ "..." ]; |
| 25 | + }; |
| 26 | + networking.wireless.enable = true; |
| 27 | + } |
| 28 | + ]; |
| 29 | + }; |
| 30 | + }; |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +## Try NixOS without wiping the stock OS |
| 35 | + |
| 36 | +Build the image, then flash it to a USB thumbdrive: |
| 37 | + |
| 38 | +```shellsession |
| 39 | +$ nix build .#nixosConfigurations.ntcchip.config.system.build.sdImage -o result-image -vL |
| 40 | +$ zstdcat ./result-image/sd-image/*.img.zst | sudo dd of=/dev/sdb status=progress |
| 41 | +``` |
| 42 | + |
| 43 | +(It's called `sdImage` but we are not going to flash it to an SD card, just utilizing the `sdImage` infrastructure to build a flashable image.) |
| 44 | + |
| 45 | +Plug the thumbdrive to your CHIP. Now we need to enter the "FEL mode". This can be achieved by connecting a jumper wire between the "FEL" pin and "GND" before boot, or pressing the `Reboot to FEL mode` button on the stock OS. |
| 46 | + |
| 47 | +Now we can build our version of the bootloader and boot from it: |
| 48 | + |
| 49 | +```shellsession |
| 50 | +$ nix build .#nixosConfigurations.ntcchip.config.system.build.uboot -o result-uboot -vL |
| 51 | +$ nix-shell -p sunxi-tools |
| 52 | +[nix-shell]$ sudo sunxi-fel uboot ./result-uboot/u-boot-sunxi-with-spl.bin |
| 53 | +``` |
| 54 | + |
| 55 | +The `sunxi-fel` command can fail complaining `ERROR: Allwinner USB FEL device not found!`. Simply try rerunning the command a few times more. |
| 56 | + |
| 57 | +## Install U-Boot to NAND |
| 58 | + |
| 59 | +The Allwinner R8 SoC itself can boot from NAND or SD cards (on PF or PC pins). However, this device does not have an SD card slot. In theory you could [add an SD card slot](https://byteporter.com/ntc-chip-micro-sd-slot/), but that's on the PE pins and the SoC cannot boot from it. |
| 60 | + |
| 61 | +To make it boot without the help of a computer, we must install our bootloader to NAND. (WARNING: THIS WILL WIPE YOUR STOCK OS!) |
| 62 | + |
| 63 | +Connect a USB-to-UART dongle to your CHIP (TXD->RXD, RXD->TXD, GND->GND), then run: |
| 64 | + |
| 65 | +```shellsession |
| 66 | +$ nix-shell -p picocom |
| 67 | +[nix-shell]$ picocom -b 115200 /dev/ttyUSB0 |
| 68 | + |
| 69 | +Type [C-a] [C-h] to see available commands |
| 70 | +Terminal ready |
| 71 | +``` |
| 72 | + |
| 73 | +Short "FEL" to "GND", boot your CHIP. Open another shell session, run: (again these commands may fail, repeat the command when it fails) |
| 74 | + |
| 75 | +```shellsession |
| 76 | +$ nix-shell -p sunxi-tools |
| 77 | +[nix-shell]$ sudo sunxi-fel spl result-uboot/sunxi-spl.bin |
| 78 | +[nix-shell]$ sudo sunxi-fel write 0x4a000000 result-uboot/u-boot-dtb.bin |
| 79 | +[nix-shell]$ sudo sunxi-fel write 0x43000000 result-uboot/sunxi-spl-with-ecc.bin |
| 80 | +[nix-shell]$ sudo sunxi-fel exe 0x4a000000 |
| 81 | +``` |
| 82 | + |
| 83 | +Back to the `picocom` shell session, you should see this: |
| 84 | + |
| 85 | +```shellsession |
| 86 | +U-Boot SPL 2025.10 (Oct 06 2025 - 19:13:09 +0000) |
| 87 | +DRAM: 512 MiB |
| 88 | +CPU: 1008000000Hz, AXI/AHB/APB: 3/2/2 |
| 89 | +Trying to boot from FEL |
| 90 | + |
| 91 | + |
| 92 | +U-Boot 2025.10 (Oct 06 2025 - 19:13:09 +0000) Allwinner Technology |
| 93 | + |
| 94 | +CPU: Allwinner A13 (SUN5I) |
| 95 | +Model: NextThing C.H.I.P. |
| 96 | +DRAM: 512 MiB |
| 97 | +Core: 62 devices, 20 uclasses, devicetree: separate |
| 98 | +WDT: Not starting watchdog@1c20c90 |
| 99 | +NAND: 0 MiB |
| 100 | +Loading Environment from nowhere... OK |
| 101 | +DDC: timeout reading EDID |
| 102 | +DDC: timeout reading EDID |
| 103 | +DDC: timeout reading EDID |
| 104 | +Setting up a 480x272 lcd console (overscan 0x0) |
| 105 | +In: serial,usbkbd |
| 106 | +Out: serial,vidconsole |
| 107 | +Err: serial,vidconsole |
| 108 | +Allwinner mUSB OTG (Peripheral) |
| 109 | +Net: using musb-hdrc, OUT ep1out IN ep1in STATUS ep2in |
| 110 | +MAC de:ad:be:ef:00:01 |
| 111 | +HOST MAC de:ad:be:ef:00:00 |
| 112 | +RNDIS ready |
| 113 | +eth0: usb_ether |
| 114 | + |
| 115 | +starting USB... |
| 116 | +USB EHCI 1.00 |
| 117 | +USB OHCI 1.0 |
| 118 | +Bus usb@1c14000: 2 USB Device(s) found |
| 119 | +Bus usb@1c14400: 1 USB Device(s) found |
| 120 | + scanning usb for storage devices... 1 Storage Device(s) found |
| 121 | +Hit any key to stop autoboot: 2 |
| 122 | +``` |
| 123 | + |
| 124 | +Hit any key before it counts to 0 and you'll enter the U-Boot shell. Run: |
| 125 | + |
| 126 | +```shellsession |
| 127 | +=> nand erase.chip |
| 128 | + |
| 129 | +NAND erase.chip: device 0 whole chip |
| 130 | +Skipping bad block at 0x14800000 |
| 131 | +Skipping bad block at 0x15800000 |
| 132 | +Skipping bad block at 0xd7c00000 |
| 133 | +Skipping bbt reserved at 0xff000000 |
| 134 | +Skipping bbt reserved at 0xff400000 |
| 135 | +Skipping bbt reserved at 0xff800000 |
| 136 | +Skipping bbt reserved at 0xffc00000 |
| 137 | + |
| 138 | +OK |
| 139 | +=> nand write.raw.noverify 0x43000000 0 40 |
| 140 | + |
| 141 | +NAND write: 1130496 bytes written: OK |
| 142 | +=> nand write.raw.noverify 0x43000000 0x400000 40 |
| 143 | + |
| 144 | +NAND write: 1130496 bytes written: OK |
| 145 | +=> nand write 0x4a000000 0x800000 0xc0000 |
| 146 | + |
| 147 | +NAND write: device 0 offset 0x800000, size 0xc0000 |
| 148 | + 786432 bytes written: OK |
| 149 | +=> reset |
| 150 | +resetting ... |
| 151 | +``` |
| 152 | + |
| 153 | +## Install rootfs to NAND |
| 154 | + |
| 155 | +This is not yet implemented, primarily due to the poor MLC NAND support on mainline Linux. In theory we could use SLC emulation mode to workaround this, like what [@macromorgan did with Debian 11](https://www.reddit.com/r/ChipCommunity/comments/pwhf37/mainline_debian_working_off_nand/). However, SLC emulation reduces usable storage by half (2 GiB), while a minimal NixOS install takes around 2.6 GiB. |
| 156 | + |
| 157 | +## PocketCHIP Keyboard |
| 158 | + |
| 159 | +[`pocketchip.nix`](./pocketchip.nix) adds an XKB keyboard layout for PocketCHIP. It should be automatically available under Xorg and Linux console. For Wayland composers, you have to configure it manually: |
| 160 | + |
| 161 | +### Sway |
| 162 | + |
| 163 | +``` |
| 164 | +input "1:1:tca8418" { |
| 165 | + xkb_layout us+pocketchip |
| 166 | +} |
| 167 | +``` |
| 168 | + |
| 169 | +### Niri |
| 170 | + |
| 171 | +```kdl |
| 172 | +input { |
| 173 | + keyboard { |
| 174 | + xkb { |
| 175 | + layout "us+pocketchip" |
| 176 | + } |
| 177 | + } |
| 178 | +} |
| 179 | +``` |
| 180 | + |
| 181 | +The Home/Power button sends `XF86PowerOff`. You can `disable-power-key-handling`, then bind it to something else: |
| 182 | + |
| 183 | +```kdl |
| 184 | +input { |
| 185 | + disable-power-key-handling |
| 186 | +} |
| 187 | +binds { |
| 188 | + XF86PowerOff repeat=false { toggle-overview; } |
| 189 | +} |
| 190 | +``` |
0 commit comments