Skip to content

Instantly share code, notes, and snippets.

@rvagg
Last active October 23, 2023 17:55
Star You must be signed in to star a gist
Save rvagg/5095506 to your computer and use it in GitHub Desktop.
Kindleberry "Paperwhite" Pi

Work in progress, I'll write this up properly when I'm done.

Almost all credit goes to @maxogden for putting me on to this and pointing me in the right direction for each of these items.

Prerequisites:

  • Raspberry Pi
  • Kindle Paperwhite freed from its locked down state (jailbroken) http://www.mobileread.com/forums/showthread.php?t=198446
    • You have to downgrade your Kindle to 5.3.1 to install the current jailbreak; that's just a matter of getting the old version image, putting it on your Kindle via USB and telling it to install "upgrade". Then you put in the Jailbreak files, load the ebook and break.
    • Your kindle will be quick to detect an upgrade is available so it'll want to upgrade soon afterwards but the jailbreak will last but you have to reinstall the developer certificates so it's a bit of a pain but doable. Find all the instructions on the mobileread.com forums and wiki.
    • Install SSH to work over wifi http://wiki.mobileread.com/wiki/Kindle_Touch_Hacking#SSH_access_over_Wifi I disabled USBNet because I want to use my Kindle as normal via USB but SSH via Wifi is enabled full-time so I can log in to it whenever I like. I also have my pubkey in authorized_keys.
  • Kindle Unified Application Launcher (KUAL) http://www.mobileread.com/forums/showthread.php?t=203326
  • Extend - additional command line tools, including a proper openssh client http://wiki.mobileread.com/wiki/Kindle_Touch_Hacking#Additional_command-line_tools:_.22Extend.22 - this was a pain to get right, the install instructions aren't great but you need to end up with a mount.sh and unmount.sh that mount and unmount the extra stuff in /opt/.
  • KTerm https://github.com/bfabiszewski/kterm - grab the custom build @maxogden requested for landscape mode here: bfabiszewski/kterm#2 (comment) - you need to set this up in KUAL in the /mnt/us/extensions/ directory so you can launch "kterm" from the launcher.
  • Automatic console login on the Raspberry Pi, put this in your /etc/inittab in place of the existing 1: entry: 1:2345:respawn:/bin/login -f <YOURUSERNAME> tty1 /dev/tty1
  • Automatic screen session start on login on your Pi, put this in your ~/.bash_profile:
if [ -z "$STY" ];  then
    exec screen -xR
fi

Hint: type ~ds into the search bar on the Kindle to disable screensaver while you're working. A reboot will undo this.

Keyboard toggle

Note that there is a kterm commandline option to toggle the keyboard (-k0) but for the current build of landscape kterm it doesn't quite work properly so I prefer to leave the keyboard showing on startup and then tap with 2 fingers and select "Toggle keyboard" to get rid of it. The 2 finger tap will also let you kill the kterm and toggle a few other things.

Running in screen

Remember that you're only using screen for the shared session so doing Ctrl-A stuff to switch windows is going to cause problems because your Pi console might switch but your Kindle terminal won't so you'll be out of sync. Just use it as a single console. Use Ctrl-Z and fg %X to switch between programs and you'll be fine.

Terminal size

Because the terminal size is kind of awkward, especially when you change the font size, you'll probably want to set your terminal width settings with the stty command, mainly for the "columns". For the font size I like I've found that a column width of 72 does the trick so things fit on properly and I get proper wrapping: stty columns 72. You may want to tinker with this a little to make it just right for you. You may also need to restart your kterm session and/or restart programs you have running to make them adjust properly.

The following files need to be placed in this structure:

/mnt/us/extensions/kindleberrypi/config.xml
/mnt/us/extensions/kindleberrypi/menu.json
/mnt/us/extensions/kindleberrypi/etc/id
/mnt/us/extensions/kindleberrypi/bin/kindleberrypi.sh

Node.js on Kindle

I finally have a good cross-compiler working. I'll write up the details of this when I have time, but for now I can distribute Node.js binaries. I gave up on 0.8.x, there were too many V8 issues to deal with, mainly regarding soft floating-point stuff. The V8 in 0.9.x/0.10 clean that all up and there's even a libuv change that means it's a fairly straightforward compile.

Because of the filesystem on the Kindle, permissions don't work (it's FAT or some variant) which throws Node, and particularly npm into a fit. So instead, I've set up a 250Mb image file that can be mounted in /opt/node/ where everything can be stored and Node apps can be installed & run. There's nothing stopping you from using the standard /mnt/us/ filesystem for storing data as long as permissions aren't a problem for your use-case.

Here is the mountable image, compressed. You'll need to gunzip it before you transfer it to your Kindle. Place it in /mnt/us/ and then make a mount script, /mnt/us/noodlemount.sh:

#!/bin/sh

mkdir -p /opt
mkdir -p /opt/node/
mount -o loop,noatime -t ext3 /mnt/us/noodle.img /opt/node

