Flashrom was able to dump the SPI flash memory, both dumps have the same md5sum result
SPI Flash: Initial Analysis
After extracting the firmware, we will use binwalk/strings on the resulting image
SPI FLash: Binwalk Output
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
778808 0xBE238 JPEG image data, EXIF standard
778820 0xBE244 TIFF image data, big-endian, offset of first image directory: 8
779486 0xBE4DE Copyright string: "Copyright (c) 1998 Hewlett-Packard Company"
786200 0xBFF18 Copyright string: "Copyright (c) 1998 Hewlett-Packard Company"
794662 0xC2026 Copyright string: "Copyright (c) 1998 Hewlett-Packard Company"
2512544 0x2656A0 Zlib compressed data, default compression
2651638 0x2875F6 Copyright string: "copyright displaying) or when the hiscore **"
2832512 0x2B3880 Zip archive data, at least v2.0 to extract, compressed size: 44, uncompressed size: 279, name: bprg1.11d
2832625 0x2B38F1 Zip archive data, at least v2.0 to extract, compressed size: 47, uncompressed size: 279, name: buf1
2832726 0x2B3956 Zip archive data, at least v2.0 to extract, compressed size: 47, uncompressed size: 279, name: c632.ic1
2832839 0x2B39C7 Zip archive data, at least v2.0 to extract, compressed size: 53, uncompressed size: 279, name: ioa1
2832946 0x2B3A32 Zip archive data, at least v2.0 to extract, compressed size: 53, uncompressed size: 279, name: iob1.12d
2833065 0x2B3AA9 Zip archive data, at least v2.0 to extract, compressed size: 45, uncompressed size: 260, name: ioc1.ic7
2833176 0x2B3B18 Zip archive data, at least v2.0 to extract, compressed size: 71, uncompressed size: 279, name: prg1
2833301 0x2B3B95 Zip archive data, at least v2.0 to extract, compressed size: 47, uncompressed size: 279, name: rom1
2833402 0x2B3BFA Zip archive data, at least v2.0 to extract, compressed size: 285723, uncompressed size: 524288, name: s92-10m.3c
3119165 0x2F983D Zip archive data, at least v2.0 to extract, compressed size: 281716, uncompressed size: 524288, name: s92-11m.4c
3400921 0x33E4D9 Zip archive data, at least v2.0 to extract, compressed size: 185573, uncompressed size: 524288, name: s92-12m.5c
3586534 0x36B9E6 Zip archive data, at least v2.0 to extract, compressed size: 181541, uncompressed size: 524288, name: s92-13m.6c
3768115 0x397F33 Zip archive data, at least v2.0 to extract, compressed size: 290810, uncompressed size: 524288, name: s92-1m.3a
4058964 0x3DEF54 Zip archive data, at least v2.0 to extract, compressed size: 290778, uncompressed size: 524288, name: s92-2m.4a
4349781 0x425F55 Zip archive data, at least v2.0 to extract, compressed size: 195599, uncompressed size: 524288, name: s92-3m.5a
4545419 0x455B8B Zip archive data, at least v2.0 to extract, compressed size: 195382, uncompressed size: 524288, name: s92-4m.6a
4740840 0x4856E8 Zip archive data, at least v2.0 to extract, compressed size: 293202, uncompressed size: 524288, name: s92-5m.7a
5034081 0x4CD061 Zip archive data, at least v2.0 to extract, compressed size: 294846, uncompressed size: 524288, name: s92-6m.8a
5328966 0x515046 Zip archive data, at least v2.0 to extract, compressed size: 204031, uncompressed size: 524288, name: s92-7m.9a
5533036 0x546D6C Zip archive data, at least v2.0 to extract, compressed size: 204872, uncompressed size: 524288, name: s92-8m.10a
5737948 0x578DDC Zip archive data, at least v2.0 to extract, compressed size: 69, uncompressed size: 279, name: s9263b.1a
5738086 0x578E66 Zip archive data, at least v2.0 to extract, compressed size: 216174, uncompressed size: 524288, name: s92e_23b.8f
5954335 0x5ADB1F Zip archive data, at least v2.0 to extract, compressed size: 32045, uncompressed size: 65536, name: s92_09.11a
5986452 0x5B5894 Zip archive data, at least v2.0 to extract, compressed size: 116790, uncompressed size: 131072, name: s92_18.11c
6103314 0x5D2112 Zip archive data, at least v2.0 to extract, compressed size: 116874, uncompressed size: 131072, name: s92_19.12c
6220260 0x5EE9E4 Zip archive data, at least v2.0 to extract, compressed size: 46782, uncompressed size: 524288, name: s92_21a.6f
6267082 0x5FA0CA Zip archive data, at least v2.0 to extract, compressed size: 97339, uncompressed size: 524288, name: s92_22b.7f
6364493 0x611D4D Zip archive data, at least v2.0 to extract, compressed size: 58, uncompressed size: 279, name: sou1
6367003 0x61271B End of Zip archive, footer length: 22
6367028 0x612734 Zip archive data, at least v2.0 to extract, compressed size: 204370, uncompressed size: 524288, name: s92u_23a.8f
6571439 0x6445AF Zip archive data, at least v2.0 to extract, compressed size: 119139, uncompressed size: 524288, name: s92_22a.7f
6690731 0x6617AB End of Zip archive, footer length: 22
SPI Flash: Initial Analysis
Examining the strings in the binary showed some plaintext data
RE Tips: Firmware Blob Analysis
In addition to running binwalk and strings, examine the beginning of the file for header information
Examining the first 512 bytes of the file reveal what looks like a header; googling these strings leads us to the Sunxi FEL Webpage
SPI Flash Analysis
pi@voidstar:~ $ hexdump -n512 -C street-fighter.bin
00000000 a8 00 00 ea 65 47 4f 4e 2e 42 54 30 0d 0c 66 fc |....eGON.BT0..f.|
The first byte sequence - a8 00 00 ea is an ARM branch instruction!
SPI Flash Analysis
Now that we have extracted the SPI flash, we will attempt to understand the boot process
How many stages are there in the boot process?
Are there any stages that we can interrupt?
We also need to answer the following questions:
What OS is in use? (if any)
What filesystem(s) are present?
SPI Flash Analysis
Here we see some debug strings
Are these present in our serial logs?
Understanding the Boot Process
BOOT0 is starting
init dram , base is 0x80000000
init dram , clk is 156
init dram , access_mode is 1
init dram , cs_num is 0x55000001
init dram , ddr8_remap is 0
init dram , sdr_ddr is 1
init dram , bwidth is 16
init dram , col_width is 10
init dram , row_width is 13
init dram , bank_size is 4
init dram , cas is 3
init dram , size is 120
dram init successed,size is 64
jump to BOOT1
DBG: boot1 starting!
DBG: init key OK
before check_key_to_fel.
Understanding the Boot Process
After further analysis of the flash, there are two possible boot images:
eGON.BT0 at address 0
eGON.BT1 at address 0x6000
In both boot images, there are references to jump to fel
After researching FEL we find the following on the Allwinner website
FEL is a low-level subroutine contained in the BootROM on Allwinner devices. It is responsible for the initial programming and recovery of devices using USB.
Understanding FEL Mode
FEL is a low-level subroutine contained in the BootROM on Allwinner devices.
It is used for initial programming and recovery of devices using USB.
Devices must enter FEL mode, causing them to present themselves as a USB device
FEL mode is entered by holding certain IO lines on boot
If this mode is present on our cabinet, how might we trigger it?
Understanding FEL Mode
After testing, it was discovered that holding volume down during startup causes FEL mode to be entered
[129080.108765] usb 1-1.1: new full-speed USB device number 16 using xhci_hcd
[129080.251695] usb 1-1.1: New USB device found, idVendor=1f3a, idProduct=efe8, bcdDevice= 2.b3
[129080.251718] usb 1-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
SPI Flash: Analysis
Based on our initial analysis of the SPI flash, we know the following:
There is a two-stage bootloader
FEL mode can be entered on startup
The CPU is an Allwinner Series CPU
FB Alpha Emulation software is in use
The SF2 ROM in use is likely a standard one
It matches the same structure as the typical MAME ROM
Using FEL Mode
We can enter FEL mode, causing the cabinet to present itself as a USB device
What can we do with this?
before check_key_to_fel.
=== key_type =1 ===
port0:1
port_num0:0
key_value:0
times up, detect io jump to fel.
key found, jump to fel
Using FEL Mode
To communicate with the device in FEL mode, we need to build the sunxi-tools
After building this software, the FEL version can be queried as shown below:
pi@voidstar:~/sf2/sunxi-tools $ sudo ./sunxi-fel version
Warning: no 'soc_sram_info' data for your SoC (id=1663)
AWUSBFEX soc=00001663(unknown) 00000001 ver=0001 44 08 scratchpad=00007e00 00000000 00000000
Using FEL Mode
The standard FEL tools do not have support for our chip ID
After searching through GitHub using the chip ID a fork of this repo was found that supports our chip!
Using Kaitai, we can now generate a python library to parse our structure
This allows us to parse them with the following code quickly:
from minfs import *
target = Minfs.from_file("/home/wrongbaud/blog/sf-cabinet/output-files/ramdisk.iso")
os.mkdir("/home/wrongbaud/blog/sf-cabinet/ramdisk/")
for entry in target.minfs_file_table:
if entry.flags != target.FileType.directory:
with open(f"/home/wrongbaud/blog/sf-cabinet/ramdisk/{entry.name}",'wb') as ofile:
ofile.write(entry.file_data)
Filesystem Analysis: Examining the Binaries
After running our script to parse the filesystem, we generate the following files: