|
| 1 | +# AnyCubic Centauri Carbon - UART Bootloader Patch (OC2.3.9) |
| 2 | + |
| 3 | +This directory contains tools and configuration for enabling UART serial console support on the AnyCubic Centauri Carbon 3D printer running firmware OC2.3.9 (based on Allwinner R528). |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This patch enables **full UART serial console support** in both U-Boot bootloader and Linux kernel while maintaining compatibility with the Centauri Carbon device tree for normal 3D printing operations. The solution merges UART-enabled device tree configurations with the AnyCubic 2.3.9 U-Boot binary. |
| 8 | + |
| 9 | +## Background |
| 10 | + |
| 11 | +The stock AnyCubic firmware does not enable UART0 for serial console access, making debugging and system analysis difficult. This patch: |
| 12 | + |
| 13 | +1. **Adds UART0 configuration** to both SPL (board) and kernel device trees |
| 14 | +2. **Enables serial console** at 115200 baud on UART0 |
| 15 | +3. **Preserves the Centauri Carbon device tree** for LCD, PWM, I2C, and other peripherals |
| 16 | +4. **Maintains bootloader integrity** through proper checksum and slot management |
| 17 | + |
| 18 | +## Hardware Connection |
| 19 | + |
| 20 | +UART0 is available on the SD card pins: |
| 21 | +- **TX (Transmit)**: PF2 (SD Card DAT0) |
| 22 | +- **RX (Receive)**: PF4 (SD Card DAT2) |
| 23 | +- **Ground**: SD Card Shield/GND |
| 24 | + |
| 25 | +Use a 3.3V TTL serial adapter. Connect at **115200 8N1**. |
| 26 | + |
| 27 | +## Files |
| 28 | + |
| 29 | +### Device Tree Sources (DTS) |
| 30 | + |
| 31 | +- **`board_config.dts`** - SPL/U-Boot board configuration |
| 32 | + - Configures clocks, pinmux, storage controllers |
| 33 | + - **UART0 injection** at lines 825-839 with aliases and chosen stdout |
| 34 | + |
| 35 | +- **`kernel_config.dts`** - Main Linux kernel device tree |
| 36 | + - Complete R528 device tree with all peripherals |
| 37 | + - **UART0 enabled** at lines 1165-1182 (status = "okay") |
| 38 | + - Serial console configured in bootargs and aliases |
| 39 | + |
| 40 | +### Tools |
| 41 | + |
| 42 | +- **`repack.py`** - Python script to rebuild U-Boot image |
| 43 | + - Compiles `.dts` files to `.dtb` using `dtc` compiler |
| 44 | + - Injects DTBs at fixed offsets in U-Boot binary |
| 45 | + - Updates checksums and size headers |
| 46 | + - Preserves ELF binary placement for bootloader integrity |
| 47 | + |
| 48 | +- **`uboot-generate.sh`** - Master build script |
| 49 | + - Executes `repack.py` to build new U-Boot |
| 50 | + - Runs validation with `check.sh` |
| 51 | + - Packages `boot0` and `uboot` into `uart.zip` |
| 52 | + |
| 53 | +- **`check.sh`** - Validation script |
| 54 | + - Verifies ELF magic offsets match between original and patched |
| 55 | + - Ensures binary structure integrity |
| 56 | + |
| 57 | +### Binary Files |
| 58 | + |
| 59 | +- **`original_dump.bin`** - Original AnyCubic 2.3.9 U-Boot dump |
| 60 | +- **`repacked_boot.bin`** - Generated patched U-Boot (after running scripts) |
| 61 | +- **`boot0`** - SPL bootloader (preserved from original) |
| 62 | +- **`uboot`** - Final patched U-Boot image |
| 63 | +- **`uart.zip`** - Flashable package containing `boot0` and `uboot` |
| 64 | + |
| 65 | +## Usage |
| 66 | + |
| 67 | +### Prerequisites |
| 68 | + |
| 69 | +Install device tree compiler: |
| 70 | +```bash |
| 71 | +sudo apt-get install device-tree-compiler |
| 72 | +``` |
| 73 | + |
| 74 | +### Building |
| 75 | + |
| 76 | +Run the generation script: |
| 77 | +```bash |
| 78 | +./uboot-generate.sh |
| 79 | +``` |
| 80 | + |
| 81 | +This will: |
| 82 | +1. Compile both DTS files to DTB format |
| 83 | +2. Inject them into the U-Boot binary at fixed slots |
| 84 | +3. Update checksums and headers |
| 85 | +4. Validate binary integrity |
| 86 | +5. Create `uart.zip` ready for flashing |
| 87 | + |
| 88 | +### Flashing |
| 89 | + |
| 90 | +1. Extract the original AnyCubic firmware update |
| 91 | +2. Replace `boot0` and `uboot` with files from `uart.zip` |
| 92 | +3. Flash using standard AnyCubic update procedure |
| 93 | + |
| 94 | +**Note**: Boot0 is typically unchanged, but included for completeness. |
| 95 | + |
| 96 | +### Verification |
| 97 | + |
| 98 | +After flashing, connect a serial adapter to UART0 pins and monitor at 115200 8N1. You should see: |
| 99 | +- U-Boot boot messages |
| 100 | +- Kernel boot log |
| 101 | +- Linux login prompt |
| 102 | + |
| 103 | +## Technical Details |
| 104 | + |
| 105 | +### U-Boot Binary Structure |
| 106 | + |
| 107 | +The U-Boot binary has a fixed structure: |
| 108 | + |
| 109 | +``` |
| 110 | ++-------------------+ |
| 111 | +| Header (0x800) | <-- Checksums, sizes |
| 112 | ++-------------------+ |
| 113 | +| SPL Code | |
| 114 | ++-------------------+ |
| 115 | +| Slot 1: SPL DTB | <-- Offset 0xD4914, Size 32492 bytes |
| 116 | ++-------------------+ |
| 117 | +| ELF Binary | |
| 118 | ++-------------------+ |
| 119 | +| Slot 2: Main DTB | <-- Offset 0x120000, Size 65535 bytes |
| 120 | ++-------------------+ |
| 121 | +| Trailing Data | |
| 122 | ++-------------------+ |
| 123 | +``` |
| 124 | + |
| 125 | +**Critical**: DTBs must be injected at **exact fixed offsets** to preserve relative ELF binary position. Shifting these offsets corrupts the bootloader. |
| 126 | + |
| 127 | +### Checksum Algorithm |
| 128 | + |
| 129 | +Allwinner bootloaders use a simple additive checksum: |
| 130 | +1. Write stamp value `0x5F0A6C39` at offset `0x14` |
| 131 | +2. Sum all 32-bit words in the binary |
| 132 | +3. Write final checksum at offset `0x14` |
| 133 | + |
| 134 | +The `repack.py` script handles this automatically. |
| 135 | + |
| 136 | +### Device Tree Patches |
| 137 | + |
| 138 | +#### Board Config (SPL) |
| 139 | +```dts |
| 140 | +uart0: uart@2500000 { |
| 141 | + compatible = "snps,dw-apb-uart"; |
| 142 | + reg = <0x00 0x02500000 0x00 0x400>; |
| 143 | + reg-shift = <2>; |
| 144 | + status = "okay"; |
| 145 | +}; |
| 146 | +
|
| 147 | +chosen { |
| 148 | + stdout-path = "serial0:115200n8"; |
| 149 | +}; |
| 150 | +
|
| 151 | +aliases { |
| 152 | + serial0 = &uart0; |
| 153 | +}; |
| 154 | +``` |
| 155 | + |
| 156 | +#### Kernel Config |
| 157 | +```dts |
| 158 | +uart@2500000 { |
| 159 | + compatible = "allwinner,sun8i-uart"; |
| 160 | + status = "okay"; /* Changed from "disabled" */ |
| 161 | + pinctrl-0 = <0x14>; |
| 162 | + pinctrl-1 = <0x15>; |
| 163 | + ... |
| 164 | +}; |
| 165 | +
|
| 166 | +chosen { |
| 167 | + bootargs = "...console=ttyS0..."; |
| 168 | +}; |
| 169 | +``` |
| 170 | + |
| 171 | +## Troubleshooting |
| 172 | + |
| 173 | +### No Serial Output |
| 174 | +- Check wiring: TX ↔ RX, Ground connected |
| 175 | +- Verify 3.3V TTL levels (not RS-232!) |
| 176 | +- Confirm 115200 8N1 settings |
| 177 | +- Test adapter with another device |
| 178 | + |
| 179 | +### Boot Fails After Flashing |
| 180 | +- Verify `check.sh` passed before flashing |
| 181 | +- Compare file sizes: repacked should match original ±100 bytes |
| 182 | +- Re-extract original firmware and try again |
| 183 | + |
| 184 | +### DTC Compilation Errors |
| 185 | +- Check `.dts` syntax (no missing braces, semicolons) |
| 186 | +- Verify phandle references are valid |
| 187 | +- Use `dtc -I dts -O dts -o /dev/null <file>` to validate |
| 188 | + |
| 189 | +## Credits |
| 190 | + |
| 191 | +- Based on AnyCubic OC 2.3.9 firmware for Centauri Carbon |
| 192 | +- Allwinner R528 (sun8iw20) platform |
| 193 | +- Device tree modifications by cc-fw-tools contributors |
| 194 | + |
| 195 | +## License |
| 196 | + |
| 197 | +These tools are provided as-is for educational and development purposes. Use at your own risk. Always maintain backups of original firmware. |
| 198 | + |
| 199 | +## See Also |
| 200 | + |
| 201 | +- [Allwinner R528 Datasheet](https://linux-sunxi.org/R528) |
| 202 | +- [U-Boot Device Tree Documentation](https://u-boot.readthedocs.io/en/latest/develop/devicetree/intro.html) |
| 203 | +- [Linux Serial Console Setup](https://www.kernel.org/doc/html/latest/admin-guide/serial-console.html) |
0 commit comments