### Author Topic: Running GNU Emacs on the TI Nspire  (Read 5573 times)

0 Members and 1 Guest are viewing this topic.

#### thursagan

• LV1 Newcomer (Next: 20)
• Posts: 5
• Rating: +0/-0
##### Running GNU Emacs on the TI Nspire
« on: April 22, 2018, 07:14:23 pm »
Hi all,

I've been trying to run GNU Emacs on the TI Nspire CX for a while now. The reason being that Emacs has a powerful Calc Mode, which is described officially as "an advanced calculator and mathematical tool." That description is underplaying this mode's power as it really turns Emacs into a powerful CAS. I've even heard it called a poor man's Mathematica, which is an accurate perception.

Unfortunately, using this mode on my own TI Nspire has been nothing but a dream so far. I have tried many different approaches to get GNU Emacs to run on this calculator, but all approaches are leading to dead ends and wasted time. I will document my efforts thus far in order to present a clear picture of what I've tried and the obstacles I've run into.

Obviously, the first thing I realized is that I need to use tangrs' Linux port for the Nspire. It would probably be a nightmare to try and write my own port of Emacs to the Nspire's builtin OS. There's no reason to do that when Emacs already runs on Linux and Linux already runs on the Nspire.

So, first I thought about cross-compiling Emacs for Busybox since that seems to be the only supported distro by tangrs' Linux port. Of course, Busybox is too small to really be called a distro. This is actually part of the problem: Emacs has a lot of dependencies even when it is compiled without X support. None of the builds on the download page seems to have all of the dependencies that are usually required by Emacs. So without going into the C sources and hacking Emacs apart to remove unnecessary dependencies, it seems that Busybox is simply not a viable platform to run GNU Emacs on.

So I decided that I needed to run Emacs on a real distro, which would allow me to use a package manager to install Emacs, instead of putzing around with the compilation myself. According to the Hackspire wiki page for Linux, the have been reports of success with running Debian and Arch on the Nspire. I am more familiar with Debian so I decided to try and make a Debian rootfs for ARM which contained Emacs in the default install.

I first tried this with debootstrap. I created a minimal Debian chroot with these commands:

Code: [Select]
$sudo debootstrap --arch=armhf --foreign --variant=allmybase stretch ~/debian$ sudo cp /usr/bin/qemu-arm-static ~/debian/usr/bin$sudo chroot ~/debian qemu-arm-static /bin/bash I am using a custom debootstrap variant called allmybase which is defined in /usr/share/debootstrap/scripts/stretch as: Code: [Select] work_out_debs () {... elif doing_variant allmybase; then base="apt emacs25-nox ncdu" fi...} All I've got there is emacs25-nox (which means Emacs 25 compiled with no X support) and ncdu (for browsing the filesystem by size). Unfortunately, even with this fairly minimal setup, it was too big for my TI Nspire. In order to make more space, I had to remove many Lisp files from the Emacs installation as well as other non-critical files and utilities. After removing many such files with the aid of ncdu, I finally managed to shrink my rootfs down enough to fit on my calculator: Code: [Select] $ sudo du -sh ~/debian81M /home/my_username/debian
However, I still had a few problems at this point. How was I supposed to install my rootfs onto my calculator? I saw on the wiki that tangrs says to use Buildroot, but I could not figure out how to use Buildroot in my context. Then I found a tutorial about running Debian on the TI Nspire, but the author of the blog post only tells how to do it with a USB drive. I want to install this Debian rootfs directly to my calculator. Finally, I found this post on Omnimaga which describes the same sort of thing, but for Arch Linux. Yet it also deals with installing to and booting from a USB drive so it is not what I wanted.

After doing some more searching, I figured that I needed to turn my rootfs at ~/debian into a bootable ext2 image. I found several different ways describing how to do this, but they all had various quirks and errors when I tried to use them. The first way that I found to do this was with debirf, but I could not figure out how to use it. Or, rather, how to apply it to my situation. I also found genext2fs and it seemed to almost actually work at first. I tried running it like so:

