Recent Changes - Search:

edit SideBar

HailSize

This page consists of notes about TockOS problems with the Hail board and size

Too Big

The first problem is that make fails because the file is too big:

  LD        /Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.elf
/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-2.2.0.20150423\
-out/arm-none-eabi/armv6-m/newlib/libc/stdlib/../../../../../../newlib-2.2.0.20150423/newlib/libc/stdlib/abort.c:55: first define\
d here
/opt/local/lib/gcc/arm-none-eabi/5.1.0/../../../../arm-none-eabi/bin/ld: /Users/cxh/src/hail/tock/userland/examples/duktape/build\
/cortex-m4/app.elf section `.data' will not fit in region `SRAM'
/opt/local/lib/gcc/arm-none-eabi/5.1.0/../../../../arm-none-eabi/bin/ld: region `SRAM' overflowed by 34680 bytes
/Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/c_eventloop.o: In function `eventloop_run'
:
/Users/cxh/src/hail/tock/userland/examples/duktape/c_eventloop.c:381: undefined reference to `usleep'
/Users/cxh/src/hail/tock/userland/newlib/libc.a(lib_a-gettimeofdayr.o): In function `_gettimeofday_r'
:
/home/alevy/hack/helena/tock/userland/newlib/newlib-2.2.0.20150423-out/arm-none-eabi/armv6-m/newlib/libc/reent/../../../../../../\
newlib-2.2.0.20150423/newlib/libc/reent/gettimeofdayr.c:71: 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

The size of the SRAM is determined by https://github.com/helena-project/tock/blob/master/userland/linker.ld :

MEMORY {
FLASH (rx) : ORIGIN = 0x80000000, LENGTH = 0x00080000
SRAM (RWX) : ORIGIN = 0x00000000, LENGTH = 0x00002000
}

See Duktape under Cortex M4: region `SRAM' overflowed by 36208 bytes (Google Groups) for possibilities about relocating.

However, smaller sizes are possible:

  • 512K of memory so that we have breathing room. 256K might not work. Duktape Eclipse ARM Cortex M4 was reported to have the following sizes:
    • Code size = 176K
    • Constants = 628 bytes
    • RAM = 492 bytes

Here are the sizes:

bash-3.2$ size build/cortex-m4/*.o
   text    data     bss     dec     hex filename
   1530     182     168    1880     758 build/cortex-m4/c_eventloop.o
    160      10       0     170      aa build/cortex-m4/duk_stack.o
 118708   17206       0  135914   212ea build/cortex-m4/duktape.o
    700    3993       0    4693    1255 build/cortex-m4/eduk.o
    384     211       0     595     253 build/cortex-m4/modSearch.o
    380   38052       0   38432    9620 build/cortex-m4/nofileio.o

See https://mcuoneclipse.com/2013/04/14/text-data-and-bss-code-and-data-size-explained/ for an explanation about text, data and bss.

We want to decrease data by moving the the JavaScript code that is encoded in the .h files into the text segment.

To do this, we make the arrays in commonHost.h, events.h and util.h be const.

Compilation

See Compilation for details

RampJSDisplay

It is possible to read from stdout using tockloader

eduk.c was modifies so that if it is compiled with -DEDUK_RAMPJSDISPLAY -DEDUK_RUNRAMPJSDISPLAY, then the test/auto/RampJSDisplay.js Composite Accessor is invoked.

Below is a run of eduk from a shell. Note that we used Control-C to terminate.

bash-3.2$ pwd
/Users/cxh/src/hail/tock/userland/examples/duktape/accessors/web/hosts/duktape/eduk
bash-3.2$ rm eduk
bash-3.2$ make SWARMLET=-DEDUK_RUN_RAMPJSDISPLAY
gcc -o eduk  -DEDUK_FULL -DEDUK_RAMPJSDISPLAY -DEDUK_RUN_RAMPJSDISPLAY -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-fram\
e-pointer -I. -I../duktape/src    c_eventloop.c duk_stack.c eduk.c modSearch.c nofileio.c ../duktape/src/duktape.c  -lm
bash-3.2$ ./eduk
eduk: About to run test/auto/RampJSDisplay.js
duktapeHost.js done
1
2
3
  C-c C-c
bash-3.2$

RESPONSE_BADADDR: Invalid address for page to write

Unfortunately, the binary is still too large and fails to flash:

bash-3.2$ make TOCK_BOARD=hail PORT=/dev/tty.usbserial-00001014 program
  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
    Finished debug [unoptimized + debuginfo] target(s) in 0.0 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`
tockloader --port /dev/tty.usbserial-00001014 flash --address 0x30000 /Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.bin
Error: Error when flashing page
Error: RESPONSE_BADADDR: Invalid address for page to write (address: 0x80000
Could not flash the binaries.
make: *** [program] Error 1
bash-3.2$

Here's the size of our duktape binary compared with the accl-leds binary.

bash-3.2$ arm-none-eabi-size duktape/build/cortex-m4/app.elf
   text    data     bss     dec     hex filename
 313304    3449     308  317061   4d685 duktape/build/cortex-m4/app.elf
bash-3.2$ arm-none-eabi-size accel-leds/build/cortex-m4/app.elf
   text    data     bss     dec     hex filename
   4014     197      40    4251    109b accel-leds/build/cortex-m4/app.elf
bash-3.2$

See Duktape under Cortex M4: region `SRAM' overflowed by 36208 bytes (Google Groups) for possibilities about relocating.

Minimum Duktape

I added a #ifdef EDUK_MIN to try to create the a very small eduk:

bash-3.2$ make PORT=/dev/tty.usbserial-00001014 TOCK_BOARD=hail
   text    data     bss     dec     hex filename
 263168    3237     236  266641   41191 /Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.elf

But it failed:

bash-3.2$ make PORT=/dev/tty.usbserial-00001014 TOCK_BOARD=hail program
tockloader --port /dev/tty.usbserial-00001014 flash --address 0x30000 /Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.bin
Error: Error when flashing page
Error: RESPONSE_BADADDR: Invalid address for page to write (address: 0x80000
Could not flash the binaries.
make: *** [program] Error 1
bash-3.2$

The above message comes from https://github.com/helena-project/tockloader/blob/master/tockloader/main.py

                        if ret[1] != RESPONSE_OK:
                                print('Error: Error when flashing page')
                                if ret[1] == RESPONSE_BADADDR:
                                        print('Error: RESPONSE_BADADDR: Invalid address for page to write (address: 0x{:X}'.format(address + (i*512)))
                                elif ret[1] == RESPONSE_INTERROR:
                                        print('Error: RESPONSE_INTERROR: Internal error when writing flash')
                                elif ret[1] == RESPONSE_BADARGS:
                                        print('Error: RESPONSE_BADARGS: Invalid length for flash page write')
                                else:
                                        print('Error: 0x{:X}'.format(ret[1]))
                                return False
 

The Hail boot loader at https://github.com/lab11/hail/blob/master/bootloader/src/bl_commands.c is what returns the RESPONSE_BADARGS. (Note that in tockloader, the macro is RESPONSE_BADARGS, whereas in bootloader, it is RES_BADARGS.

    if (addr < ALLOWED_FLASH_FLOOR || addr >= ALLOWED_FLASH_CEILING ||
            (addr & 511) != 0)
    {
        _escape_set(NULL, 0, RES_BADADDR);
        return;
    }

Optimize for space

Using -Os to optimize for space failed:

    Running `/Users/cxh/src/hail/tock/userland/tools/elf2tbf/target/debug/elf2tbf -o /Users/cxh/src/hail/tock/u\
serland/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
 169680    2617     236  172533   2a1f5 /Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.e\
lf
bash-3.2$ make PORT=/dev/tty.usbserial-00001014 TOCK_BOARD=hail program
tockloader --port /dev/tty.usbserial-00001014 flash --address 0x30000 /Users/cxh/src/hail/tock/userland/examples\
/duktape/build/cortex-m4/app.bin
Error connecting to bootloader. No "pong" received.
Things that could be wrong:
  - The bootloader is not flashed on the chip
  - The DTR/RTS lines are not working
  - The serial port being used is incorrect
  - The bootloader API has changed
  - There is a bug in this script
Could not flash the binaries.
make: *** [program] Error 1
bash-3.2$

Interestingly compiling accel-leds with -Os works.

Without -Os:

   text    data     bss     dec     hex filename
   4014     197      40    4251    109b /Users/cxh/src/hail/tock/userland/examples/accel-leds/build/cortex-m4/app.elf

With -Os:

   text    data     bss     dec     hex filename
   3486     197      40    3723     e8b /Users/cxh/src/hail/tock/userland/examples/accel-leds/build/cortex-m4/app.elf

Eventually, I was able to get tockloader to work.

Adding a print statement to /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tockloader/main.py seemed to allow the load to complete?

                # Loop through the binary 512 bytes at a time until it has been flashed                                
                # to the chip.                                                                                          
                for i in range(len(binary) // 512):
                        targetAddress = address + i * 512

                        # FIXME: Printing the address seems to help avoid RESPONSE_BADADDR
                        print('0x:{:X}'.format(targetAddress))  

                        # First we write the sync string to make sure the bootloader is ready                          
                        # to receive this page of the binary.                                                          
                        self.sp.write(SYNC_MESSAGE)
                        time.sleep(0.0001)

Tockloader

Below is an approved way of updated tockloader.

sudo -i
mkdir ~/src
cd ~/src
git clone https://github.com/helena-project/tockloader.git
cd tockloader
/opt/local/bin/python3.6 setup.py install
(:source lang=bash:)

Note that for the above to work, your ~/.bashrc needs to refer to the Python 3.6 binary directory:
(:source lang=bash:)
export PATH=/opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}

Local TockLoader

Messing around with tockloader was getting tricky because when I installed using /opt/local/bin/pip-3.6, the main.py was owned by root.

Then, when in downloaded from the tockloader github repo and ran setup, it looked like /opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/tockloader was using a compressed .egg file.

So, I installed a local copy.

cd ~/src/hail
git clone https://github.com/helena-project/tockloader.git
mkdir bin
cd bin
ln -s ../tockloader/tockloader/main.py tockloader
chmod a+x ../tockloader/tockloader/main.py
export PATH=`pwd`:${PATH}

Continuing with Optimizing for Space

After getting -Os to work and tockloader working, I can upload

bash-3.2$ size build/cortex-m4/app.elf
   text    data     bss     dec     hex filename
 169680    2617     236  172533   2a1f5 build/cortex-m4/app.elf
bash-3.2$ make PORT=/dev/tty.usbserial-00001014 TOCK_BOARD=hail program
tockloader --port /dev/tty.usbserial-00001014 flash --address 0x30000 /Users/cxh/src/hail/tock/userland/examples/duktap\
e/build/cortex-m4/app.bin
Wrote 262656 bytes in 32.840 seconds
CRC check passed. Binaries successfully loaded.

However, the red LED flashes, indicating a problem.

Using tockloader listen, I see the following output:

bash-3.2$ tockloader --port /dev/tty.usbserial-00001014 listen
Kernel panic at /Users/cxh/src/hail/tock/chips/sam4l/src/lib.rs:238:
        "Process HardFault.
        r0  0x0
        r1  0x20005330
        r2  0x20005f00
        r3  0x0
        r12 0x921f980
        lr  0x3061d
        pc  0x4f796
        prs 0x41000000
        sp  0x20004d10
        SHCSR 0x0
        CFSR  0x1
        HSFR  0x400Kernel panic at /Users/cxh/src/hail/tock/chips/sam4l/src/lib.rs:238:
        "
Process HardFault.
        r0  0x0
        r1  0x20005330
        r2  0x20005f00
        r3  0x0
        r12 0x921f980
        lr  0x3061d
        pc  0x4f796
        prs 0x41000000
        sp  0x20004d10
        SHCSR 0x0
        CFSR  0x1
        HSFR  0x40000000
"

Update my fork

See Updating my fork for how to merge from the helena-project/tock repo into the branch

I then reprogrammed the kernel on the board, see https://github.com/helena-project/tock/tree/master/boards/hail

Size Again

The new version has better error map, below is how to reproduce the issue

I have ifdef'd my main down to just printing, which works fine, I can listen to the board and see the message.

However, if at link time, I include the duktape.o file, then I get a fault.

I'm guessing this is a size issue, but could use some help.

Details:

Here's how to reproduce this.

I'm using these versions:

bash-3.2$ rustc --version
rustc 1.12.0-nightly (54c0dcfd6 2016-07-28)
bash-3.2$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496]
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I'm working in a branch (cxbrooks/ducktape3) on a (fork https://github.com/cxbrooks/tock). I sync'd my fork to the helena-project/tock about 60 minutes ago:

bash-3.2$ git log | head -200
commit c44eebf8b0aaf6b2df9c5daabc2e69cd9a74bd08
Author: Christopher Brooks <cxh@eecs.berkeley.edu>
Date:   Fri Jan 6 17:46:37 2017 -0800
     Duktape Makefile that compiles but faults at run time.

commit c352454bed6e63a5ab5f30329f4a8f7beabebc2e
Author: Branden Ghena <brghena@umich.edu>
Date:   Fri Jan 6 20:34:41 2017 -0500

    Refactor process status printing

     * Explain text segment in more depth
     * Refactor `statistics_str` function
     * Remove unnecessary fields from process struct

Here are the commands to run:

git clone https://github.com/cxbrooks/tock
cd tock
git checkout cxbrooks/duktape3
cd boards/hail
make PORT=/dev/tty.usbserial-00002014 TOCK_BOARD=hail program
cd ../../userland/examples/blink
make PORT=/dev/tty.usbserial-00002014 TOCK_BOARD=hail program

The blink program works fine.

The duktape example program consists of a makefile that has a target called "update" that checks out the accessors repo and copies .c and .h files.

cd ../duktape
make update
make PORT=/dev/tty.usbserial-00002014 TOCK_BOARD=hail program

Here are the sizes:

bash-3.2$ size build/cortex-m4/*
/opt/local/libexec/llvm-3.9/bin/llvm-size: error reading file: The file was not recognized as a valid object file.
   text    data     bss     dec     hex filename
 163544    6621     236  170401   299a1 build/cortex-m4/app.elf
/opt/local/libexec/llvm-3.9/bin/llvm-size: error reading file: The file was not recognized as a valid object file.
   1562     182     168    1912     778 build/cortex-m4/c_eventloop.o
/opt/local/libexec/llvm-3.9/bin/llvm-size: error reading file: The file was not recognized as a valid object file.
    160      10       0     170      aa build/cortex-m4/duk_stack.o
/opt/local/libexec/llvm-3.9/bin/llvm-size: error reading file: The file was not recognized as a valid object file.
 120092   17206       0  137298   21852 build/cortex-m4/duktape.o
/opt/local/libexec/llvm-3.9/bin/llvm-size: error reading file: The file was not recognized as a valid object file.
     54      15       0      69      45 build/cortex-m4/eduk.o
/opt/local/libexec/llvm-3.9/bin/llvm-size: error reading file: The file was not recognized as a valid object file.
     92      42       0     134      86 build/cortex-m4/ledcontrol.o
/opt/local/libexec/llvm-3.9/bin/llvm-size: error reading file: The file was not recognized as a valid object file.
    384     211       0     595     253 build/cortex-m4/modSearch.o
/opt/local/libexec/llvm-3.9/bin/llvm-size: error reading file: The file was not recognized as a valid object file.
      0       0       0       0       0 build/cortex-m4/nofileio.o

The board has the red-blink-of-death.

(Reminds me of the students that used a red blinking LED as their first program on a similar board. They thought they got it right the first time! But it was just the error blink.)

Listening to the port:

bash-3.2$ tockloader --port /dev/tty.usbserial-00002014 listen
Kernel panic at /Users/cxh/src/hail/tock/kernel/src/process.rs:278:
        "Process duktape had a fault"

---| Fault Status |---
Instruction Access Violation:       true
Forced Hard Fault:                  true
Fault Status Register (CFSR):       0x00000001
Hard Fault Status Register (HFSR):  0x40000000
---| App Status |---
App: duktape
 [Fault]  -  Events Queued: 0  Syscall Count: 0
  &#9556;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9572;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;Kernel panic at /Users/cxh/src/hail/tock/kernel/src/process.rs:278:
        "Process duktape had a fault"
 ---| Fault Status |---
Instruction Access Violation:       true
Forced Hard Fault:                  true
Fault Status Register (CFSR):       0x00000001
Hard Fault Status Register (HFSR):  0x40000000
 ---| App Status |---
App: duktape
 [Fault]  -  Events Queued: 0  Syscall Count: 0
 &#9556;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9572;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9559;
 &#9553;  Address  &#9474; Region Name    Used | Allocated (bytes)  &#9553;
 &#9562;0x20006000&#9552;&#9578;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9565;
             &#9474; &#9660; Grant         256 |   1024
  0x20005F00 &#9532;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;
             &#9474; Unused
  0x200052D0 &#9532;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;
             &#9474; &#9650; Heap            0 |   1024              S
  0x200052D0 &#9532;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480; R
             &#9474; &#9660; Stack          32 |   2048              A
  0x200052B0 &#9532;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480; M
             &#9474; Unused
  0x20004AD0 &#9532;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;
             &#9474; Data           2768 |   2768
  0x20004000 &#9524;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;
             .....
  0x00070000 &#9516;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;
             &#9474; Unused
  0x00058EE0 &#9532;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480; F
             &#9474; Data           2532                       L
  0x000584FC &#9532;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480; A
             &#9474; Text         163544                       S
  0x00030624 &#9532;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480;&#9480; H
             &#9474; Header         1572
  0x00030000 &#9524;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;

  R0 : 0x20004AD0    R6 : 0x00000000
  R1 : 0x200052D0    R7 : 0x00000000
  R2 : 0x20005F00    R8 : 0x00000000
  R3 : 0x00000000    R10: 0x00000000
  R4 : 0x00000000    R11: 0x00000000
  R5 : 0x00000000    R12: 0x00000000
  R9 : 0x20004000 (Static Base Register)
  PC : 0x0004C0C0 [0x8001BA9C in lst file]
  LR : 0x00030629 [0x80000004 in lst file]

BTW - the output is pretty, but it does not copy and paste that well. Maybe stick with non-graphical characters?

Ok, so the above failed.

Now remove duktape.c, which is huge, and two files that use functions defined in duktape.c:

rm c_eventloop.c ledcontrol.c duktape.c
make clean
make PORT=/dev/tty.usbserial-00002014 TOCK_BOARD=hail program

Here are the sizes:

bash-3.2$ size build/cortex-m4/*
/opt/local/libexec/llvm-3.9/bin/llvm-size: error reading file: The file was not recognized as a valid object file.
   text    data     bss     dec     hex filename
    206    4236      20    4462    116e build/cortex-m4/app.elf
/opt/local/libexec/llvm-3.9/bin/llvm-size: error reading file: The file was not recognized as a valid object file.
    160      10       0     170      aa build/cortex-m4/duk_stack.o
/opt/local/libexec/llvm-3.9/bin/llvm-size: error reading file: The file was not recognized as a valid object file.
     54      15       0      69      45 build/cortex-m4/eduk.o
/opt/local/libexec/llvm-3.9/bin/llvm-size: error reading file: The file was not recognized as a valid object file.
    384     211       0     595     253 build/cortex-m4/modSearch.o
/opt/local/libexec/llvm-3.9/bin/llvm-size: error reading file: The file was not recognized as a valid object file.
      0       0       0       0       0 build/cortex-m4/nofileio.o

And here is my message:

bash-3.2$ tockloader --port /dev/tty.usbserial-00002014 listen
Hello World!

So, printing works. Below is the part of the main() from eduk.c:

int main(int argc, char *argv[]) {
#ifdef HAIL_PRINT

#ifdef __ARM_EABI__
  putnstr_async(hello, sizeof(hello), nop, NULL);
#else
  printf("%s", hello);
#endif // __ARM_EABI                                                    
  return 0;
#else //HAIL_PRINT    

So, what I don't understand is why including duktape.o in the binary is causing the crash. Any ideas?

Unfortunately, duktape.c is 87k lines of code, so paring this down is not easy.

I'm using Duktape-1.6.0, which came out in December. Duktape-2.0.0 is out, but the configuration options have changed.

I have not looked very far in to how to use gdb to debug this. I was able to use tools/build-arm-gdb to build an arm-specific version of gdb. I believe I need to use the -tty argument to gdb. I see that https://github.com/helena-project/tock/blob/master/doc/tutorials/README.md has plans for a JTAG/GDB tutorial and that https://github.com/helena-project/tock/blob/master/boards/storm/README.md has some details about using JLinkGDBServer. My guess is that to use gdb, I need to get a JTAG box. I saw some notes about which JTAG box is preferred, but I'm not finding them right now.

So, any ideas here?

Disable the MPU

Below is Brendan's response:

"To give a little more information here, the large version of your code is failing at the very first line of `main`. This very much looks like an MPU problem to me and you might be able to get around it for now by simply disabling the MPU."
"To determine this:"
"I checked out and built your code. Then I ran `make debug` which generates an LST file, `build/cortex-m4/app.lst` (Warning: this lst file is 700000 lines and took a couple minutes to generate)"
"Then I looked up the address where your app is failing from the debug report. 0x8001BA9C in the LST file."
...
8001ba9c <main>:
*
* @param argc The number of arguments.
* @param argv The arguments.
*/
//main(void)
int main(int argc, char *argv[]) {
8001ba9c: b507 push {r0, r1, r2, lr}
#ifdef HAIL_PRINT

#ifdef __ARM_EABI__
putnstr_async(hello, sizeof(hello), nop, NULL);
8001ba9e: 4b09 ldr r3, [pc, #36] ; (8001bac4 <main+0x28>)
...
"The actual entry point of your program is in libtock/crt1.c. Relevant disassembly:"
...
Disassembly of section .text:

80000000 <_start>:
__attribute__ ((section(".start"), used, naked))
void _start(
__attribute__((unused))void* mem_start,
__attribute__((unused))void* app_memory_break,
__attribute__((unused))void* kernel_memory_break) {
main();
80000000: f01b fd4c bl 8001ba9c <main>
while(1) { yield(); }
80000004: f01d ff5e bl 8001dec4 <yield>
80000008: e7fc b.n 80000004 <_start+0x4>
...
"So, the very first thing your code does is branch to main(), which immediately throws an Instruction Access Violation. It seems that we are probably doing something wrong when setting up the MPU for programs with a lot of flash. For now, you could try turning off the MPU. Comment out the MPU enable in the kernel. (https://github.com/cxbrooks/tock/blob/cxbrooks/duktape3/boards/hail/src/main.rs#L343), then recompile and load the kernel (`make program` from tock/boards/hail/)."

See Duktape2 Initial Compilation

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