Recent Changes - Search:

edit SideBar


This page is about compiling the Duktape Host for TockOS

See also Duktape2 Initial Compilation


/Users/cxh/src/hail/tock/userland/libtock/build/cortex-m4/libtock.a(sys.o): In function `abort':
/Users/cxh/src/hail/tock/userland/libtock/sys.c:56: multiple definition of `abort'

/Users/cxh/src/hail/tock/userland/newlib/libc.a(lib_a-abort.o):/home/alevy/hack/helena/tock/userland/newlib/newlib- first defined here

The solution was to edit duktape/Makefile and add -DDUK_OPT_SEGFAULT_ON_PANIC to TINY_EDUK_FLAGS.


/Users/cxh/src/hail/tock/userland/newlib/libc.a(lib_a-gettimeofdayr.o): In function `_gettimeofday_r':
newlib- undefined reference to `_gettimeofday'

collect2: error: ld returned 1 exit status
make: *** [/Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.elf] Error 1

c_eventloop.c calls gettimeofday() and usleep(), which we can ifdef out temporarily:

/* Get Javascript compatible 'now' timestamp (millisecs since 1970). */
static double get_now(void) {
        struct timeval tv;
        int rc;

#ifdef __ARM_EABI__
        // FIXME: Need gettimeofday(), see {$ACCESSORS_HOME}/wiki/Main/DuktapeEclipseARMCortexM4#TimerSetup    
        return 0.0;
        rc = gettimeofday(&tv, NULL);
        if (rc != 0) {
                /* Should never happen, so return whatever. */
                return 0.0;
        return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;


// Accessors: Use usleep() here instead of poll().                                                                                
                //printf("timeout -> %d \n", timeout);                                                                            
#ifndef __ARM_EABI__
                // FIXME: Need usleep()                                                                                          
                //rc = poll(poll_list, poll_count, timeout);                                                                      
                rc = 0;

However, even with the above, we still get a message about _gettimeofday.

We need to define a _gettimeofday() function?

Adding the following to c_eventloop.c:

#ifdef __ARM_EABI__
int _gettimeofday(struct timeval *tp, void *tzp) {
  return 0;

solves the problem

  LD        /Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.elf
 BIN        /Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.bin
   Compiling byteorder v0.4.2
   Compiling getopts v0.2.14
   Compiling elf v0.0.6 (
   Compiling elf2tbf v0.1.0 (file:///Users/cxh/src/hail/tock/userland/tools/elf2tbf)
    Finished debug [unoptimized + debuginfo] target(s) in 2.73 secs
     Running `/Users/cxh/src/hail/tock/userland/tools/elf2tbf/target/debug/elf2tbf -o /Users/cxh/src/hail/tock/userland/examples/\
duktape/build/cortex-m4/app.bin /Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.elf`
   text    data     bss     dec     hex filename
 308136    3401     272  311809   4c201 /Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.elf

Next step, see Duktape Eclipse ARM Cortex M4 -> Timer Setup for a possible gettimeofday() solution.

Or, see for timer_read(), so we now have:

#ifdef __ARM_EABI__
#include "timer.h" // TockOS specific, see            
int _gettimeofday(struct timeval *tp, void *tzp) {
  return timer_read();


Now that it compiles, we can go back and fix some of the FIXMEs.

usleep() was not found:

/Users/cxh/src/hail/tock/userland/examples/duktape/c_eventloop.c:388: undefined reference to `usleep'

Happily, defines

/* Delay for for the given microseconds (approximately).
 * For a 16 MHz CPU, 1us == 16 instructions (assuming each instruction takes
 * one cycle). */

static void busy_delay_us(int duration) {
  // The inner loop instructions are: 14 NOPs + 1 SUBS/ADDS + 1 CMP
  while (duration-- != 0) {
    __asm volatile (

So, we can use that for microsecond delays.

Or, we can use the TockOS Timer:

See Duktape2 Initial Compilation

Edit - History - Print - Recent Changes - Search
Page last modified on January 22, 2017, at 10:15 PM