Code: [Select]
$genext2fs -U -v -d ~/debian initrd.tns But I would get this error: Code: [Select] genext2fs: too few blocks. Note: options have changed, see --help or the man page. Finally, at this point I was wondering whether I should even use Debian. It seemed like making an ext2 image would be totally impossible and that I should just modify an existing Busybox image using fuse-ext2. I tried to do that with an xconfig build that I found on the download page, but then I remembered that this would be totally pointless since some of Emacs' dependencies were still missing from this build. Now it seems that I must use my Debian rootfs, or else just give up. I am a bit embarrassed that I can't even figure out how to dump an ext2 image from a directory, but it really seems harder than what I've experienced on other Unix systems. Anyway, I hope that someone can take the time to read this and help me out. Thanks. #### Eeems • Mr. Dictator • Administrator • LV13 Extreme Addict (Next: 9001) • Posts: 6250 • Rating: +318/-36 • little oof ##### Re: Running GNU Emacs on the TI Nspire « Reply #1 on: April 23, 2018, 01:09:34 pm » After a little digging into genext2fs I've found the code that is throwing your error: genext2fs.c#L2544 After digging a little bit, this error seems tied to the --size-in-blocks (-b) option: README.md#options Have you attempted to run it with -b 8? /e #### thursagan • LV1 Newcomer (Next: 20) • Posts: 5 • Rating: +0/-0 ##### Re: Running GNU Emacs on the TI Nspire « Reply #2 on: April 24, 2018, 03:13:47 am » After a little digging into genext2fs I've found the code that is throwing your error: genext2fs.c#L2544 After digging a little bit, this error seems tied to the --size-in-blocks (-b) option: README.md#options Have you attempted to run it with -b 8? Thanks for helping me out and finding out the cause of the error I was having. Unfortunately, now I'm getting a segfault instead: Code: [Select] $ sudo genext2fs -b 8 -U -v -d ~/debian initrd.tnssudo genext2fs -b 8 -U -v -d ~/debian initrd.tnsgenext2fs 1.4.1Segmentation fault (core dumped)
Even more strangely, when I downloaded the program and compiled it with -g to give you a stack trace, I found this error while running in gdb:

Code: [Select]
$sudo gdb ./genext2fs GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1Copyright (C) 2016 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law. Type "show copying"and "show warranty" for details.This GDB was configured as "x86_64-linux-gnu".Type "show configuration" for configuration details.For bug reporting instructions, please see:<http://www.gnu.org/software/gdb/bugs/>.Find the GDB manual and other documentation resources online at:<http://www.gnu.org/software/gdb/documentation/>.For help, type "help".Type "apropos word" to search for commands related to "word"...Reading symbols from ./genext2fs...done.(gdb) set args -b 8 -U -v -d ~/debian initrd.tns(gdb) runStarting program: /home/my_username/genext2fs/genext2fs -b 8 -U -v -d ~/debian initrd.tnsgenext2fs 1.4.1/home/my_username/genext2fs/genext2fs: Internal error, block out of range[Inferior 1 (process 16569) exited with code 01](gdb) bt fullNo stack.(gdb) quit Perhaps I need a different block size? #### Eeems • Mr. Dictator • Administrator • LV13 Extreme Addict (Next: 9001) • Posts: 6250 • Rating: +318/-36 • little oof ##### Re: Running GNU Emacs on the TI Nspire « Reply #3 on: April 24, 2018, 10:46:56 am » You may need a different block size. I'm not really up on my filesystem theory so I don't really remember how it all works. Looking into the code though I found the error: genext2fs.c#L906. From what I can read in the code, the block size must be greater than 0, greater than 8 and greater than EXT2_FIRST_INO - 1 + (nbresrvd ? 1 : 0). Where EXT2_FIRST_INO is 11. nbresrvd is set here: genext2fs.c#L3346-L3349. We aren't hitting any of those errors though. but I'm not entirely sure what we need to specify. What you should probably do is figure out the sum of the size of the files you are generating a filesystem out of and set -b and --block-size (-B) appropriately (This can be 1024, 2048 or 4096 bytes). /e #### thursagan • LV1 Newcomer (Next: 20) • Posts: 5 • Rating: +0/-0 ##### Re: Running GNU Emacs on the TI Nspire « Reply #4 on: April 24, 2018, 11:43:31 am » You may need a different block size. I'm not really up on my filesystem theory so I don't really remember how it all works. Looking into the code though I found the error: genext2fs.c#L906. From what I can read in the code, the block size must be greater than 0, greater than 8 and greater than EXT2_FIRST_INO - 1 + (nbresrvd ? 1 : 0). Where EXT2_FIRST_INO is 11. nbresrvd is set here: genext2fs.c#L3346-L3349. We aren't hitting any of those errors though. but I'm not entirely sure what we need to specify. What you should probably do is figure out the sum of the size of the files you are generating a filesystem out of and set -b and --block-size (-B) appropriately (This can be 1024, 2048 or 4096 bytes). Okay, your advice seems to have worked. I was able to make an ext2 image with the following command: Code: [Select] $ sudo ./genext2fs -B 1024 -b 83968 -U -v -d ~/debian initrd.tns
(FYI, my value for the -b option is the equivalent of 82MiB, which is just slightly above the size of my ~/debian folder)

