EV3 linux hacking

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
dwalton76
Posts: 4
Joined: 09 Sep 2013, 04:40

EV3 linux hacking

Post by dwalton76 »

There doesn't seem to be a thread focused on this yet so I'll start one :) I'd love to be able to write a perl or python script to program the EV3 instead of using the improved but still awful GUI programming software provided by lego.

Restoring the system
Before I venture into changing anything via the linux prompt is there anything one needs to do to restore the system other than re-image the firmware?

Writing to the filesystem
The filesystem is mounted as readonly and df claims there isn't any free space. I'm guessing one needs to insert a SD card and use that storage space for adding new software etc. I'll try that tomorrow.

Code: Select all

root@EV3:~# pwd
/home/root
root@EV3:~# whoami
root
root@EV3:~# touch foo
touch: foo: Read-only file system
root@EV3:~#
root@EV3:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                22.4M     22.4M         0 100% /
none                      1.0M     48.0K    976.0K   5% /dev
tmpfs                     2.0M      1.1M    932.0K  54% /var/volatile
tmpfs                     6.0M      1.4M      4.6M  24% /mnt/ramdisk
root@EV3:~#
Adding software
This thing is bare bones in terms of software. There is no gcc, no perl, no python, no vim, no ftp, no web server, etc. Most everything in /bin is via a busybox build from 2010

Code: Select all

root@EV3:/bin# ls -l | grep busybox
lrwxrwxrwx    1 root     root            7 Jan  1 00:00 ash -> busybox
-rwxr-xr-x    1 root     root       650588 Jan  1 00:00 busybox
lrwxrwxrwx    1 root     root            7 Jan  1 00:00 cat -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1 00:00 chgrp -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1 00:00 chmod -> busybox
lrwxrwxrwx    1 root     root            7 Jan  1 00:00 chown -> busybox
[snip]

root@EV3:/bin# ./busybox
BusyBox v1.13.2 (2010-12-21 19:28:47 CST) multi-call binary

The EV3 does however include wget and there is a  pre-built binary of busybox 1.21.1 out there:
[url]http://www.busybox.net/downloads/binaries/1.21.1/busybox-armv5l[/url]

