node.js

最近在HISI3535平台上要用到node.js,記錄porting上面遇到問題
順便了解一下


更新記錄

item note
20160203 第一版

目錄


Node.js

  • Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine.(出處)

    • node.js使用chrome v8解譯器
    • V8 is Google’s open source, high performance JavaScript engine.(出處)
    • V8 implements ECMAScript as specified in ECMA-262, 5th edition
  • Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient

    • node.js是javascript直譯器,跟lua很像(也是直譯),使用JS語法就可以當成app而且還有一堆package
  • NodeJS的作者说,他创造NodeJS的目的是为了实现高性能Web服务器,他首先看重的是事件机制和异步IO模型的优越性,而不是JS(出處)

Node.js LTS

Release LTS End node / V8 版本
v0.10 2016-10-01 v.0.10.41-rc1 /2012-10-22: Version 3.14.5
v0.12 2017-04-01 v.0.12.9 /2014-08-12: Version 3.28.71
v4.2.0 2018-04-01 v.4.2.6 / 2015-07-08: Version 4.5.103

Node LTS

注意:V8在3.18板之後就不支援VFP2

Cross Compile NodeJS

1
2
3
4
5
6
7
8
9
10
11
git clone https://github.com/nodejs/node.git
cd node ; git checkout v0.10.41

export AR="arm-hisiv200-linux-ar"
export CC="arm-hisiv200-linux-gcc"
export CXX="arm-hisiv200-linux-g++"
export LD="arm-hisiv200-linux-ld"
export AS="arm-hisiv200-linux-as"
export GYP_DEFINES="armv7=0"
./configure --without-snapshot --without-ssl --dest-cpu=arm --dest-os=linux
make -j 2
  • Cross Compile V0.12.9

V8採用3.28.71,即不support VFP2

因此即使用compile成功,但執行但失敗如下,看來還是無使用V0.12.9 node.js(受限於V8 source 改版)

  • V8 source
1
2
deps/v8/src/base/cpu.cc
o['variables']['arm_fpu'] = 'vfpv3' # V8 3.18 no longer supports VFP2.
  • Hisi3535 runtime error
1
2
3
4
5
# ./node-v120-t6 --v8-options | head -2
target arm v7 vfp3 softfp
ARMv7=1 VFP3=1 VFP32DREGS=1 NEON=0 SUDIV=0 UNALIGNED_ACCESSES=1 MOVW_MOVT_IMMEDIATE_LOADS=0 USE_EABI_HARDFLOAT=0
# ./node-v120-t6 -e 'console.log("het werkt!");'
Illegal instruction

HISI3535 GCC tools採用arch=armv5te產生,但HI3535裡面是armv7-a

在手刪中有強調需要增加(march=armv7-a -mcpu=cortex-a9)

  • 手冊中說明
1
2
3
4
Hi3535无硬浮点单元,文件系统中发布的库都是无硬浮点单元的库。但是,工具链默认的是armv5的指令集,而Hi3535是armv7的指令集,因此请用户注意,所有Hi3535板端代码编译时需要在Makefile里面添加以下命令:
CFLAGS += -march=armv7-a -mcpu=cortex-a9
CXXFlAGS +=-march=armv7-a -mcpu=cortex-a9
其中CXXFlAGS中的XX根据用户Makefile中所使用宏的具体名称来确定,e.g:CPPFLAGS。
  • gcc tools 使用armv5te產生
1
2
3
4
5
6
root@b682b1efa3d7:/opt/DOCKER-erwin-build-hiv200/work/github/node-org# arm-hisiv200-linux-gcc -v
Using built-in specs.
Target: arm-hisiv200-linux-gnueabi
Configured with: ../gcc-4.4-2010q1/configure --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --target=arm-hisiv200-linux-gnueabi --prefix=/home/c00132816/toolchain_glibc/install/arm-hisiv200-linux --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --with-arch=armv5te --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --enable-shared --enable-lto --enable-symvers=gnu --enable-__cxa_atexit --disable-nls --enable-extra-hisi-multilibs --with-sysroot=/home/c00132816/toolchain_glibc/install/arm-hisiv200-linux/target --with-build-sysroot=/home/c00132816/toolchain_glibc/install/arm-hisiv200-linux/target --with-gmp=/home/c00132816/toolchain_glibc/install/host_lib --with-mpfr=/home/c00132816/toolchain_glibc/install/host_lib --with-ppl=/home/c00132816/toolchain_glibc/install/host_lib --with-cloog=/home/c00132816/toolchain_glibc/install/host_lib --with-libelf=/home/c00132816/toolchain_glibc/install/host_lib --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bstatic -lm' --enable-libgomp --enable-poison-system-directories --with-libelf=/home/c00132816/toolchain_glibc/install/host_lib --with-pkgversion='Hisilicon_v200(gcc4.4-290+glibc-2.11+eabi+nptl)' --with-bugurl=http://www.hisilicon.com/cn/service/claim.html
Thread model: posix
gcc version 4.4.1 (Hisilicon_v200(gcc4.4-290+glibc-2.11+eabi+nptl))
  • 於板端cpuinfo是無vfpv3 support
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# cat /proc/cpuinfo
Processor : ARMv7 Processor rev 1 (v7l)
processor : 0
BogoMIPS : 1987.37

