r/nintendo • u/freenesclassic • Nov 11 '16
Mod Pick Linux on NES Classic Mini - Current Progress and HowTo
..
UPDATE: Running Linux. HowTo extended.
... and I will stop at this point. See comment below.
I'd like to share my current progress and process how to get an own linux on the board. The goal is to get a own linux running on the system, read the NAND storage and so nintendos' uboot, linux and rootfs.
I wont fully explain everything, just the necessary steps. So, everyone else can join and progress will be faster together. The NES hardware parts are listed here https://www.reddit.com/r/nintendo/comments/5avo9m/nes_classic_hardware_if_this_picture_is_true/
Hardware u need:
- a serial to usb converter is enough. Something like the FTDI232.
Software:
- Ubuntu Linux
- Install the build tools, cross compiler and dtc: apt-get install build-essential git gcc-arm-linux-gnueabihf device-tree-compiler
Connect the FTDI as shown here: http://emuonpsp.net/images/famicon_mini_hack/DSC09016_mod.JPG and check for /dev/ttyUSB0.
> screen /dev/ttyUSB0 115200Connect the nintento power cable. U should see something like
U-Boot 2011.09-rc1 (Aug 04 2016 - 17:38:23) Allwinner Technology
[ 0.218]version: 1.1.0
[ 0.220]uboot commit : 99e37e13f097e9d91c91252e8f00f0c6eaf6f7a0
ready
no battery, limit to dc
no key input
dram_para_set start
dram_para_set end
Using default environment
In: Out: Err:Pressing the power button will give u
Uncompressing Linux... done, booting the kernel.And this is all u see for. Now, turn off the device and unplug the power cable. Plugin in the power cable again, hold reset button and press the power button. Now u are in FEL mode.
U-Boot 2011.09-rc1 (Aug 04 2016 - 17:38:23) Allwinner Technology
[ 0.218]version: 1.1.0
[ 0.220]uboot commit : 99e37e13f097e9d91c91252e8f00f0c6eaf6f7a0
ready
no battery, limit to dcSince there is an A33 from Allwinner, clone this repo and build it: https://github.com/linux-sunxi/sunxi-tools
> ./sunxi-fel version
AWUSBFEX soc=00001667(A33) 00000001 ver=0001 44 08 scratchpad=00007e00 00000000 00000000Seeing this line means u are in FEL mode. sunxi-fel is very handy. All we want now is to boot our custom u-boot from USB (http://linux-sunxi.org/FEL/USBBoot). Follow http://linux-sunxi.org/FEL/USBBoot#Mainline_U-Boot_.28v2015.04_and_newer_versions.29 and use Sinlinx_SinA33_defconfig instead Cubietruck_defconfig.
> git clone git://git.denx.de/u-boot.git
> cd u-boot
> make CROSS_COMPILE=arm-linux-gnueabihf- Sinlinx_SinA33_defconfig
> make CROSS_COMPILE=arm-linux-gnueabihf- menuconfigDisable: CMD_MMC, CONFIG_SPL_MMC_SUPPORT and CONFIG_MMC (use SHIFT + / in menuconfig to search for these symbols and to get their location).
> make CROSS_COMPILE=arm-linux-gnueabihf-
> ./sunxi-fel uboot u-boot-sunxi-with-spl.bin
U-Boot SPL 2016.11-rc3-00044-g38cacda (Nov 11 2016 - 17:47:36)
DRAM: 256 MiB
Trying to boot from FEL
U-Boot 2016.11-rc3-00044-g38cacda (Nov 11 2016 - 17:47:36 +0000) Allwinner Technology
CPU: Allwinner A33 (SUN8I 1667)
Model: Sinlinx SinA33
DRAM: 256 MiB
Using default environment
In: serial
Out: serial
Err: serial
Net: No ethernet found.
starting USB...
USB0: USB EHCI 1.00
USB1: USB OHCI 1.0
scanning bus 0 for devices... 1 USB Device(s) found
Hit any key to stop autoboot: 0
=> Unfortunately, I did not manage to get NAND support for the A33 (sun8i) into u-boot. So there was no way to read the on-boards' NAND from u-uboot. But since we have u-boot, we can run our custom linux kernel (which for sure has sun8i and nand support). The only think we have to care about, is to do everything from RAM. If we touch the NAND, we probably loose our desired data. We will use the mainline kernel. Follow the steps from https://linux-sunxi.org/Mainline_Kernel_Howto until "Adding a new device".
First of all, run menuconfig
> make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfigGo to General setup > Initramfs source files and enter /home/xyz/rootfs. The initramfs will contain a fully root filesystem that resist in RAM. We will put our root filesystem into the /home/xyz/rootfs folder. Build your own rootfs with yocto or check the web for some minimal filesystems, e.g. releases.linaro.org has some minimal-initramfs images.
> cd
> wget yourimage.cpio.gz -O rootfs.cpio.gz
> gunzip rootfs.cpio.gz
> mkdir rootfs
> cd rootfs
> sudo cpio -idv < ../rootfs.cpio
> cd dev/
> sudo mknod -m 622 console c 5 1
> sudo mknod -m 622 tty0 c 4 0
> sudo mknod -m 622 ttyS0 c 4 0Back to your linux-src folder. We need to make some changes on a dts file (we will misuse the sinlinx file):
arch/arm/boot/dts/sun8i-a33-sinlinx-sina33.dts
-> replace status ="okay" with "disabled" for mmc0 and mmc2
Time to build the kernel. The initramfs will be embedded into the kernel.
> sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage dtbs modulesFor booting the new kernel we need following files:
- arch/arm/boot/zImage
- arch/arm/boot/dts/sun8i-a33-sinlinx-sina33.dtb
Put it all together:
> ./sunxi-fel uboot u-boot-sunxi-with-spl.bin write 0x42000000 zImage write 0x46000000 sun8i-a33-sinlinx-sina33.dtbIn u-boot:
=> setenv bootargs console=ttyS0,115200 loglevel=8 earlyprintk panic=10
=> bootz 0x42000000 - 0x46000000Your Linux will boot now:
Starting kernel ...
Uncompressing Linux... done, booting the kernel.
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 4.9.0-rc5-ge76d21c-dirty (--) (gcc version 4.8.4 (Ubuntu/Linaro 4.8.4-2ubuntu1~14.04.1) ) #0 SMP Tue Nov 15 00:35:50 UTC 2016
[ 0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
[ 0.000000] CPU: div instructions available: patching division code
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
...
fs-test [rc=0]#
fs-test [rc=0]# uname -a
Linux (none) 4.9.0-rc5-ge76d21c-dirty #0 SMP Tue Nov 15 00:35:50 UTC 2016 armv7l GNU/LinuxSomething else
The RAM (256 MB = 0x10000000) is memory mapped starting from 0x40000000 (see User Guide http://dl.linux-sunxi.org/A33/A33%20user%20manual%20release%201.1.pdf).
Once u have initialized the RAM, u can get a lot of information out of it:
./sunxi-fel spl u-boot-sunxi-with-spl.bin
./sunxi-fel read 0x40000000 0x10000000 ram.dump.bin
binwalk ram.dump.bin
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
1678698 0x199D6A Unix path: /--/-/-/-=
4555312 0x458230 Certificate in DER format (x509 v3), header length: 4, sequence length: 17856
7005504 0x6AE540 Executable script, shebang: "/bin/sh"
19745406 0x12D4A7E PARity archive data
50366968 0x30089F8 YAFFS filesystem
...
50368312 0x3008F38 YAFFS filesystem
50368416 0x3008FA0 YAFFS filesystem
50372096 0x3009E00 YAFFS filesystem
88389652 0x544B814 MySQL ISAM index file Version 2
88390263 0x544BA77 MySQL MISAM index file Version 5
93239345 0x58EB831 Private key in DER format (PKCS header length: 4, sequence length: 512
93335030 0x5902DF6 Marvell Libertas firmware
97029512 0x5C88D88 YAFFS filesystem
105555691 0x64AA6EB mcrypt 2.2 encrypted data, algorithm: blowfish-448, mode: CBC, keymode: 8bit
106513439 0x659441F mcrypt 2.2 encrypted data, algorithm: blowfish-448, mode: CFB, keymode: 8bit
108073851 0x671137B mcrypt 2.2 encrypted data, algorithm: blowfish-448, mode: CBC, keymode: 8bit
111917339 0x6ABB91B MySQL ISAM index file Version 8
112904216 0x6BAC818 Unix path: /dev/mepper/rO/t-srypt
115221232 0x6DE22F0 Marvell Libertas firmware
117835404 0x706068C Android bootimg, kernel size: 1869570560 bytes, kernel addr: 0x203A6174, ramdisk size: 543449442 bytes, ramdisk addr: 0x746F6F62, product name: "a boot.img?"
117850432 0x7064140 CRC32 polynomial table, little endian
118000120 0x70889F8 YAFFS filesystem
...
118001568 0x7088FA0 YAFFS filesystem
118005248 0x7089E00 YAFFS filesystem
168051508 0xA044334 CRC32 polynomial table, little endian
168096407 0xA04F297 Android bootimg, kernel size: 1296126464 bytes, kernel addr: 0x73696420, ramdisk size: 1869357163 bytes, ramdisk addr: 0x61206461, product name: "%skernel size: %x"
247330549 0xEBDF6F5 MySQL MISAM index file Version 1
252101561 0xF06C3B9 MySQL MISAM index file Version 4
253972467 0xF234FF3 mcrypt 2.2 encrypted data, algorithm: blowfish-448, mode: CBC, keymode: 8bitThere are almost as much as YAFFS filesystems (29) as roms (30). Hmmm :) Now, one could extract specific parts (with dd) from the dump and look into it.
9
u/freenesclassic Nov 15 '16 edited Nov 15 '16
Hey guys, I wont update the documentation anymore. Just full nand support is missing. I have updated the dts files according to the datasheet and activated nand support in the kernel. It gets detected but not really initialized yet. And this is the point where I stop.
My primary goal with this post was to inspire and give the community an initial introduction to start hacking on the nes classic mini. People around the world are starting now. Everyone with a different method. My way is just one way. Its nice, to see the growing on the net. Sooner or later there will be super easy ways to get the nes under full control and nice documentations.
Keep hacking on it but dont forget to enjoy some nice old games as well :) Everything what I have described here, wont brick the console.
15
u/[deleted] Nov 11 '16
Holy shit this just released today o.0
5
u/frederic_b Nov 12 '16
To get NAND support in UBoot, maybe you should use the OSS code released by Nintendo : http://data.nintendo.co.jp/oss/NintendoEntertainmentSystemNESClassicEdition_OSS.zip
3
u/[deleted] Nov 11 '16
you need to specify the rootfs in the bootargs.
Altough didn't you need to use mkimage on those systems?
2
u/will_r3ddit_4_food Nov 14 '16
Will this enable reading ROMs from a USB drive?
21
u/zerotri Nov 11 '16
Hey, I'm working on a similar thing now. You'd likely have better luck with their kernel and maybe even uboot. The NAND drivers in mainline are not compatible with the NAND drivers in the onboard firmware. Nintendo is using Allwinner's Sunxi NAND driver. You could however use a mainline uboot to boot a build of their kernel and an initramfs sideloaded from FEL. This should allow you to read from the NAND.
•
u/razorbeamz ON THE LOOSE Nov 11 '16
I'm giving this the Mod Pick flair because it's really neat!
13
u/nintendoclover Nov 14 '16 edited Nov 14 '16
https://twitter.com/6f70 Has gotten linux up and running. screenshot & bootlog
20
u/afsdjkll Nov 12 '16
Whoa. You should put an EMULATOR on this thing. I have a list of like 30 games that would be just awesome.
18
u/MrRom92 Nov 11 '16
That was fast. Hope you guys are able to implement some simple i/o through the USB port!
8
u/[deleted] Nov 12 '16
Enable CONFIG_MTD
https://cateee.net/lkddb/web-lkddb/MTD.html
11
u/City66 Nov 11 '16
And now we wait for how to load new games on it.
2
u/Spork_Schivago Nov 13 '16
Hi, sorry to bug ya, I'm just a little confused here and wanted some clarification. When you say, "All we want now is to boot our custom u-boot from USB...", I'm having a little trouble understanding. Aren't we connecting via RS232 (serial)? Is this because we're using a serial to USB adapter? If we weren't using a serial to USB adapter and had a serial port on our PC, would the steps be the same, or couldn't we use u-boot?
Also, this might be because I know nothing about u-boot, but how does u-boot know what device to connect to? I don't see where we're passing anything like /dev/ttyUSB0 to sunxi-fel.
Finally, as previously mentioned, I don't know anything about u-boot and sunxi-fel. I do have a good amount of Linux experience though. We're not actually writing anything to the NES Classic's flash, right? So, once I boot into the custom kernel, all I have to do is restart the NES to get back to the NES? I'd like to try to start helping once my NES Classic comes in the mail tomorrow or the next day.
Thanks and keep up the great work!
5
u/roccoaugusto Nov 12 '16
Has anyone been able to extract the emulator from this?
4
u/sebastian404 Nov 12 '16
Looking forward to the day I can play Doom on it.
5
u/dajigo Nov 11 '16
This is pretty neat. I hope you get to dump the nand soon!
In particular, extracting the nes roms from this should be interesting, as some videos have shown that they seem to be anti-epilepsy patched. I'd love to know wether the rom dumps match the ones from previous VC releases, which have also been altered at the rom level.
1
u/Spork_Schivago Nov 13 '16
Also, I see on this Japanese site I've been reading, that the mini-USB connector can be used to communicate with the SoC via FEL mode. Is that true? I've used Google translator to translate the text. This is what the gentleman says:
NES D+ and D- pins of the mini-USB port is not short-circuited as rapid charging cable of the smartphone, has been connected to the SoC.
This is, following in addition to order and to be recognized as a device to request the power of legally 500mA like, can also be used as a communication channel of FEL mode (see below).
For anyone who can read Japanese, here's the original text:
ファミコンミニのUSB端子のD+ピンとD-ピンはスマホの急速充電ケーブルのようにショートしておらず、SoCに接続されています。
これは、以下のようにデバイスとして認識させて合法的に500mAの電力を要求するため以外にも、FELモード(後述)の通信路としても使われます。
Am I misunderstanding the translation or is this guy saying we can access FEL Mode via the USB port on the NES Classic? Thanks!
2
u/[deleted] Nov 11 '16
Good work so far hacker friend :)
1
u/[deleted] Nov 11 '16
So it has nearly the same hardware as the C.H.I.P? Interesting.
1
u/TryingT0Wr1t3 Nov 12 '16
https://forums.gentoo.org/viewtopic-t-942728-start-0.html
Hey, isn't the nand support missing from the kernel and not u-boot?
1
u/duo8 Nov 12 '16
Maybe you could modify Nintendo's kernel and UBoot to get hw support.
1
u/pcpower Nov 15 '16
Can you please post the RAM dump? I'm willing to bet that all those filesystems in the binwalk are just false positives.
1
u/Spork_Schivago Nov 16 '16 edited Nov 16 '16
I'm having trouble after putting the NES Classic into FEL mode and was hoping you could provide some suggestions. First off, I'm using a RS232 shifter, from Sparkfun ( https://www.sparkfun.com/products/449 ) and I'm using a Prolific PL2303 serial to USB adapter.
I can see the system boot up using screen. When I unplug the USB cable and plug it back in, I see the expected text on the screen. I hold down the reset button and hit power. I see the expected text on the screen (so I'm pretty sure it's going into FEL mode...the power light on the NES Classic does not light up). But when I run ./sunxi-fel version I see: ERROR: Allwinner USB FEL device not found!
Because I'm using an RS232 Shifter, I need to power the shifter. I soldered the VCC wire from the shifter to the pin next to the RX pad on the NES Classic. I believe that's the correct pin, otherwise, I wouldn't be seeing the text when I turn on the system.
When I run lsusb, I do NOT see Bus 001 Device 074: ID 1f3a:efe8 in the output.
Any ideas what I might be doing wrong or how I could fix this? I'm running OpenSUSE and the toolchain isn't in the repository, so I download one manually. I'm using the gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabihf toolchain.
I'm thinking maybe it's something with my serial to USB adapter? I see that listed in lsusb as: Bus 001 Device 002: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Any suggestions? Thanks!
1
u/norefillonsleep Nov 30 '16
In order to get the same NAND dump output as /u/freenesclassic do I just need to run the "./sunxi-fel spl u-boot-sunxi-with-spl.bin" and "./sunxi-fel read 0x40000000 0x10000000 ram.dump.bin" in FEL mode (obviously after I create the u-boot file) or do I need to first load the new kernel in FEL mode and then run the spl and read commands?
1
u/acrolance Nov 30 '16
has any one ripped the nes classic's emulator and got it to run on something else like a raspberry pi or something?
if so please let me know what i need to google to find this info!
1
u/[deleted] Nov 11 '16
Wait. I thought they swore up and down that the USB was only power. You were able to reach the CPU via that port? Or is this an HDMI hack I'm not aware of?
1
u/langer_hans Nov 11 '16
Nice work, wasn't brave enough to solder around yet ;)
Was playing around in FEL mode before I saw this post and trying to do a NAND dump there. But I couldn't get the NAND mapped properly so far :/ Any idea about that way?
1
u/TotesMessenger Nov 11 '16
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
1
u/speel Nov 11 '16
What is the screen command?
0
u/[deleted] Nov 12 '16
[deleted] — view deleted comment