Howto: Building the espruino code

Posted on
of 2
/ 2

  • Note: There is now improved documentation at­lding-under-windowsmacos-with-a-vm

    Hello all,
    I've been playing around the last three days with the espruino source code and I want to share my experience with the build system.
    First I wanted to make it work under windows (yes, I'm a masochist :-) ) and after I burned the midnight oil I concluded: Forgot it! I have an MSYS environment and the included shell doesnt' work properly. I'm afraid that for windows there will be the need for a different build system like ant (java based) or nant (same as ant, .net version).
    Next try: Linux in a virtual machine (virtual box). I installed the compiler (just untared the archive), installed a additional library for python, changed some little things in the makefile, typed "make" - and voila!
    Here's a step by step guide.

    Preparing the build environment

    I guess vour linux system or linux vm is up and running.

    • Check if python 2.6 / 2.7 is installed. On the shell type python -V (be careful! Big 'V'!). You need python 2.6 or 2.7. python3 doesn't work!

    • Check if importlib ist installed. On the shell type python -c 'import importlib' . If the lib isn't there you got an error like this "ImportError: No module named importlib".

    • Optional: Install importlib. You need easy_install from the package python-setuptools. I'm assuming that it's already installed. On the bash type easy_install importlib . That's all.

    • Check if make ist installed. Type make -v (little "v")

    • Download and install a compiler. I'm using this:­sourcery-tools/sourcery-codebench/editio­ns/lite-edition/
      On the linked website got to the section ARM Processors -> Download the EABI Release.
      You need to register and after that you'll get an email with a link to the download page. (I've chosen the linux You're best off using version 2013.05-23-arm-none-eabi, as other versions produce larger binaries which may be too big to go in Espruino's available flash memory.
      Install it in your home-dir or elsewhere.

    Compiling the code

    • Download the source code. You can find the source of the js interpreter here:
      Download an ZIP-archive with the code­hive/ (last button on the right side) and unzip it in your home dir or elsewhere (unzip The root dir of the unzipped archive is "Espruino-master".
      There seems to be an error in the Makefile. It always stops at the same position saying it can't find the directory 'gen'. I've created it by hand (mkdir gen) and it works.

    • Edit Makefile. Open Makefile in an editor, search for the string "CCPREFIX" (it's in the section "ifdef ARM"), change it to /path-to-compiler/arm-2013.05/bin/arm-no­ne-eabi-

    • Check the head of the Makefile for environment variables and options (boards, creating of debug version and final releases etc)

    I'm using a STM32F4DISCOVERY. For that board just type on the shell STM32F4DISCOVERY=1 RELEASE=1 make . You can also "hard code" these variables on top of the makefile or just uncomment the examples in the header.

    After some time (30 seconds I guess, virtual box VM with opensuse 11.2, host system Windows Vista with core i7) you get 5 files espruino_stm32vldiscovery with the endings .bin .srec .elf .lst and .hex. Take the hex-file and upload it with ST-Link to your board. Reconnect the board to the pc and it will respond in your terminal window as "Espruino V1.40 KickStarter Version".

    That's all. Have fun!

  • Thanks! I'm going to try this some evening next week on OS X and/or linux.

  • Very good, although I could get it to work. thanks

  • Thanks! Using a VM is definitely a good way to go - I wonder if someone could wrap this up in a script that could be executed once a VM was set up?

    There's also USB stick Ubuntu as well - could be worth a try:­ry-ubuntu-before-you-install

  • Using a VM is definitely a good way to go - I wonder if someone could wrap this up in a script that could be executed once a VM was set up?

    This might be a little tricky, a challenge for a rainy weekend :-)

  • I guess the more sensible thing is to put a Raspberry Pi SD card image online somewhere.

    It doesn't take that long to compile on a Pi, and a lot of folks have one.

  • I could setup a Vagrant VM. It would require VirtualBox and takes a little time to setup initially (installing all the software, etc.), but should be easy to maintain the config in a repo.

  • @Bluecamel : it would be really great!

  • I got a basic vagrant vm created. I don't have the compile toolchain setup yet. I'm new to building for embedded processors, so I'm still trying to figure out how to build. I installed arm-linux-gnueabi-gcc-4.6 and made a soft link to that from arm-none-eabi-gcc and ran 'STM32F4DISCOVERY=1 RELEASE=1 make' but get loads of warnings. I'm guessing that arm-linux-gnueabi-gcc-4.6 isn't what I should be using?

    Anyhow, if you want to see the vm and maybe help get the correct compiler setup...

    To setup the vm on your machine:

    • install VirtualBox:
    • install Vagrant:
    • download the 'build_vm' branch of my fork of the Espruino repo:­ee/build_vm (I'll send a pull request when this is working)
    • cd into the vm directory
    • type 'vagrant up' (this should download the Ubuntu image, then install all of the required takes several minutes, depending on your bandwidth/machine)
    • type 'vagrant ssh' (this gives you a ssh session into the machine)
    • you have access to the Espruino repo within the vm at /Espruino (any files you edit here are synced with your host machine and vice versa)

    For those interested in how I made it (or want to help with or suggest configuration):

    It just uses a bare-bones precise32 image that I added a few basic things to (python, pip, git, make, blueprint). I left out arm-linux-gnueabi-gcc-4.6 for now, since I'm not sure that's right.

    I used blueprint ( to generate the chef config files. Vagrant runs Chef Solo ( using these config files to install all of the packages we need/want in the vm.

    If you want to contribute your changes (installed packages and config files):

    • type 'blueprint create EspruinoBuild'
    • type 'blueprint show -C EspruinoBuild'
    • this should have created a folder named 'EspruinoBuild' in the current directory
    • replace /espruino/vm/cookbooks/EspruinoBuild with the directory you just created
    • commit your changes to the repo (all should be config files under the vm directory)
    • all the rest of us will need to do (after pulling the changes) is type 'vagrant reload' from the vm directory

  • By the way, I think it should also be possible to install st-link on the vm and configure it to share the USB device from the host, and flash directly from the vm. At least I'm really, really hoping that'll work ;)

  • Well, there were lots of fun hurdles, but I finally got a working build environment that can build itself automagically. The instructions are the same as before, with a few extensions:

    • after the vm is created, stlink is built (more on this below)
    • after that, arm-eabi-toolchain from jsnyder (­chain) is installed
    • on my machine, it took about an hour (all but maybe 10 minutes of this is building using the jsnyder/arm-eabi-toolchain makefile)

    It works! I've been able to build for my STM32F4DISCOVERY, flash it using stlink, and use screen to get to the virtual terminal - all within the vm.

    I wish it didn't take so long. For those more familiar with the toolchain, is an hour normal? I tried adding some settings to the vm to use more cores and added 'PROCS=2' before my make statement, but that didn't seem to change anything.

    Another option is I could just create an image of the vm at this state and that could be hosted somewhere (probably not in this repository since it would be fairly large). However, it would be much faster to setup for the first time.

    Please let me know how it goes if you give it a try. I hope this is useful to others ;)

  • Oh, I forgot to mention some config you'll need to use stlink in the vm. Basically, you'll want to tell virtualbox the vendor and product ids for your device. Look in vm/Vagrantfile and you'll see a line that looks like:

    vb.customize ["usbfilter", "add", "1", "--target", :id, "--name", "stm32-vcom", "--vendorid", "0x0483", "--productid", "0x5740"]

    Just change the values of vendorid and productid to match what lsusb ('system_profiler SPUSBDataType' on OS X) tells you for your device.

  • The arm-unknown-eab template from crosstool-ng seems to work fine.

    export CCPREFIX=$(HOME)/x-tools/arm-unknown-eab­i/bin/arm-unknown-eabi
  • Sorry, I imagined that. I forgot to set the BOARd variable.

  • In Ubuntu 10.04 Lucid Lynx I got the following error:

    arm-none-eabi-gcc command not found

    After some digging I was able to resolve by installing the relevant package from:­rm-embedded/ubuntu/pool/main/g/gcc-arm-n­one-eabi/

  • I have managed to to install Ubunto 10.4 LTS in the Oracle VM, and I have done the steps described in the beginning of this chain. However, when I try to build the project I get the following error message. I'm a newbie to Linux, CodeSourcery and using make so the cause may be quite simple ...

    asko@asko-desktop:~/Espruino-master$ STM32FDISCOVERY=1 RELEASE=1 make
    Traceback (most recent call last):
    File "scripts/", line 40, in

    print common.get_board_binary_name(board)

    File "/home/asko/Espruino-master/scripts/comm­", line 247, in get_board_binary_name

    return["binary_name"].replace("%v", get_version());

    File "/home/asko/Espruino-master/scripts/comm­", line 237, in get_version

    return subprocess.check_output(["sed", "-ne", "s/^.*JS_VERSION.*\"\(.*\)\"/\\1/p", jsutils]).strip()

    AttributeError: 'module' object has no attribute 'check_output'
    Makefile:300: *** Unable to work out binary name (PROJ_NAME). Stop.

  • Look in the Makefile, in the top you can se which names that can be used.
    STM32FDISCOVERY is not in. Do you mean STM32F3DISCOVERY or STM32F4DISCOVERY instead of.

  • Yes you are right, that was a typo which I actually had spotted but forgot to correct while posting the comment. Unfortunately I had no better luck with the correct board name i.e. STM32F3DISCOVERY . Nor with STM32F4DISCOVERY or ESPRUINO_1V3=1. I copy-pasted the boardname from the makefile just to make sure. All give the same errors.

    asko@asko-desktop:~/Espruino-master$ STM32F3DISCOVERY=1 RELEASE=1 make
    Traceback (most recent call last):
    File "scripts/", line 40, in

    print common.get_board_binary_name(board)

    File "/home/asko/Espruino-master/scripts/comm­", line 247, in get_board_binary_name

    return["binary_name"].replace("%v", get_version());

    File "/home/asko/Espruino-master/scripts/comm­", line 237, in get_version

    return subprocess.check_output(["sed", "-ne", "s/^.*JS_VERSION.*\"\(.*\)\"/\\1/p", jsutils]).strip()

    AttributeError: 'module' object has no attribute 'check_output'
    Makefile:300: *** Unable to work out binary name (PROJ_NAME). Stop.

  • Has anyone tried to build the source on OS X? All requirements seem to be in place, except for the ARM GCC compiler. I am not going to start messing with a VM or building CodeBench from source as this is my primary machine unless I know of a fail-proof method to do so. Even then ... building GCC from scratch doesn't sound too appealing ...

  • I wonder how easy it is to build on Raspberry Pi? This might actually be the easiest solution for a lot of people (especially as SSHing into the Raspberry Pi doesn't require any fancy plugging or unplugging).

  • If you have a Pi :). I think that the most important part would be step-by-step instructions on the dependencies, how to get the code, how to compile it and how to get in on the boards on *nix systems (Windows might be hard, but maybe cygwin might be of help ...). Some of those steps are still missing or obscure. It's okay if you have a disposable machine to test on, but things such as compiling a gcc version can be messy. Though I think you can get everything running on e.g. OS X using macports, it is a bit too much of a gamble on a production system to test it out.

    Another question in the same line: would it be possible to have a version of Espruino that can be run on *nix systems? This would essentially be an implementation of the Javascript version you have. This would make the development on the Javascript engine easier as you don't need to code, flash an external device and only then start testing. I don't know how easy it would be though.

  • Under Linux, the steps really are pretty simple. When things calm down I'll try and get something more definitive, but it should just be a matter of just downloading the CodeSourcery GCC compiler, git cloning Espruino, and typing: ESPRUINO_1V3=1 make

    Perhaps there are now a few Python dependencies (as above) that need to be installed though. I'll have to run through on a VM and see what's needed.

    For a Unix/Mac version, literally:

    git clone­
    cd Espruino

    Should just work. I've had that running on Mac, Linux, OpenWRT, the Pi, and even my Netgear NAS box :)

  • Well, on Mac I definitely bumped into the need to compile a gcc compiler (there doesn't seem to be a package for that) and a lack of instructions on how to get in onto the boards. I agree that the first steps are easy though :).

    Might think about getting it running on my NAS as I believe that is an ARM as well.

  • Yes, that looks like a pain on Mac - probably a VM is the best route there...

    By the way, Espruino doesn't actually need an ARM to run - so (especially on Linux) as long as you can compile the C code you can make it work. Old Netgear ReadyNAS uses Sparc and it runs fine on those (as well as Carambola, which isn't ARM either).

  • Could you elaborate on running it on something else than ARM? How do you compile and run it in such cases?

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Howto: Building the espruino code

Posted by Avatar for tickTock @tickTock