processor : 1
BogoMIPS : 1993.93

Features : swp half thumb fastmult edsp tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x4
CPU part : 0xc09
CPU revision : 1

Hardware : hi3535
Revision : 0000
Serial : 0000000000000000
#

arm cross compile">arm cross compile

gcc工具名稱定義

目前手邊工具有:arm-hisiv200-linux-gcc、mips-openwrt-linux-musl-gcc

其名稱定義 arch - vendor - os - eabi

  • arch:指名板端CPU架構(ARM/MIPS)
  • vendor: 工具提供廠商
  • os:板端作業系統(OS)
  • eabi:嵌入試應用(Embedded Application Binary Interface)
  • ex.
    • arm-none-eabi:用於沒有OS(即MCU),因此無提供fork等功能
    • arm-none-linux-eabi:用於Linux,使用Glibc等
    • arm-none-uclinuxeabli-gcc:用於uCLinux

abi及abihf不同 (arm-linux-gnueabi-gcc 及arm-linux-gnueabihf-gcc)

  • mfloat-abi=name
    Specifies which floating-point ABI to use. Permissible values are: ‘soft’, ‘softfp’ and ‘hard’.

    • soft: causes GCC to generate output containing library calls for floating-point operations
      不使FPU硬体進行浮點計算,即使用軟体模式

    • softfp: allows the generation of code using hardware floating-point instructions, but still uses the soft-float calling conventions.
      armel(對應gcc: arm-linux-gnuabi-gcc),使用FPU硬体計算,但採用soft return code

    • hard: allows generation of floating-point instructions and uses FPU-specific calling conventions.
      armhf(對應gcc: arm-linux-gnueabihf-gcc),使用FPU硬体計算,採用hardware return code

  • mfpu=name

    • This specifies what floating-point hardware (or hardware emulation) is available on the target. Permissible names are: ‘vfp’, ‘vfpv3’, ‘vfpv3-fp16’, ‘vfpv3-d16’, ‘vfpv3-d16-fp16’, ‘vfpv3xd’, ‘vfpv3xd-fp16’, ‘neon’, ‘neon-fp16’, ‘vfpv4’, ‘vfpv4-d16’, ‘fpv4-sp-d16’, ‘neon-vfpv4’, ‘fpv5-d16’, ‘fpv5-sp-d16’, ‘fp-armv8’, ‘neon-fp-armv8’ and ‘crypto-neon-fp-armv8’.

Floating-point (VFP)定義">Floating-point (VFP)定義

VFP Description
VFP1 已废弃
VFP2 ARMv5TE、ARMv5TEJ 和 ARMv6 架构中 ARM 指令集的可选扩展
VFPv2 has 16 64-bit FPU registers
VFPv3 or VFPv3-D32 ARMv7-A 和 ARMv7-R 配置文件中 ARM
backwards compatible with VFPv2
FPv3 has 32 64-bit FPU registers as standard..
VFPv3-D16 16 64-bit FPU registers. Implemented on Cortex-R4 and R5

hisi3535: ARM Cortex-a9(即ARMv7)

  • ARM Cortex A9 dual core
  • 看一下HI3535手冊沒有Support VFPv3

DM8168:ARM Cortex-A8: 930 MHz(即ARMv7)

  • ARMv7 ISA plus Thumb-2, Jazelle-X, and media extensions
  • NEON floating-point unit
  • Little Endian
  • Supports Integer and Floating Point (VFPv3)

ARM


其它參考資料