root@EV3:~# cd /tmp
root@EV3:/var/volatile/tmp#
root@EV3:/var/volatile/tmp# wget http://www.busybox.net/downloads/binaries/1.21.1/busybox-armv5l
Connecting to http://www.busybox.net (140.211.167.224:80)
busybox-armv5l       100% |***********************************************************************************************|  1083k 00:00:00 ETA
root@EV3:/var/volatile/tmp#
root@EV3:/var/volatile/tmp# chmod 755 busybox-armv5l
root@EV3:/var/volatile/tmp# ./busybox-armv5l
BusyBox v1.21.1 (2013-07-08 10:13:48 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:
        [, [[, acpid, add-shell, addgroup, adduser, adjtimex, arp, arping, ash, awk, base64, basename, beep, blkid, blockdev, bootchartd,
        brctl, bunzip2, bzcat, bzip2, cal, cat, catv, chat, chattr, chgrp, chmod, chown, chpasswd, chpst, chroot, chrt, chvt, cksum, clear,
        cmp, comm, conspy, cp, cpio, crond, crontab, cryptpw, cttyhack, cut, date, dc, dd, deallocvt, delgroup, deluser, depmod, devmem, df,
        dhcprelay, diff, dirname, dmesg, dnsd, dnsdomainname, dos2unix, du, dumpkmap, dumpleases, echo, ed, egrep, eject, env, envdir,
        envuidgid, ether-wake, expand, expr, fakeidentd, false, fbset, fbsplash, fdflush, fdformat, fdisk, fgconsole, fgrep, find, findfs,
        flock, fold, free, freeramdisk, fsck, fsck.minix, fsync, ftpd, ftpget, ftpput, fuser, getopt, getty, grep, groups, gunzip, gzip, halt,
        hd, hdparm, head, hexdump, hostid, hostname, httpd, hush, hwclock, id, ifconfig, ifdown, ifenslave, ifplugd, ifup, inetd, init, insmod,
        install, ionice, iostat, ip, ipaddr, ipcalc, ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kbd_mode, kill, killall, killall5, klogd,
        last, less, linux32, linux64, linuxrc, ln, loadfont, loadkmap, logger, login, logname, logread, losetup, lpd, lpq, lpr, ls, lsattr,
        lsmod, lsof, lspci, lsusb, lzcat, lzma, lzop, lzopcat, makedevs, makemime, man, md5sum, mdev, mesg, microcom, mkdir, mkdosfs, mke2fs,
        mkfifo, mkfs.ext2, mkfs.minix, mkfs.vfat, mknod, mkpasswd, mkswap, mktemp, modinfo, modprobe, more, mount, mountpoint, mpstat, mt, mv,
        nameif, nanddump, nandwrite, nbd-client, nc, netstat, nice, nmeter, nohup, nslookup, ntpd, od, openvt, passwd, patch, pgrep, pidof,
        ping, ping6, pipe_progress, pivot_root, pkill, pmap, popmaildir, poweroff, powertop, printenv, printf, ps, pscan, pstree, pwd, pwdx,
        raidautorun, rdate, rdev, readahead, readlink, readprofile, realpath, reboot, reformime, remove-shell, renice, reset, resize, rev, rm,
        rmdir, rmmod, route, rpm, rpm2cpio, rtcwake, run-parts, runlevel, runsv, runsvdir, rx, script, scriptreplay, sed, sendmail, seq,
        setarch, setconsole, setfont, setkeycodes, setlogcons, setserial, setsid, setuidgid, sh, sha1sum, sha256sum, sha3sum, sha512sum,
        showkey, slattach, sleep, smemcap, softlimit, sort, split, start-stop-daemon, stat, strings, stty, su, sulogin, sum, sv, svlogd,
        swapoff, swapon, switch_root, sync, sysctl, syslogd, tac, tail, tar, tcpsvd, tee, telnet, telnetd, test, tftp, tftpd, time, timeout,
        top, touch, tr, traceroute, traceroute6, true, tty, ttysize, tunctl, udhcpc, udhcpd, udpsvd, umount, uname, unexpand, uniq, unix2dos,
        unlzma, unlzop, unxz, unzip, uptime, users, usleep, uudecode, uuencode, vconfig, vi, vlock, volname, wall, watch, watchdog, wc, wget,
        which, who, whoami, whois, xargs, xz, xzcat, yes, zcat, zcip

root@EV3:/var/volatile/tmp#
This build of busybox does include a FTP daemon so that makes it easier to copy files.

Does anyone know of a GCC binary that will work on this system?
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: EV3 linux hacking

Post by gloomyandy »

The safest way to work is to boot off of an SD card that way the Lego firmware stays intact. There are scripts that are part of the leJOS project that allow you to create a bootable SD card (witb Java added), perhaps something similar would work for you.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: EV3 linux hacking

Post by afanofosc »

The EV3 includes "dropbear" which makes it very easy to copy files to the brick using scp. Have you tried running the newer build of busybox to see if it was built with a newer C runtime dependency? Perhaps it was statically linked, in which case it should be fine.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mrblp
Posts: 82
Joined: 02 Oct 2010, 14:33

Re: EV3 linux hacking

Post by mrblp »

Hello,

you can boot from sd card. The card needs the following layout:

Partition 1: At least 4 MBytes size, filesystem type 0x0c / W95/FAT32, named "LMS2012" (not sure if this is needed).
Partition 2: The available space, filesystem type 0x83 / Linux ext3 / named "LMS2012_EXT" (not sure if this is needed).

Put the kernel (uImage) in the first partition and the lms filesystem in the second partition.

You can extract the firmware bin files from LEGO:

EV3_firmware_1.03H.bin
uBoot: 0x000000 - 0x04ffff
uImage: 0x050000 - 0x24ffff
lms2012cramfs: 0x250000 - 0xcb0000

Throw away uBoot, put uImage in the first partition and extract the cramfs to the second partition.
To make it perfect edit /etc/fstab of the second partition not to mount any sd card - comment all the entries at the bottom.
Et voila - when put in the EV3 before switching it on it will boot from that sd card.
Bye Marvin

- "I think you ought to know I'm feeling very depressed." - (Android Marvin in "The Hitchhiker's Guide to the Galaxy" by Douglas Adams, 1978)
mrblp
Posts: 82
Joined: 02 Oct 2010, 14:33

Re: EV3 linux hacking

Post by mrblp »

Hello,

You can write data to /mnt/ramdisk. This partition is stored to flash when shutting down and restored when starting up. So there is a risk of losing data while hacking until shutdown.

Source code is also available:

http://sourceforge.net/apps/phpbb/mindb ... 759#p16759

And a platform documentation:

http://sourceforge.net/apps/phpbb/mindb ... f=3&t=1940
Bye Marvin

- "I think you ought to know I'm feeling very depressed." - (Android Marvin in "The Hitchhiker's Guide to the Galaxy" by Douglas Adams, 1978)
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 4 guests