Then I received all sorts of output in the terminal about each inode allocated. I saved the output in case you want to see it, but I'm not posting it here right now for brevity's sake.

I verified that the file was indeed an ext2 image with this command:

Code: [Select]
$file initrd.tnsinitrd.tns: Linux rev 0.0 ext2 filesystem data, UUID=00000000-0000-0000-0000-000000000000 Now all I need to know is how to make this image bootable. I.e., I need a /linuxrc file or something to boot from, right? #### Eeems • Mr. Dictator • Administrator • LV13 Extreme Addict (Next: 9001) • Posts: 6250 • Rating: +318/-36 • little oof ##### Re: Running GNU Emacs on the TI Nspire « Reply #5 on: April 24, 2018, 01:25:53 pm » Okay, your advice seems to have worked. I was able to make an ext2 image with the following command: Code: [Select] $ sudo ./genext2fs -B 1024 -b 83968 -U -v -d ~/debian initrd.tns
Awesome! glad to have helped move you forward.
Now all I need to know is how to make this image bootable. I.e., I need a /linuxrc file or something to boot from, right?
I believe so. Unfortunately I wont be much help from here as I don't have an nspire and thus haven't actually done any of this.
/e

#### Ivoah

• LV6 Super Member (Next: 500)
• Posts: 336
• Rating: +3/-0
##### Re: Running GNU Emacs on the TI Nspire
« Reply #6 on: April 24, 2018, 08:11:09 pm »
Now all I need to know is how to make this image bootable. I.e., I need a /linuxrc file or something to boot from, right?

It looks like you should be able to just send that file to the Nspire and boot using an ll2 file that looks like this:
Code: [Select]
kernel linux/zImage.tnsinitrd linux/initrd.tnsdtb linux/nspire-cx.dtb.tnscmdline root=/dev/ramboot
You'll need to change the filenames to point where you've put them on your calculator, and change the dtb line to use the correct device tree file for your model.
http://codinghobbit.no-ip.org
My Calcs:
TI-86 (now broken) $2 TI SR-56 -$0
TI-Nspire CX CAS - $152 TI-84+ Silver Edition -$56
TI-84+ Silver Edition - $0 TI-85 -$0
TI-73 Explorer VS - $10 ViewScreen -$3

#### thursagan

• LV1 Newcomer (Next: 20)
• Posts: 5
• Rating: +0/-0
##### Re: Running GNU Emacs on the TI Nspire
« Reply #7 on: April 24, 2018, 10:14:34 pm »
Now all I need to know is how to make this image bootable. I.e., I need a /linuxrc file or something to boot from, right?

It looks like you should be able to just send that file to the Nspire and boot using an ll2 file that looks like this:
Code: [Select]
kernel linux/zImage.tnsinitrd linux/initrd.tnsdtb linux/nspire-cx.dtb.tnscmdline root=/dev/ramboot
You'll need to change the filenames to point where you've put them on your calculator, and change the dtb line to use the correct device tree file for your model.

Thanks for the advice. It seems that your tip almost worked except that I get this error upon booting. Thereafter, the calculator hangs and I can't do anything without a hard reset. I can't attach the image directly because of the file size.

Do I really need to shrink my initrd as the error suggests? I don't think I can shrink it anymore than it already is without losing the stuff that I want to use...

#### thursagan

• LV1 Newcomer (Next: 20)
• Posts: 5
• Rating: +0/-0
##### Re: Running GNU Emacs on the TI Nspire
« Reply #8 on: July 12, 2018, 04:34:40 pm »
I did a little more with this issue recently. @Ivoah as per your suggestion, I whittled down the image even further all the way to ~28MiB(!), but this still wasn't enough. The bootloader still complained that the initrd was too large. At this point, I don't know what to do. TBH, Linux may not even boot at this point since I removed some libraries and utilities which may be important to the boot process (although I'm not sure). I'm really confused since, according to the bootloader homepage,  one can load ramdisks and kernels up to ~40MB on the CX. I am well under that limit and yet I still get this error...

Am I missing something? I truly don't see how I can load Debian at all under such constraints, unless I use a USB stick. Let alone Emacs! I would really appreciate any help that could be offered.