06-06-2014, 05:34 PM | #1 |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
ARMhf on the Kindle(s)
An old subject, born again - -
Our plan to extend the availability of applications for the Kindle: https://bitbucket.org/twobob/kual-system That plan above will have to be altered to accommodate the hard-coded search behavior of the multi-lib'd dynamic loader. And it will have to be re-written to account for the system tree change @ v-0.3 The Quick and Dirty way to get rich with Porn <<-- Do Not Read This Spoiler -->> you might go blind. Spoiler:
PatchElf 0.8 A required utility for putting binaries outside of the FHS trusted locations. See: https://www.mobileread.com/forums/sho...88&postcount=9 Usage examples: See the commented script in the "helpers" attachment. Version 0.5 Add "Ledger v3.0" from Debian/Jessie This will also add-in fairly complete C++ application support. Version 0.4 Add ld.so audit support. Package up the -dev files add-on. Version 0.3 Note to self and others: Do not try to package and release new system libraries on Friday the 13th. Replaced Lua-5.1.5 with LuaJit-2.0.3 (which also runs Lua-5.1 code and source) in base system. Added nano-2.3.2 (because I hate busybox vi - which is still there). Redefined our external, hard-float, system tree. Installation and Usage: https://www.mobileread.com/forums/sho...1&postcount=47 Coding example: https://www.mobileread.com/forums/sho...2&postcount=56 Note: Only tested on KPW-1, firmware 5.3.3 Linaro toolchain: http://releases.linaro.org/14.05/com...gcc-linaro/4.9 Older stuff: "Plan B" died a horrible death at V-0.2.2 - see: https://www.mobileread.com/forums/sho...7&postcount=46 Spoiler:
Last edited by knc1; 06-16-2014 at 07:11 AM. |
06-06-2014, 06:44 PM | #2 |
BLAM!
Posts: 13,494
Karma: 26047188
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
|
You'll also have to push the full hardf libc suite matching the TC used to the libdir the rpath points to, or things will go kaboom in fun & interesting ways .
|
Advert | |
|
06-06-2014, 08:52 PM | #3 | |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Quote:
Note: These lists are from the (dead) V-0.2.x series of builds. Spoiler:
Which will need a little bit of post-build fix-up. Busybox, Lua and C++ additions: Spoiler:
Which will also need to be diddled. And our starter-pack of two applications: Spoiler:
Actually, worse than it looks - the Buildroot Lua package is broken (ignoring the LDFLAGS setting in BR GUI). Note: I may decide that 'Ledger' will be part of the base install (for tracking what is installed and in-use). Last edited by knc1; 06-14-2014 at 10:04 AM. |
|
06-06-2014, 09:42 PM | #4 | |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Quote:
Spoiler:
Edit: This libc has the default loader hardcoded, but since it is a library, it doesn't seem to matter. I will put building a "patchelf" high on my todo list to have on hand, just in case it does matter. Ref: http://anonscm.debian.org/gitweb/?p=....git;a=summary (Which happens to be written in C++, one of this thread's goals to support.) Last edited by knc1; 06-07-2014 at 08:48 AM. |
|
06-07-2014, 08:49 AM | #5 |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
The original top post - for sake of history
This is **not** the specific plan being followed now!!
This is (was) the starting point of this thread. The links and general information here are relevant, most of the build details are not. = = = = *) Picked a build system to use (Buildroot, v2014.05, see: http://buildroot.net/download.html) *) Leaving that local repo copy alone, clone it (disk-to-disk) into a workplace that can be easily sacrificed when things go really wrong. *) If this isn't the first time using the above sacrificial clone, do: make clean *) Use the 'make menuconfig' command to select arch and toolchain options. Here, I am using the 'Cortex-A8' selection, with EABIhf Selected C++ support, since we want to support C++ sources. *) Also selected: Linux headers: 3.0 (I may have to change that, but that is as old as this version goes without patching it). BinUtils: 2.23.2 gcc: 4.8.2 glibc: 2.19 *) Let Buildroot do its thing about creating this toolchain: make toolchain *) Now, to funky up the build system options to create binaries that reference our (hard float) dynamic loader and hard float libraries (which will live in USB storage). make menuconfig Set the "Target Linker Options" to this god-awful looking thing: Code:
-Wl,--dynamic-linker=/mnt/us/extensions/system/lib/ld-2.19.so,-rpath=/mnt/us/extensions/system/lib,--enable-new-dtags When the kernel is told to run an executable, it: Reads the executable's header and finds that it is dynamically linked - Then it reads the header to find out what dynamic loader to use (our hard float dynamic loader: ld-2.19.so, not Amazon's old soft float dynamic loader) - The kernel then loads and runs that dynamic loader, passing along the information on what should be loaded and run. Yup - thats it, the kernel never "runs" the executable you requested, it only runs the dynamic loader and lets ld.so worry about the details. *) Build a dynamically linked BR application (Busybox, since it is already set-up by default): make busybox *) Use readelf to see if things are looking at least reasonable: Code:
core2quad bin $ readelf -dl busybox Elf file type is EXEC (Executable file) Entry point 0xdbd0 There are 8 program headers, starting at offset 52 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align EXIDX 0x092a20 0x0009aa20 0x0009aa20 0x00008 0x00008 R 0x4 PHDR 0x000034 0x00008034 0x00008034 0x00100 0x00100 R E 0x4 INTERP 0x000134 0x00008134 0x00008134 0x00029 0x00029 R 0x1 [Requesting program interpreter: /mnt/us/extensions/system/lib/ld-2.19.so] LOAD 0x000000 0x00008000 0x00008000 0x92a2c 0x92a2c R E 0x8000 LOAD 0x093000 0x000a3000 0x000a3000 0x00782 0x02a3c RW 0x8000 DYNAMIC 0x09300c 0x000a300c 0x000a300c 0x000f8 0x000f8 RW 0x4 NOTE 0x000160 0x00008160 0x00008160 0x00020 0x00020 R 0x4 GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4 - - - - Dynamic section at offset 0x9300c contains 26 entries: Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libc.so.6] 0x0000000f (RPATH) Library rpath: [/mnt/us/extensions/system/lib] 0x0000001d (RUNPATH) Library runpath: [/mnt/us/extensions/system/lib] 0x0000000c (INIT) 0xb8c4 0x0000000d (FINI) 0x7d460 - - - - http://blog.tremily.us/posts/rpath/ And a correction, patchelf **can** edit in a longer string: http://nixos.org/patchelf.html Note: that page needs a correction also, to the correct, current, form of the load flag options. But, why all of this effort? Because with our own hard float library and library loader, then all we need is patchelf and anything from the Debian ARMhf repository can be edited to run on "our" system. **) Whoot! Looking good so far. Now just need to do some file location mangling and test if it works. (Probably not, this is the 'pre-alpha' test stage and I most likely missed some critical details.) Then, once the above (pure C source) is working, get the C++ stuff working. A nice little summer project. Last edited by knc1; 06-11-2014 at 08:08 AM. |
Advert | |
|
06-07-2014, 10:54 AM | #6 | |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
The quick and dirty on DT_tags
Pathnames:
There are two pathname tags of interest in runtime dynamic loading. There is also an (un-documented) maximum string length limit. Which was the death of the V-0.2 series of builds. Two tags, four cases: 0) Neither (the default linker output) 1) DT_RPATH (only) 2) DT_RUNPATH (only) 3) Both For case #3 (Both), the DT_RPATH tag is ignored and the DT_RUNPATH is used (I.E: Collapses into a case #2). Case 1: DT_RPATH (only) Provides the path(s) to be searched for the NEEDED soname libraries. This path is used in all searches, it is not restricted to the imports of the ELF file it appears in. This tag **DOES** over-ride LD_LIBRARY_PATH environment settings. Case 2: DT_RUNPATH (only or both) Provides the path(s) to be searched for the NEEDED soname libraries. This path is used ONLY for searching for the imports of the ELF file it appears in. I.E: Its scope is the current file requesting the import of other soname libraries. This tag **DOES NOT** over-ride LD_LIBRARY_PATH environment settings. All cases (including Case 0): Unless over-ridden, the loader will search the system directories: /lib and /usr/lib. (Which is useless for this thread, those are all soft-float libraries that we can not link with.) Filenames: Linux (and all *nix systems) follow a library naming convention that includes the ABI and library version in the visible filename. Details: http://tldp.org/HOWTO/Program-Librar...libraries.html The internal (DT_SONAME) of the library is the load-time, actual, name of the library. For instance: Code:
Dynamic section at offset 0xaf04 contains 23 entries: Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libc.so.6] 0x0000000e (SONAME) Library soname: [libbsd.so.0] Quote:
And the (symbol) imports should be found in the file with the internal (soname) [lib] c [.so] [.6] code, regardless of its external name on the file system. In the above case, the name of this file on the file system is: Code:
core2quad lib $ ls -l libbsd.so.0.3.0 -rw-r--r-- 1 root root 46744 2011-06-04 01:19 libbsd.so.0.3.0 On file systems which support symbolic links, the soname appears on the file system as a symbolic link to the fully versioned binary. Code:
core2quad lib $ ls -l libbsd.so.0* lrwxrwxrwx 1 root root 15 2012-06-07 22:06 libbsd.so.0 -> libbsd.so.0.3.0 -rw-r--r-- 1 root root 46744 2011-06-04 01:19 libbsd.so.0.3.0 * Rename the fully versioned binary to the soname (what I did in version-0.1 to the libc library) or * Leave the binary with its fully versioned name and just let the loader search for it. (or Get the loader to use a cache file in a non-standard location. That could be done, but might not be worth the effort to maintain. This is a slow e-book not a high-performance machine. ) - - - - - Unrelated to dynamic loading, there is another naming convention used by the build-time linker. From the -lbsd option passed to the compiler/linker - The "-l" specifies a name mangling that adds the 'lib' prefix and the '.so' dynamic library extension. The build-time linker then searchs for: libbsd.so for the code to link. On Linux (and other *nix) development systems, this name will also be a symbolic link to the fully versioned filename of the library binary. But FAT32 does not do symbolic links. Does that mean we can't do program development on FAT32 - No (Although it certainly isn't recommended, it can be done. ) Creating a file named: libbsd.so with the contents: Code:
INPUT(libbsd.so.0.3.0) Will keep the build-time linker happy. Edit: Could I patch ld.so to follow the same convention? Interesting thought (and it might already do it, will have to read the source). Last edited by knc1; 06-14-2014 at 10:06 AM. |
|
06-08-2014, 09:34 AM | #7 | |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Quote:
The Buildroot variable $O is part of the vary basic structure of the build system, there is no escaping it in the ld.so token: $ORIGIN. The answer: Build with an un-modified Buildroot, use patchelf as required on the resulting binaries. Ref: https://github.com/NixOS/patchelf Progress Note: After 14 hours of beating head against wall (wall being the glibc-2.19 multi-lib loader) - This is the best I have come up with for its search behavior: Code:
[root@kindle bin]# LD_DEBUG=libs ./busybox 17626: find library=libc.so.6 [0]; searching 17626: search path=/mnt/us/extensions/system/lib/tls/v7l/neon/vfp:/mnt/us/extensions/system/lib/tls/v7l/neon:/mnt/us/extensions/system/lib/tls/v7l/vfp:/mnt/us/extensions/system/lib/tls/v7l:/mnt/us/extensions/system/lib/tls/neon/vfp:/mnt/us/extensions/system/lib/tls/neon:/mnt/us/extensions/system/lib/tls/vfp:/mnt/us/extensions/system/lib/tls:/mnt/us/extensions/system/lib/v7l/neon/vfp:/mnt/us/extensions/system/lib/v7l/neon:/mnt/us/extensions/system/lib/v7l/vfp:/mnt/us/extensions/system/lib/v7l:/mnt/us/extensions/system/lib/neon/vfp:/mnt/us/extensions/system/lib/neon:/mnt/us/extensions/system/lib/vfp:/mnt/us/extensions/system/lib (RUNPATH from file ./busybox) 17626: trying file=/mnt/us/extensions/system/lib/tls/v7l/neon/vfp/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/tls/v7l/neon/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/tls/v7l/vfp/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/tls/v7l/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/tls/neon/vfp/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/tls/neon/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/tls/vfp/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/tls/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/v7l/neon/vfp/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/v7l/neon/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/v7l/vfp/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/v7l/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/neon/vfp/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/neon/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/vfp/libc.so.6 17626: trying file=/mnt/us/extensions/system/lib/libc.so.6 17626: 17626: 17626: calling init: /mnt/us/extensions/system/lib/libc.so.6 17626: 17626: 17626: calling init: /usr/lib/libenvload.so 17626: 17626: 17626: initialize program: ./busybox 17626: 17626: 17626: transferring control: ./busybox 17626: BusyBox v1.22.1 (2014-06-08 17:55:06 CDT) multi-call binary. BusyBox is copyrighted by many authors between 1998-2012. Licensed under GPLv2. See source distribution for detailed copyright notices. Usage: busybox [function [arguments]...] or: busybox --list[-full] or: busybox --install [-s] [DIR] or: function [arguments]... BusyBox is a multi-call binary that combines many common Unix utilities into a single executable. Most people will create a link to busybox for each function they wish to use and BusyBox will act like whatever it was invoked as. Currently defined functions: [, [[, addgroup, adduser, ar, arping, ash, awk, basename, blkid, bunzip2, bzcat, cat, catv, chattr, chgrp, chmod, chown, chroot, chrt, chvt, cksum, clear, cmp, cp, cpio, crond, crontab, cut, date, dc, dd, deallocvt, delgroup, deluser, devmem, df, diff, dirname, dmesg, dnsd, dnsdomainname, dos2unix, du, dumpkmap, echo, egrep, eject, env, ether-wake, expr, false, fdflush, fdformat, fgrep, find, fold, free, freeramdisk, fsck, fstrim, fuser, getopt, getty, grep, gunzip, gzip, halt, hdparm, head, hexdump, hostid, hostname, hwclock, id, ifconfig, ifdown, ifup, inetd, init, insmod, install, ip, ipaddr, ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kill, killall, killall5, klogd, last, less, linux32, linux64, linuxrc, ln, loadfont, loadkmap, logger, login, logname, losetup, ls, lsattr, lsmod, lsof, lspci, lsusb, lzcat, lzma, makedevs, md5sum, mdev, mesg, microcom, mkdir, mkfifo, mknod, mkswap, mktemp, modprobe, more, mount, mountpoint, mt, mv, nameif, netstat, nice, nohup, nslookup, od, openvt, passwd, patch, pidof, ping, pipe_progress, pivot_root, poweroff, printenv, printf, ps, pwd, rdate, readlink, readprofile, realpath, reboot, renice, reset, resize, rm, rmdir, rmmod, route, run-parts, runlevel, sed, seq, setarch, setconsole, setkeycodes, setlogcons, setserial, setsid, sh, sha1sum, sha256sum, sha3sum, sha512sum, sleep, sort, start-stop-daemon, strings, stty, su, sulogin, swapoff, swapon, switch_root, sync, sysctl, syslogd, tail, tar, tee, telnet, test, tftp, time, top, touch, tr, traceroute, true, tty, udhcpc, umount, uname, uniq, unix2dos, unlzma, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, vlock, watch, watchdog, wc, wget, which, who, whoami, xargs, xz, xzcat, yes, zcat 17626: 17626: calling fini: ./busybox [0] 17626: 17626: 17626: calling fini: /usr/lib/libenvload.so [0] 17626: [root@kindle bin]# #16 is where I actually put it (and told the loader to look there). Last edited by knc1; 06-08-2014 at 09:07 PM. |
|
06-08-2014, 09:39 AM | #8 |
BLAM!
Posts: 13,494
Karma: 26047188
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
|
Tiny nitpick about #6: I think you meant -l, not -L, the uppercase one is for tweaking the link time libdir searchpath . (like what -I does for headers at compile time).
Neat idea to use linker scripts though, especially if the dynamic loader can be coerced into parsing those . Last edited by NiLuJe; 06-12-2014 at 10:53 AM. |
06-09-2014, 10:16 AM | #9 |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
PatchElf for I386 - Details
No way out of it - this is a "must have" utility.
Until Buildroot can create a host-patchelf utility, here is a hand built version. This build passes all of its own self-tests. Ref: http://nixos.org/patchelf.html https://github.com/NixOS/patchelf/archive/0.8.zip Repo: git clone https://github.com/NixOS/patchelf.git patchelf.git Short description: Code:
core2quad src $ file /usr/local/bin/patchelf /usr/local/bin/patchelf: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped Code:
cd /usr/local tar --create --gzip --file=patchelf-0.8.tar.gz \ share/doc/patchelf/README \ share/man/man1/patchelf.1 \ bin/patchelf Spoiler:
Find the most recent build attached at post #1 of this thread. Last edited by knc1; 06-09-2014 at 10:20 AM. |
06-10-2014, 12:09 AM | #10 | |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Quote:
"Enhancing" that thing will have to wait. Too much time for too little result - will just "make do" for now. |
|
06-10-2014, 08:06 PM | #11 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
Possibly the most awesome post I have read in months.
Okay the only post I have read in months, and it is awesome. Amazing work. |
06-10-2014, 09:37 PM | #12 |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Thanks.
And welcome back. Glad to see that "life" has let you have some hobby time again. - - - - In other news (about the missing): https://www.mobileread.com/forums/sho...&postcount=901 |
06-10-2014, 10:25 PM | #13 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
hah... classic tunes.
Yeah. life. sure does stomp all over you when you least expect it. I'm going to get a raspberry pi tomorrow to test out the hardfloat stuff. if that helps any? |
06-10-2014, 10:47 PM | #14 | |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Quote:
You will find a lot of support for Rpi has been added. Members from two of the commercial users of BR are pushing a lot of that support into the tree. |
|
06-10-2014, 10:57 PM | #15 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
excellent.
it's silly o clock here so time to collapse. will give that a once over then. thank knc1. you are , eternally, the man. |
Tags |
armhf |
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Kindle Nicknaming Scheme, Using Kindle with Calibre, and Hacking the Kindle | Klif | Amazon Kindle | 11 | 09-12-2012 05:11 PM |
$0.01 in Kindle Store: Interactive Sudoku for Kindle 2 and Kindle DX - Volume 1 | Xia | Deals and Resources (No Self-Promotion or Affiliate Links) | 2 | 11-07-2009 10:06 AM |