From Investigation to Practical Results
In the previous article, I described how I managed to gain access to Linux inside the Allwinner V851-based Carlinkit U2W Mini.
Now I want to take a closer look at the technical side of the process: how I dumped the flash memory, examined the firmware, modified the filesystem, and wrote the modified image back to the device.
Later, I prepared a Python script that automates unpacking, repacking, and verifying the firmware dump.
In this article, I'll cover the main steps and commands. I plan to publish the script separately on GitHub.
Hardware Platform
My Carlinkit U2W Mini uses an Allwinner V851 processor.
The firmware is stored in SPI NAND Flash:
- Model:
F35SQA001G - Capacity: 128 MiB (134,217,728 bytes)
- Interface: SPI NAND
I decided to access the flash memory through the processor's built-in boot mechanism using the xfel utility.
First, I needed to put the V851 into FEL mode.
Entering FEL Mode
During normal startup, the processor loads its firmware from SPI NAND.
I assumed that if I disrupted flash memory reads during startup, the processor might enter an alternative boot mode.
To test this, I temporarily shorted one of the SPI Flash signal pins to ground.
The experiment worked: instead of booting normally, the Carlinkit entered FEL mode and became accessible to the computer over USB.
This can be checked with:
lsusb
In my case, the device appeared as:
Bus 001 Device 003: ID 1f3a:efe8 Allwinner Technology sunxi SoC OTG connector in FEL/flashing mode
Warning: shorting pins on an integrated circuit can damage the device. This experiment describes my own experience and is not a universal procedure. Shorting power supply pins is particularly dangerous.
Installing xfel
I used the xfel project:
https://github.com/xboot/xfel
Install the dependencies on Ubuntu:
sudo apt update
sudo apt install -y git build-essential libusb-1.0-0-dev pkg-config
Clone the repository and build the tool:
git clone https://github.com/xboot/xfel.git
cd xfel
make
sudo make install
After installation, you can reload the device rules:
sudo udevadm control --reload-rules
sudo udevadm trigger
Check communication with the processor:
xfel version
In my case, the output was:
AWUSBFEX ID=0x00188600(V851/V853) dflag=0x44 dlength=0x08 scratchpad=0x00040400
This confirmed that the computer could communicate with the processor.
Detecting SPI NAND
The next step was to identify the flash memory connected to the V851.
xfel spinand
Output:
Found spi nand flash 'F35SQA001G' with 134217728 bytes
The xfel utility successfully detected the flash chip model and its capacity.
I could now proceed with reading its contents.
Creating a Complete Flash Dump
To read the entire flash memory, I used:
xfel spinand read 0 134217728 u2w_full_dump.bin
Here:
0is the starting offset in flash memory.134217728is the number of bytes to read.u2w_full_dump.binis the output filename.
After running the command, I had a complete 128 MiB SPI NAND image.
This is the most important file in the entire process.
Always keep a separate backup of the original dump before making any modifications.
It provides a way to restore the original firmware if the modified version does not work.
What's Inside the Dump?
The resulting file cannot simply be opened like a regular archive.
In my case, the firmware had a particular structure that required investigation.
I eventually identified the following parameters:
| Parameter | Value |
|---|---|
| Full image size | 128 MiB |
| UBI region offset | 0x500000 |
| PEB size | 0x40000 (256 KiB) |
| Page size | 0x800 (2048 bytes) |
| VID Header offset | 0x800 |
| Data offset | 0x1000 |
| UBI volume containing rootfs | 5 |
| rootfs filesystem | SquashFS |
Another complication was the way data was arranged in the SPI NAND dump.
To obtain a valid UBI image for analysis with standard tools, I had to rearrange the pages.
The Python script uses a function called transform() for this.
Transforming SPI NAND Data
Each 256 KiB block is divided into two 128 KiB halves.
During the transformation, 2048-byte pages from the first and second halves are interleaved.
In simplified form:
Original block:
First half: A0 A1 A2 A3 ...
Second half: B0 B1 B2 B3 ...
After transformation:
A0 B0 A1 B1 A2 B2 A3 B3 ...
The main part of the algorithm:
for base in range(0, len(data), PEB):
for p in range(HALF // PAGE):
a = base + p * PAGE
b = base + HALF + p * PAGE
c = base + p * 2 * PAGE
out[c:c + PAGE] = data[a:a + PAGE]
out[c + PAGE:c + 2 * PAGE] = data[b:b + PAGE]
After this transformation, the UBI structure can be processed.
When rebuilding the firmware, the reverse operation restores the original page order.
Extracting UBI and rootfs
After transforming the data, I obtained a UBI image.
The ubi_reader tools can be used to examine it.
For example:
ubireader_extract_images -p 262144 \
-o extracted_volumes \
ubi-deinterleaved.img
The firmware contains several UBI volumes.
The rootfs filesystem I needed was located in volume 5.
This is a dynamic UBI volume containing a SquashFS image.
After extracting the volume contents, the filesystem can be unpacked:
unsquashfs -d rootfs rootfs-volume.bin
This creates a rootfs directory containing the Linux filesystem.
Now it is possible to inspect configuration files, startup scripts, and executable programs.
This was the point where I began to understand why the stock firmware restricted access to the system.
Why UART RX Didn't Work and ADB Was Unavailable
During my first Carlinkit experiments, I had already connected to its UART interface.
Linux console output worked, but I could not send commands to the console.
After examining the firmware, I discovered that the stock application reconfigured the function of the processor pin used for UART RX.
As a result, transmission through TX continued to work, while receiving commands through RX stopped working.
The stock software also prevented access through ADB over USB.
In other words, Linux already had the necessary access mechanisms, but the stock application prevented me from using them.
Modifying rootfs
To gain access, I modified the contents of the filesystem.
The main idea was to prevent the stock executable sdDongle, responsible for CarPlay functionality, from starting automatically.
This binary handled the adapter's main functions: communicating with the iPhone and forwarding data to the head unit.
With it disabled, the system could boot without launching the stock application that restricted access to the interfaces.
In my case, simply removing sdDongle from the extracted rootfs was enough.
Before deleting it, you can locate the file and check its path:
find firmware-unpacked/rootfs -name sdDongle
After confirming the path, the file can be removed from the extracted filesystem.
For example, if it is located in usr/bin:
rm firmware-unpacked/rootfs/usr/bin/sdDongle
This path is only an example. The actual file location must be determined for the specific firmware.
After removing the file, the next step was to rebuild SquashFS and place it back into the original SPI NAND image.
Rebuilding SquashFS
The mksquashfs utility is used to create a new SquashFS image.
In my Python script, the command is constructed as follows:
run(
'mksquashfs',
rootdir,
output,
'-comp', 'gzip',
'-b', str(block_size),
'-mkfs-time', str(timestamp),
'-noappend'
)
This preserves the block size and filesystem creation timestamp read from the original SquashFS.
After building the new image, the script checks whether it fits within the available UBI volume capacity.
If the image exceeds that capacity, the script stops.
Replacing rootfs Inside UBI
Instead of rebuilding the entire UBI image, I chose a different approach.
The script preserves the existing UBI structure, including its headers and other volumes.
Only the data areas of the logical blocks belonging to rootfs are modified.
The main operation looks like this:
for lnum, peb in sorted(mapping.items()):
start = peb * PEB + DATA_OFFSET
updated[start:start + LEB] = b'\xff' * LEB
chunk = sq[lnum * LEB:(lnum + 1) * LEB]
updated[start:start + len(chunk)] = chunk
The algorithm performs the following steps:
- Finds the physical PEB blocks belonging to rootfs.
- Fills their data areas with
0xFF. - Splits the new SquashFS into LEB-sized chunks.
- Writes those chunks into the corresponding blocks.
- Preserves the other UBI volumes and metadata.
The page-order transformation is then reversed, and the modified UBI region is combined with the unchanged initial portion of the original dump.
The result is a complete SPI NAND image ready to be written.
This method is designed for the specific structure of the firmware I investigated, not for arbitrary UBI images.
Automating the Process
To avoid performing every operation manually, I prepared a Python script with three main commands.
Unpacking
python3 v851_firmware.py unpack \
u2w_full_dump.bin \
-o firmware-unpacked
The script:
- Checks the original dump size.
- Transforms the page layout.
- Validates the UBI headers.
- Locates the rootfs volume.
- Extracts SquashFS.
- Unpacks the filesystem.
Repacking
After making changes to the rootfs directory:
python3 v851_firmware.py pack \
u2w_full_dump.bin \
firmware-unpacked/rootfs \
-o u2w_modified.bin
The script builds a new SquashFS, places it into the original UBI structure, and creates a complete flash memory image.
The original dump is not overwritten.
Verification
python3 v851_firmware.py verify \
u2w_modified.bin \
--original u2w_full_dump.bin
Verification includes:
- Full image size.
- UBI structure and headers.
- Presence of rootfs.
- SquashFS validity.
- Reversibility of the page transformation.
- Confirmation that no changes were made outside the rootfs data areas.
However, successfully verifying the image structure does not guarantee that the device will boot with the modified firmware.
Note: v851_firmware.py is a placeholder filename used in these examples. Once the script is published on GitHub, the commands can be updated to match its final name.
Flashing the Modified Firmware
After preparing the image, I put the Carlinkit back into FEL mode.
For flashing, I used xfel with the spinand write command.
The general command looks like this:
xfel spinand write 0 u2w_modified.bin
I did not use a separate xfel spinand erase command.
It is important to understand that this operation writes a complete flash memory image. An incorrect file or incompatible partition layout may prevent the device from booting.
Before flashing, make sure the image was created from a dump of the same device and that the original backup has been preserved.
Result: Carlinkit Appears as an ADB Device
After flashing the modified firmware, I rebooted the adapter.
And the result was exactly what I had hoped for.
Previously, when connected over USB, the Carlinkit identified itself as a device intended to communicate with the car's multimedia system.
Now the computer detected it as an ADB device.
To connect, you can use:
adb devices
adb shell
The shell opened immediately with root privileges.
No additional privilege escalation was required.
This gave me full access to Linux inside the Carlinkit U2W Mini.
I could now examine the system directly on the running device, execute my own programs, and continue development.
Restoring the Original Firmware
Having a complete original dump makes it possible to restore the original SPI NAND contents using xfel.
To do this, the processor must be put into FEL mode again, and the saved image can be written back:
xfel spinand write 0 u2w_full_dump.bin
Of course, recovery depends on FEL mode remaining accessible and the flash memory itself being functional.
For this reason, the original dump should be stored separately from working files and should never be used as an output file during modification.
What's Next?
Originally, all this work started with a fairly simple goal: accessing the built-in MFi chip without having to solder wires to it.
But gaining root access opened up much greater possibilities.
I now had full access to Linux running on the Allwinner V851, its filesystem, and the ability to run my own software.
And the Carlinkit already contained a hardware platform capable of receiving and processing a CarPlay stream.
The next logical step was to try porting CaRaBack directly to the V851.
That's what I'll cover in the next article.