View Single Post
Old 10-08-2020, 02:20 PM   #9
katadelos
rm -rf /
katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.
 
Posts: 219
Karma: 3333683
Join Date: Nov 2019
Location: United Kingdom
Device: K5, KT, KT2, KT3, KT4, KV, PW2, PW3, PW4, PW5
An update to this - it's fairly trivial to build a kernel with the kexec call and /proc/atags enabled, but I've not been able to use the userspace tools to switch to a different kernel. Here are the steps that you should follow if you want to try this yourself; I used NiLuJe's toolchain for this.
  • Download the GPL release for your PW3 version here from here
  • Extract the kernel source from within the tar.gz archive
  • Apply this patch (otherwise the build will fail).
  • Load the base kernel .config for the PW3:
    make ARCH=arm CROSS_COMPILE=arm-kindlepw2-linux-gnueabi- imx60_wario_defconfig
  • Add these options to the kernel config:
    CONFIG_KEXEC=y
    CONFIG_ATAGS_PROC=y
  • Build a kernel uImage (you need to set LOCALVERSION to an empty variable if you've initialised a git repo inside the kernel source folder, otherwise the kernel name will be 3.0.35-lab126+ and you'll cause a boot loop when the kernel can't find a kernel module folder with the appended "+" ):
    make ARCH=arm CROSS_COMPILE=arm-kindlepw2-linux-gnueabi- LOCALVERSION= uImage
  • Reboot PW3 into fastboot mode:
    idme -d --bootmode fastboot; reboot
  • Flash kernel uImage to PW3:
    sudo ./fastboot flash kernel uImage
  • Change back to main boot mode:
    sudo ./fastboot setvar bootmode main
  • Reboot the PW3
    sudo ./fastboot reboot
The PW3 should now be running your custom kernel. From here, it gets a bit murkier - the original instructions for kexec stuff mention grabbing a copy of the kexec binary from the Debian armel kexec-tools package.

There's 2 versions of this with differing features - one is from v2.0.3 and the other from v2.0.7. The latter requires you to specify the --atags flag because the kernel sources for the PW3 (and all other Kindles?) do not include DTS/DTB files.

Here's the commands that I used when attempting to load a different kernel (you can get the kernel boot commands from /proc/cmdline):
Code:
./kexec \
  -l /mnt/us/uImage \
  --type uImage \
  --atags \ #remove this for v2.0.3
  --command-line="rootwait log_pos_goal=0x8fff0000 console=ttymxc0,115200 root=/dev/mmcblk0p1 ro ip=off debug ignore_loglevel video=mxcepdcfb:E60,bpp=8,x_mem=3M"
./kexec -e
Regardless of which version you use, kexec will cause the Kindle to halt when you attempt to execute the new kernel - 2.0.3 will halt silently after outputting Starting new kernel and 2.0.7 will cause a kernel panic, output a stack trace to the serial console and reboot after around 40 seconds:

Spoiler:
[root@kindle us]# ./kexec -d -l /root/kernels/uImage --type uImage --atags --command-line="rootwait log_pos_goal=0x8fff0000 console=ttymxc0,115200 root=/dev/mmcblk0p1 ro ip=off debug ignore_loglevel video=mxcepdcfb:E60,bpp=8,x_mem=3M"
kernel: 0x40280008 kernel_size: 0x24c71c
kexec_load: entry = 0x80008000 flags = 0x280000
nr_segments = 2
segment[0].buf = 0x45068
segment[0].bufsz = 0xe4
segment[0].mem = 0x80001000
segment[0].memsz = 0x1000
segment[1].buf = 0x40280048
segment[1].bufsz = 0x24c6dc
segment[1].mem = 0x80008000
segment[1].memsz = 0x24d000
[root@kindle us]# ./kexec -e
[ 252.725856] imx2-wdt imx2-wdt.0: Device shutdown: Expect reboot!
[ 252.731913] Starting new kernel
[ 252.842635] Unable to handle kernel paging request at virtual address ffe00000
[ 252.850123] Unhandled fault: external abort on non-linefetch (0x008) at 0x06926cae
[ 252.857940] Internal error: : 8 [#1] PREEMPT
[ 252.862400] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 252.870293] Internal error: : 1808 [#2] PREEMPT
[ 252.875011] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 252.882900] Internal error: : 1808 [#3] PREEMPT
[ 252.887621] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 252.895511] Internal error: : 1808 [#4] PREEMPT
[ 252.900228] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 252.908117] Internal error: : 1808 [#5] PREEMPT
[ 252.912836] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 252.920726] Internal error: : 1808 [#6] PREEMPT
[ 252.925444] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 252.933333] Internal error: : 1808 [#7] PREEMPT
[ 252.938057] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 252.945940] Internal error: : 1808 [#8] PREEMPT
[ 252.950659] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 252.958542] Internal error: : 1808 [#9] PREEMPT
[ 252.963264] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 252.971149] Internal error: : 1808 [#10] PREEMPT
[ 252.975961] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 252.983846] Internal error: : 1808 [#11] PREEMPT
[ 252.988655] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 252.996538] Internal error: : 1808 [#12] PREEMPT
[ 253.001347] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.009233] Internal error: : 1808 [#13] PREEMPT
[ 253.014041] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.021923] Internal error: : 1808 [#14] PREEMPT
[ 253.026728] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.034611] Internal error: : 1808 [#15] PREEMPT
[ 253.039419] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.047301] Internal error: : 1808 [#16] PREEMPT
[ 253.052105] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.059986] Internal error: : 1808 [#17] PREEMPT
[ 253.064804] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000173
[ 253.072683] Internal error: : 1808 [#18] PREEMPT
[ 253.077485] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.085363] Internal error: : 1808 [#19] PREEMPT
[ 253.090163] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.098043] Internal error: : 1808 [#20] PREEMPT
[ 253.102844] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.110739] Internal error: : 1808 [#21] PREEMPT
[ 253.115538] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.123408] Internal error: : 1808 [#22] PREEMPT
[ 253.128204] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.136073] Internal error: : 1808 [#23] PREEMPT
[ 253.140869] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.148737] Internal error: : 1808 [#24] PREEMPT
[ 253.153533] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.161401] Internal error: : 1808 [#25] PREEMPT
[ 253.166198] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.174066] Internal error: : 1808 [#26] PREEMPT
[ 253.178866] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.186741] Internal error: : 1808 [#27] PREEMPT
[ 253.191542] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.199415] Internal error: : 1808 [#28] PREEMPT
[ 253.204216] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.212090] Internal error: : 1808 [#29] PREEMPT
[ 253.216892] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.224766] Internal error: : 1808 [#30] PREEMPT
[ 253.229568] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.237441] Internal error: : 1808 [#31] PREEMPT
[ 253.242242] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.250116] Internal error: : 1808 [#32] PREEMPT
[ 253.254916] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.262788] Internal error: : 1808 [#33] PREEMPT
[ 253.267590] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.275464] Internal error: : 1808 [#34] PREEMPT
[ 253.280266] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.288138] Internal error: : 1808 [#35] PREEMPT
[ 253.292941] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.300813] Internal error: : 1808 [#36] PREEMPT
[ 253.305617] Unhandled fault: external abort on non-linefetch (0x008) at 0x1b478597
[ 253.313419] Internal error: : 8 [#37] PREEMPT
[ 253.317962] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.325846] Internal error: : 1808 [#38] PREEMPT
[ 253.330649] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.338536] Internal error: : 1808 [#39] PREEMPT
[ 253.343342] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.351227] Internal error: : 1808 [#40] PREEMPT
[ 253.356032] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.363918] Internal error: : 1808 [#41] PREEMPT
[ 253.368723] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.376607] Internal error: : 1808 [#42] PREEMPT
[ 253.381413] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.389300] Internal error: : 1808 [#43] PREEMPT
[ 253.394107] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.401993] Internal error: : 1808 [#44] PREEMPT
[ 253.406798] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.414685] Internal error: : 1808 [#45] PREEMPT
[ 253.419495] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.427379] Internal error: : 1808 [#46] PREEMPT
[ 253.432187] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.440058] Internal error: : 1808 [#47] PREEMPT
[ 253.444861] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.452730] Internal error: : 1808 [#48] PREEMPT
[ 253.457533] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.465404] Internal error: : 1808 [#49] PREEMPT
[ 253.470206] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.478074] Internal error: : 1808 [#50] PREEMPT
[ 253.482875] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.490742] Internal error: : 1808 [#51] PREEMPT
[ 253.495544] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.503412] Internal error: : 1808 [#52] PREEMPT
[ 253.508215] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.516083] Internal error: : 1808 [#53] PREEMPT
[ 253.520883] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.528752] Internal error: : 1808 [#54] PREEMPT
[ 253.533554] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.541421] Internal error: : 1808 [#55] PREEMPT
[ 253.546220] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000174
[ 253.554086] Internal error: : 1808 [#56] PREEMPT
[ 253.558840] Modules linked in: ath6kl_sdio cfg80211 g_ether arcotg_udc cyttsp4_mt_b mxc_epdc_fb mxc_epdc_eink(P) cyttsp4_core cyttsp4_i2c fuse ehci_hcd fsl_otg_arc [last unloaded: g_file_storage]
[ 253.577265] CPU: 0 Tainted: P (3.0.35-lab126 #9)
[ 253.583425] PC is at __rcu_read_lock+0x24/0x2c
[ 253.588085] LR is at atomic_notifier_call_chain+0x20/0x50
[ 253.593720] pc : [<c00a4540>] lr : [<c0089390>] psr: 200001d3
[ 253.593838] sp : ffdfa218 ip : ffdfa228 fp : ffdfa224
[ 253.605523] r10: 00000001 r9 : 200001d3 r8 : 00000000
[ 253.610938] r7 : 00001808 r6 : ffdfa254 r5 : 00000001 r4 : c04e1860
[ 253.617671] r3 : 698a604b r2 : 00000000 r1 : 00000001 r0 : c04e1860
[ 253.624425] Flags: nzCv IRQs off FIQs off Mode SVC_32 ISA ARM Segment user
[ 253.631958] Control: 10c52c79 Table: 99914059 DAC: 00000015
[ 253.637898] Process (pid: -473747393, stack limit = 0xffdfa2e8)
[ 253.644190] Stack: (0xffdfa218 to 0xe34c704d)
[ 253.648671] Backtrace: invalid frame pointer 0xffdfa224
[ 253.654272] Unable to handle kernel paging request at virtual address e582334c
[ 253.661711] Unhandled fault: external abort on non-linefetch (0x008) at 0x42698af8
[ 253.669495] Internal error: : 8 [#57] PREEMPT
[ 253.674049] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000175
[ 253.681914] Internal error: : 1808 [#58] PREEMPT
[ 253.686723] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000175
[ 253.694587] Internal error: : 1808 [#59] PREEMPT
[ 253.699397] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000175
[ 253.707259] Internal error: : 1808 [#60] PREEMPT
[ 253.712068] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000175
[ 253.719932] Internal error: : 1808 [#61] PREEMPT
[ 253.724748] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000175
[ 253.732622] Internal error: : 1808 [#62] PREEMPT
[ 253.737437] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000175
[ 253.745309] Internal error: : 1808 [#63] PREEMPT
[ 253.750122] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000175
[ 253.757996] Internal error: : 1808 [#64] PREEMPT
[ 253.762809] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000175
[ 253.770682] Internal error: : 1808 [#65] PREEMPT
[ 253.775496] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000175
[ 253.783370] Internal error: : 1808 [#66] PREEMPT
[ 253.788184] Unhandled fault: external abort on non-linefetch (0x1808) at 0x00000175
[ 253.796052] Internal error: : 1808 [#67] PREEMPT
[ 253.800839] Modules linked in: ath6kl_sdio cfg80211 g_ether arcotg_udc cyttsp4_mt_b mxc_epdc_fb mxc_epdc_eink(P) cyttsp4_core cyttsp4_i2c fuse ehci_hcd fsl_otg_arc [last unloaded: g_file_storage]
[ 253.819355] CPU: 0 Tainted: P (3.0.35-lab126 #9)
[ 253.825522] PC is at do_alignment_ldrstr+0xe0/0x10c
[ 253.830582] LR is at 0x23
[ 253.833409] pc : [<c004035c>] lr : [<00000023>] psr: 600001d3
[ 253.833533] sp : ffdf80e8 ip : 00000003 fp : ffdf80fc
[ 253.845233] r10: 00000801 r9 : 00000175 r8 : c00a4540
[ 253.850662] r7 : c04d6154 r6 : e5823174 r5 : 00000174 r4 : ffdf8208
[ 253.857410] r3 : 22698a61 r2 : ffdf8208 r1 : 00000000 r0 : 00000175
[ 253.864175] Flags: nZCv IRQs off FIQs off Mode SVC_32 ISA ARM Segment user
[ 253.871723] Control: 10c52c79 Table: 99914059 DAC: 00000015
[ 253.877679] Process -� (pid: 1043973861, stack limit = 0xffdf62e8)
[ 253.884167] Stack: (0xffdf80e8 to 0x00002000)
[ 253.888656] Backtrace: invalid frame pointer 0xffdf80fc
[ 253.894275] -� (1043973861): undefined instruction: pc=c004035c
[ 253.900466] Code: e1833404 e782310c e89da830 e792310c (e4c03001)
[ 253.906947] Unhandled fault: external abort on non-linefetch (0x008) at 0x100b44e3
[ 253.914742] Internal error: : 8 [#68] PREEMPT
[ 253.919272] Modules linked in: ath6kl_sdio cfg80211 g_ether arcotg_udc cyttsp4_mt_b mxc_epdc_fb mxc_epdc_eink(P) cyttsp4_core cyttsp4_i2c fuse ehci_hcd fsl_otg_arc [last unloaded: g_file_storage]
[ 253.937784] CPU: 0 Tainted: P D (3.0.35-lab126 #9)
[ 253.943951] PC is at do_alignment_ldrstr+0xa8/0x10c
[ 253.949005] LR is at 0x32
[ 253.951832] pc : [<c0040324>] lr : [<00000032>] psr: 200001d3
[ 253.951954] sp : ffdf7c10 ip : 00000003 fp : ffdf7c24
[ 253.963652] r10: 00000001 r9 : 100b44e3 r8 : c006300c
[ 253.969080] r7 : c04d6154 r6 : e59730b8 r5 : 000000b8 r4 : ffdf7d30
[ 253.975829] r3 : 00000000 r2 : ffdf7d30 r1 : 00100000 r0 : 100b44e3
[ 253.982593] Flags: nzCv IRQs off FIQs off Mode SVC_32 ISA ARM Segment user
[ 253.990139] Control: 10c52c79 Table: 99914059 DAC: 00000015
[ 253.996092] Process -� (pid: 1043973861, stack limit = 0xffdf62e8)
[ 254.002578] Stack: (0xffdf7c10 to 0x00002000)
[ 254.007070] Backtrace: invalid frame pointer 0xffdf7c24
[ 254.012679] -� (1043973861): undefined instruction: pc=c0040324
[ 254.018870] Code: e89da830 e3510000 0a00000d e3a03000 (e4d0e001)
[ 254.025161] ---[ end trace d8053e1c707e46ab ]---
[ 254.029980] Kernel panic - not syncing: Fatal exception in interrupt
[ 254.036499] Backtrace: invalid frame pointer 0xffdf7a94
HW


U-Boot 2009.08-lab126 (Oct 12 2018 - 06:10:48)

CPU: Freescale i.MX6 family TO0.0 at 996 MHz
Temperature: 44 C, calibration data 0x5bd52d5f
mx6sl pll1: 996MHz
mx6sl pll2: 528MHz
mx6sl pll3: 480MHz
mx6sl pll8: 50MHz
ipg clock : 66000000Hz
ipg per clock : 24000000Hz
uart clock : 80000000Hz
cspi clock : 60000000Hz
ahb clock : 132000000Hz
axi clock : 198000000Hz
emi_slow clock: 22000000Hz
ddr clock : 396000000Hz
usdhc1 clock : 198000000Hz
usdhc2 clock : 198000000Hz
usdhc3 clock : 198000000Hz
usdhc4 clock : 198000000Hz
MMC: FSL_ESDHC: 0,FSL_ESDHC: 1,FSL_ESDHC: 2
Board: Muscat WFO
Boot Reason: [ POR ]
Boot Device: NAND
Board Id:
S/N:
I2C: ready
DRAM: 512 MB
Using default environment

In: serial
Out: serial
Err: serial
Quick Memory Test 0x80000000, 0x1fff0000
POST done in 111 ms
Battery voltage: 4125 mV

Hit any key to stop autoboot: 0
## Booting kernel from Legacy Image at 80800000 ...
Image Name: Linux-3.0.35-lab126
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2413244 Bytes = 2.3 MB
Load Address: 80008000
Entry Point: 80008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK

Starting kernel ...


I'm not sure how to go about debugging this further but in all honesty, I'm not that bothered - if all you want to do is add kernel features that are available at compile time only, the steps above should be enough to get you going. It goes without saying that it's a very good idea to have a serial cable attached when doing any of this - it's useful for keeping an eye on the things during boot and it'll make life easier when dealing with the inevitable bricks that you'll cause when messing around with fastboot and custom kernels.
katadelos is offline   Reply With Quote