Draft: amazon-yoshi: initial device + linux packages
Some early work to get pmOS running on the Kindle 4/5 devices from 2011ish.
It's based on the work located here and here:
- https://github.com/jmacato/linux-kindle4nt/tree/v5.8.0-kindle-4nt
- https://github.com/fread-ink/linux-5.8-wip/tree/v5.8.0-kindle-4nt-epdc-driver-wip
This is starting with a very hobbled mainline kernel, because I dunno, I don't think downstream is an option? The Amazon GPL dumps are a metric barfload of Freescale patches mingled with Lab126 drive-by-hackery on kernel internals, based off 2.6.x. That seems too old to be useful, and I'm not particularly eager to try and rebase that code into 3.x land. So, mainline it is. Luckily, all the i.MX5xx SoC bits and pieces seem pretty well mainlined by this point. The Tequila board in the Kindle 4 uses a PMIC that also appears to have quite a lot of mainline kernel code already. So ..
So far I can get pmOS booting up to getty via serial port:
U-Boot 2009.08-lab126 (Jan 12 2013 - 20:38:21)
CPU: Freescale i.MX50 family 1.1V at 800 MHz
mx50 pll1: 800MHz
mx50 pll2: 400MHz
mx50 pll3: 216MHz
ipg clock : 50000000Hz
ipg per clock : 50000000Hz
uart clock : 24000000Hz
ahb clock : 100000000Hz
axi_a clock : 400000000Hz
axi_b clock : 200000000Hz
weim_clock : 100000000Hz
ddr clock : 800000000Hz
esdhc1 clock : 80000000Hz
esdhc2 clock : 80000000Hz
esdhc3 clock : 80000000Hz
esdhc4 clock : 80000000Hz
MMC: FSL_ESDHC: 0, FSL_ESDHC: 1
Board: Tequila
Boot Reason: [POR]
Boot Device: MMC
Board Id: 0031707133252FMY
S/N: 90231703334300MH
Initing MDDR memory
ZQ calibration complete: 0x128=0xfffe0010 0x12C=0xffffffff
DRAM: 256 MB
Using default environment
In: serial
Out: logbuff
Err: logbuff
Quick Memory Test 0x70000000, 0x10000000
POST done in 13 ms
Hit any key to stop autoboot: 0
## Booting kernel from Legacy Image at 70800000 ...
Image Name: postmarketos
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 3391452 Bytes = 3.2 MB
Load Address: 70008000
Entry Point: 70008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Starting kernel ...
[ 0.000000][ T0] Booting Linux on physical CPU 0x0
[ 0.000000][ T0] Linux version 5.15.0-rc6- (pmos@pmos) (armv7-alpine-linux-musleabihf-gcc (Alpine 10.3.1_git20210921) 10.3.1 20210921, GNU ld (GNU Binutils) 2.37) #1-postmarketOS Sun O
ct 24 19:52:16 UTC 2021
[ 0.000000][ T0] CPU: ARMv7 Processor [412fc085] revision 5 (ARMv7), cr=50c5387d
[ 0.000000][ T0] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000][ T0] OF: fdt: Machine model: Amazon Kindle 4
[ 0.000000][ T0] Memory policy: Data cache writeback
[ 0.000000][ T0] Zone ranges:
[ 0.000000][ T0] Normal [mem 0x0000000070000000-0x000000007fffffff]
[ 0.000000][ T0] Movable zone start for each node
[ 0.000000][ T0] Early memory node ranges
[ 0.000000][ T0] node 0: [mem 0x0000000070000000-0x000000007fffffff]
[ 0.000000][ T0] Initmem setup node 0 [mem 0x0000000070000000-0x000000007fffffff]
[ 0.000000][ T0] CPU: All CPU(s) started in SVC mode.
[ 0.000000][ T0] Built 1 zonelists, mobility grouping on. Total pages: 65024
[ 0.000000][ T0] Kernel command line:
[ 0.000000][ T0] Dentry cache hash table entries: 32768 (order: 5, 131072 bytes, linear)
[ 0.000000][ T0] Inode-cache hash table entries: 16384 (order: 4, 65536 bytes, linear)
[ 0.000000][ T0] mem auto-init: stack:off, heap alloc:on, heap free:on
[ 0.000000][ T0] mem auto-init: clearing system memory may take some time...
[ 0.000000][ T0] Memory: 254160K/262144K available (3072K kernel code, 366K rwdata, 864K rodata, 1024K init, 144K bss, 7984K reserved, 0K cma-reserved)
[ 0.000000][ T0] random: get_random_u32 called from __kmem_cache_create+0x15/0x27c with crng_init=0
[ 0.000000][ T0] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000][ T0] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[ 0.000000][ T0] TrustZone Interrupt Controller (TZIC) initialized
[ 0.000000][ T0] CPU identified as i.MX50, silicon rev 1.1
[ 0.000000][ T0] Switching to timer-based delay loop, resolution 20ns
[ 0.000002][ T0] sched_clock: 32 bits at 50MHz, resolution 20ns, wraps every 42949672950ns
[ 0.000026][ T0] clocksource: mxc_timer1: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 38225208935 ns
[ 0.000460][ T0] Console: colour dummy device 80x30
[ 0.000852][ T0] printk: console [tty0] enabled
[ 0.000913][ T0] Calibrating delay loop (skipped), value calculated using timer frequency.. 100.00 BogoMIPS (lpj=50000)
[ 0.000956][ T0] pid_max: default: 32768 minimum: 301
[ 0.001259][ T0] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.001298][ T0] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.002175][ T0] CPU: Testing write buffer coherency: ok
[ 0.002255][ T0] CPU0: Spectre v2: firmware did not set auxiliary control register IBE bit, system vulnerable
[ 0.002795][ T1] Setting up static identity map for 0x70100000 - 0x70100054
[ 0.003357][ T1] devtmpfs: initialized
[ 0.006175][ T1] VFP support v0.3: implementor 41 architecture 3 part 30 variant c rev 2
[ 0.006477][ T1] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275000 ns
[ 0.006524][ T1] futex hash table entries: 256 (order: -1, 3072 bytes, linear)
[ 0.006662][ T1] pinctrl core: initialized pinctrl subsystem
[ 0.007746][ T1] DMA: preallocated 256 KiB pool for atomic coherent allocations
[ 0.010856][ T1] cpuidle: using governor menu
[ 0.010908][ T1] No ATAGs?
[ 0.014473][ T1] imx50-pinctrl 53fa8000.iomuxc: initialized IMX pinctrl driver
[ 0.020212][ T1] cryptd: max_cpu_qlen set to 1000
[ 0.032049][ T1] clocksource: Switched to clocksource mxc_timer1
[ 0.047677][ T1] workingset: timestamp_bits=30 max_order=16 bucket_order=0
[ 0.166939][ T1] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)
[ 0.167010][ T1] io scheduler mq-deadline registered
[ 0.167032][ T1] io scheduler kyber registered
[ 0.220204][ T1] 53fbc000.serial: ttymxc0 at MMIO 0x53fbc000 (irq = 47, base_baud = 1500000) is a IMX
[ 0.485396][ C0] random: fast init done
[ 0.601694][ T1] printk: console [ttymxc0] enabled
[ 0.610791][ T1] loop: module loaded
[ 0.615186][ T1] zram: Added device: zram0
[ 0.620269][ T1] i2c_dev: i2c /dev entries driver
[ 0.626471][ T1] device-mapper: ioctl: 4.45.0-ioctl (2021-03-22) initialised: dm-devel@redhat.com
[ 0.635893][ T1] sdhci: Secure Digital Host Controller Interface driver
[ 0.642811][ T1] sdhci: Copyright(c) Pierre Ossman
[ 0.647889][ T1] sdhci-pltfm: SDHCI platform and OF driver helper
[ 0.654737][ T1] ThumbEE CPU extension supported.
[ 0.659753][ T1] Registering SWP/SWPB emulation handler
[ 0.691771][ T5] mmc2: SDHCI controller on 50020000.mmc [50020000.mmc] using ADMA
[ 0.701928][ T1] Freeing unused kernel image (initmem) memory: 1024K
[ 0.708855][ T1] Run /init as init process
+ busybox mount -t proc proc /proc
+ busybox mount -t sysfs sysfs /sys
+ busybox sleep 1
[ 0.784231][ T42] mmc2: new high speed MMC card at address 0001
[ 0.791187][ T42] mmcblk2: mmc2:0001 SEM02G 1.82 GiB
[ 0.798542][ T42] mmcblk2: p1 p2 p3 p4
[ 0.803885][ T42] mmcblk2boot0: mmc2:0001 SEM02G 1.00 MiB
[ 0.811012][ T42] mmcblk2boot1: mmc2:0001 SEM02G 1.00 MiB
[ 0.817862][ T42] mmcblk2rpmb: mmc2:0001 SEM02G 128 KiB, chardev (250:0)
+ busybox cpio -viu
+ busybox dd 'bs=512' 'if=/dev/mmcblk0' 'skip=21000' 'count=8192'
+ busybox gunzip
.
init
splash-charging-error.ppm.gz
splash-debug-shell.ppm.gz
splash-loading.ppm.gz
splash-mounterror.ppm.gz
splash-noboot.ppm.gz
splash-noinitramfsextra.ppm.gz
splash-norootfs.ppm.gz
splash-resizefs.ppm.gz
init_functions.sh
lib
boot
tmp
sbin
usr
usr/bin
usr/sbin
proc
sys
dev
sysroot
bin
etc
usr/sbin/telnetd
bin/busybox-extras
sbin/kpartx
bin/sh
bin/busybox
lib/libc.musl-armv7.so.1
lib/ld-musl-armhf.so.1
etc/deviceinfo
lib/libdevmapper.so.1.02
3200 blocks
+ true
+ busybox umount /sys
+ busybox umount /proc
+ exec /init
### postmarketOS initramfs ###
NOTE: All output from the initramfs gets redirected to:
/pmOS_init.log
If you want to disable this behavior (e.g. because you're
debugging over serial), please add this to your kernel
command line: PMOS_NO_OUTPUT_REDIRECT
[ 4.365016][ T151] EXT4-fs (dm-0): mounting ext2 file system using the ext4 subsystem
[ 4.376183][ T151] EXT4-fs (dm-0): mounted filesystem without journal. Opts: (null). Quota mode: disabled.
[ 6.489744][ T275] EXT4-fs (dm-1): INFO: recovery required on readonly filesystem
[ 6.497415][ T275] EXT4-fs (dm-1): write access will be enabled during recovery
[ 6.562964][ T275] EXT4-fs (dm-1): recovery complete
[ 6.569784][ T275] EXT4-fs (dm-1): mounted filesystem with ordered data mode. Opts: (null). Quota mode: disabled.
[ 6.902821][ T284] EXT4-fs (dm-0): mounting ext2 file system using the ext4 subsystem
[ 6.913513][ T284] EXT4-fs (dm-0): warning: mounting unchecked fs, running e2fsck is recommended
[ 6.923548][ T284] EXT4-fs (dm-0): mounted filesystem without journal. Opts: (null). Quota mode: disabled.
Welcome to postmarketOS
Kernel 5.15.0-rc6- on an armv7l (/dev/ttymxc0)
amazon-yoshi login: user
Password:
login: can't set groups: Function not implemented
As you can see in the final line, I'm not able to login due to the error login: can't set groups: Function not implemented
. Any ideas?
This work only gives the Kindle a pinky-finger grip for the pmOS world:
-
No flasher support because even though the hacked up U-Boot from 2009 that currently boots these devices does support fastboot, it's that strange one that makes everybody in the family kinda look at the floor when it comes up. You know? I don't think the usually-packaged fastboot client can talk to it. fread.ink have a fork of a fork that works well, and I currently use this for the research. But, not sure anybody really wants to be packaging up ancient fastboot forks?
-
The way the initramfs is unceremoniously smooshed into some grey-market eMMC space is also gross, and doesn't really line up with any existing patterns for existing device ports. It's kinda like the isorec trick, but there's no actual spare partition to use, just random barely-legit-looking memory addresses that magically happen to have some gzipped cpio initramfs living there :)
-
Nothing beyond the SoC is mapped out in the device tree yet. The forks I adapted this MR from have more stuff mapped out (like the PMIC) but I felt there was too many magic values and suspicious stuff in there to pull it all in as-is. Rather, I'd prefer distinct commits / MRs with well documented stuff. The lineage of the Kindle devices is somewhat revealed through the GPL dumps Amazon does, so having a properly researched understanding of how the Tequila board works will be useful for the neighboring (earlier, later) generations, I imagine?
I'm getting to a point here though. From what I can tell, the bootloader on these devices is completely unlocked and open. U-Boot seems to just be living at 0x0 on partition 1 of the eMMC. I don't believe Amazon rolled out signed booting until the i.MX6+ based devices.
So, rather than try to bend pmOS too much to fit the esoteric aspects of the Kindle and fix the issues outlined above, maybe it's better to try and get a modern U-Boot running on the Kindle. Then the Kindle would support proper fastboot, and be able to boot from boot.img
Android images. I'm going to spend some time investigating this and would love some mentorship. I'll start lurking in some channels.
Discussion points / questions:
- Kindle 4 and Kindle 5 are essentially the same device. The board is codenamed "tequila" and is shared between them. How to best reflect this in pmOS packaging?
- I guess I should start filling out a device wiki page now right? What else?
- I spent a couple of days bashing my head repetitively against a wall trying to get something USB-ish to come out and was unsuccessful. I believe the wifi is an Atheros AR6103 attached via SDIO on ESDHC2. Is it an insane thought that it might be easier to get wifi up on this thing before USB? I'd like one or the other to improve kernel hacking ergonomics (scp a new kernel, kexec, rinse repeat).