Run it and you'll have /opt/node/ with all the goodies I've put on the image.

Then you'll probably want to export PATH=${PATH}:/opt/node/bin and then you have a working Node & npm installation.

npm set tmp /tmp/ will fix some npm install problems because by default it tries to use ~/tmp which has permissions problems (while /tmp is a tmpfs where permissions work fine).

The most reliable way to install global modules is to cd /opt/node/lib and npm install <module> from there.

I've installed a precompiled version of LevelUP in the global modules directory so you can even run LevelDB in your Node apps on your Kindle! Ping me if you want a compiled version of a Node binary add-on, my cross-compiler seems to be working well now for those.

Disable internet accessibility check

See this thread:

$ touch /mnt/us/WIFI_NO_NET_PROBE
$ restart wifid
<?xml version="1.0" encoding="UTF-8"?>
<extension>
<information>
<name>kindleberrypi</name>
<version>0.0</version>
<author>rvagg</author>
<id>kindleberrypi</id>
</information>
<menus>
<menu type="json" dynamic="true">menu.json</menu>
</menus>
</extension>
# THIS FILE NEEDS TO BE YOUR PRIVATE SSH KEY, THE PERMS ARE 644 AND IT'S HARD TO SECURE SO IT MAY BE BEST TO MAKE A SPECIAL KEYPAIR FOR THIS LOGIN
#!/bin/sh
# where kterm is installed
KTERM=/mnt/us/extensions/kterm/
# colour scheme, 0=black on white, 1=white on black
COLOUR=1
# font size
FONT=7
# username on your Pi
USER=username
# hostname of your Pi
HOST=hostname
# run the Extend commands to mount /opt/ so we can get to /opt/bin/ssh
/mnt/us/extend/unmount.sh
/mnt/us/extend/mount.sh
# copy the privkey to a place where we can set the perms to 600 to make ssh happy
cp /mnt/us/extensions/kindleberrypi/etc/id /var/tmp/_id
chmod 600 /var/tmp/_id
# set orientation to landscape
lipc-set-prop com.lab126.winmgr orientationLock R
#
${KTERM}/bin/kterm -c ${COLOUR} -s ${FONT} -e "/opt/bin/ssh -o StrictHostKeyChecking=no -i /var/tmp/_id -l ${USER} ${HOST}"
# run after exit to make sure the keyboard is gone
killall matchbox-keyboard
{
"items": [
{"name": "kindleberrypi", "priority": 1, "action": "bin/kindleberrypi.sh"}
]
}
@dnk8n
Copy link

dnk8n commented Jun 21, 2013

Will this method be able to work with Kindle 3 (WiFi only, no 3g)?

@phoenixg
Copy link

phoenixg commented Jan 6, 2014

Does it(kindleberry tutorial) support kindle paperwhite 2?

@aokolovskis
Copy link

Im also trying to get it working on the PW2.

@alairs
Copy link

alairs commented Mar 3, 2014

Edited inittab file belongs to kindle or belong Raspberry Pi?

@alairs
Copy link

alairs commented Mar 3, 2014

@madtrapper
Copy link

Could you provide some cross-compiler you used for compile node.js?
Thanks.

@vekexasia
Copy link

the nodejs binary is ineffective :(

@marcosscriven
Copy link

I was searching for a way to use a Kindle as a second terminal rather than only terminal, so was curious how you got a physical keyboard working with it. My understanding is in this case you're just screening into a session that would be visible on the Pi as well, if it were plugged into a screen.

Just wondered if you knew of a way to choose which terminal to send keyboard input to, so one session could be on a laptop or Pi screen, and a separate terminal on the Kindle?

@byarmis
Copy link

byarmis commented Jan 3, 2018

So this may be a shot in the dark-- I have everything up and working, the only problem is that after I SSH into my Pi, I end up with a dashed line across the bottom, a couple rows up. I was just wondering if you ran into this issue and what you did to solve it. I tried setting stty rows to be larger both on the Kindle as well as on the Pi with the only change being on the Pi with rows flowing off the top of the screen without anything changing on the bottom. I've also tried doing <C-a> ` to have screen re-flow the terminal window with no change.

The one thing that I can do to get any sort of change is to press with two fingers and reset the terminal in KTerm. This removes the dashed line and allows the command prompt to scroll past where it was, but when I open up something like top, vim, or anything else that takes up the "full" terminal window, it only goes as far down as where the dashed line was.

Edit: I got it working by manually setting the resolution in /boot/config.txt to 800 x 600 (Kindle Touch) and then playing with stty cols

@ironblaster
Copy link

hi sorry, I installed usbnetwork and kterm all right, when I try to use the ssh command on kindle it returns / bin / sh: ssh: not found.
also thanks to usbnetwork I can't get usb as a drive on pc. XD
do you have any idea? am I completely idiotic and isn't the ssh command to be given by kindle? this is not very clear

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment