qdk0901 / iotjs-openwrt

iotjs on mips openwrt board
Other
6 stars 10 forks source link

Compilation for AR9331 (mips, not mipsel) #1

Open danielsitnik opened 8 years ago

danielsitnik commented 8 years ago

Hi Derek. I'd like to make iotjs work on the Onion Omega. This is an IoT development board that runs OpenWRT and has an Atheros AR9331 MIPS (not mipsel) SoC.

I have the toolchain for it and I have modified the CMake config files to use it (eg: mips-openwrt-linux-gcc instead of mipsel-openwrt-linux-gcc).

So far most of the build works, until it gets to this point where it finally fails:

Console output:

[100%] Building CXX object jerry-core/CMakeFiles/release.jerry-core.dir/jrt/jrt-fatals.cpp.o
Building CXX object jerry-core/CMakeFiles/release.jerry-core.dir/jrt/jrt-bit-fields.cpp.o
Linking CXX static library librelease.jerry-core.a
make[3]: Leaving directory `/home/daniel/iotjs-openwrt/build/x86_64-linux/release/deps/jerry'
[100%] Built target release.jerry-core
make[2]: Leaving directory `/home/daniel/iotjs-openwrt/build/x86_64-linux/release/deps/jerry'
make[1]: Leaving directory `/home/daniel/iotjs-openwrt/build/x86_64-linux/release/deps/jerry'
make: Leaving directory `/home/daniel/iotjs-openwrt/build/x86_64-linux/release/deps/jerry'

[Failed - 2] make -C /home/daniel/iotjs-openwrt/build/x86_64-linux/release/deps/jerry release.linux -j

Stderr:

/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S: Assembler messages:
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:14: Error: Unrecognized opcode `mov (%rsp),%rdi'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:14: Error: Unrecognized opcode `mov %rsp,%rsi'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:14: Error: bad expression
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:14: Error: Illegal operands `add $8,%rsi'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:14: Error: Unrecognized opcode `callq main'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:14: Error: Unrecognized opcode `mov %rax,%rdi'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:14: Error: Unrecognized opcode `callq exit'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:14: Error: Unrecognized opcode `jmp 1b'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:20: Error: Unrecognized opcode `mov %rdi,%rax'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:20: Error: Unrecognized opcode `ret'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:26: Error: Unrecognized opcode `mov %rdi,%rax'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:26: Error: Unrecognized opcode `mov %rsi,%rdi'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:26: Error: Unrecognized opcode `ret'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:32: Error: Unrecognized opcode `mov %rdi,%rax'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:32: Error: Unrecognized opcode `mov %rsi,%rdi'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:32: Error: Unrecognized opcode `mov %rdx,%rsi'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:32: Error: Unrecognized opcode `ret'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:38: Error: Unrecognized opcode `mov %rdi,%rax'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:38: Error: Unrecognized opcode `mov %rsi,%rdi'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:38: Error: Unrecognized opcode `mov %rdx,%rsi'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:38: Error: Unrecognized opcode `mov %rcx,%rdx'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:38: Error: Unrecognized opcode `ret'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:53: Error: Unrecognized opcode `mov (%rsp),%rax'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:53: Error: Unrecognized opcode `mov %rsp,0x00(%rdi)'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:53: Error: Unrecognized opcode `mov %rax,0x08(%rdi)'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:53: Error: Unrecognized opcode `mov %rbp,0x10(%rdi)'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:53: Error: Unrecognized opcode `mov %rbx,0x18(%rdi)'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:53: Error: Unrecognized opcode `mov %r12,0x20(%rdi)'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:53: Error: Unrecognized opcode `mov %r13,0x28(%rdi)'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:53: Error: Unrecognized opcode `mov %r14,0x30(%rdi)'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:53: Error: Unrecognized opcode `mov %r15,0x38(%rdi)'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:53: Error: Unrecognized opcode `fnstcw 0x40(%rdi)'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:53: Error: Illegal operands `xor %rax,%rax'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:53: Error: Unrecognized opcode `ret'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `mov 0x00(%rdi),%rsp'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `mov 0x08(%rdi),%rax'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `mov 0x10(%rdi),%rbp'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `mov 0x18(%rdi),%rbx'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `mov 0x20(%rdi),%r12'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `mov 0x28(%rdi),%r13'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `mov 0x30(%rdi),%r14'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `mov 0x38(%rdi),%r15'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `fldcw 0x40(%rdi)'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `mov %rax,(%rsp)'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `mov %rsi,%rax'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `test %rax,%rax'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `jnz 1f'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `mov $1,%rax'
/home/daniel/iotjs-openwrt/deps/jerry/jerry-libc/target/linux/jerry-asm.S:69: Error: Unrecognized opcode `ret'
make[3]: *** [jerry-libc/CMakeFiles/release.jerry-libc.linux.lib.dir/target/linux/jerry-asm.S.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [jerry-libc/CMakeFiles/release.jerry-libc.linux.lib.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/release.linux.dir/rule] Error 2
make: *** [release.linux] Error 2

Do you know if it's possible to build it for the AR9331? Thanks and great job!

qdk0901 commented 8 years ago

hi, see this commit, ar9331 support is added, and I test compilation is ok.

your compiling error is due to jerry-libc is included, because jerry-libc has no mips or mipsel specific implement, but we can use external libc, this can be set in toos/build.py as below

    if option.target_os == 'linux' or option.target_os == 'openwrt':
        cmake_opt.append('-DUSE_COMPILER_DEFAULT_LIBC=YES')
danielsitnik commented 8 years ago

Thanks for the prompt response Derek! I managed to compile successfully as well, then transferred the binary to the Omega and chmod +x iotjs.

Now when I run just ./iotjs I get some output to the console: usage: iotjs <js> [<iotjs arguments>] [-- <app arguments>]

However, when I try to run any .js file there's no output to stdout or stderr. Even the most simple hello world script or even something with invalid code won't output anything. Is there any way to debug it? Or maybe I need to transfer something else from the compilation process as well?

qdk0901 commented 8 years ago

it seems the js snapshot is wrong due to big endian, I would try to figure out how to fix this problem. you can change buildtype to 'debug' in build.config, so that the debug message can printed.

qdk0901 commented 8 years ago

you can set 'no-snapshot' option to 'true' in build.config, that will make iotjs running ok on ar9331, but it will need more time to launch.

danielsitnik commented 8 years ago

Oh, I was under the impression that debug mode was the default. Recompiled for debug and with no-snapshot, but still no luck.

root@Omega-2018:~# ./iotjs hello.js
ICE: Unreachable control path at /home/daniel/iotjs-openwrt/deps/jerry/jerry-core/ecma/operations/ecma-regexp-object.cpp(re_match_regexp):1132 was executed.
Error: ERR_FAILED_INTERNAL_ASSERTION
Aborted
qdk0901 commented 8 years ago

hi, what in your hello.js.

danielsitnik commented 8 years ago

Just a simple console.log('hello');

qdk0901 commented 8 years ago

the iotjs has no builtin console module, you can change to

print('hello');

oh, I make mistake, it has console module.

danielsitnik commented 8 years ago

No? As I understood from the tutorial it should have! Isn't it supposed to be compatible with Nodejs as well (meaning it's scripts can be run by Node)? That would mean it should have a console module.

qdk0901 commented 8 years ago

you are right, it has console module. it seems

console.log('hello')

failed, but

print('hello')

is ok.

qdk0901 commented 8 years ago

it's so weird, on mipsel board all thing going right, but in mips board, something is wrong.

zoobab commented 8 years ago

I am hitting the same issue. I have tried with different versions of release/debug. Still debugging...

zoobab commented 8 years ago

I bet the js2c is not producting a header file which is for a MIPS arch.

qdk0901 commented 8 years ago

after fixing the endian of the header structure, there's still "out of memory" exception I had submited an issue to the official jerryscript repo, but it has not been fixed now.

zoobab commented 8 years ago

See also this kernel problem (for nodejs but it might be related as well):

https://github.com/openwrt/packages/issues/2442