1425bb815Sopenharmony_ci# JerryScript for OpenWrt build guide 2425bb815Sopenharmony_ci 3425bb815Sopenharmony_ciThis document describes the steps required to compile the JerryScript 4425bb815Sopenharmony_cifor OpenWrt. For target device the TP-Link WR1043ND v1.x router is 5425bb815Sopenharmony_ciused. Please be advised, that if you have a different one minor 6425bb815Sopenharmony_cimodifications to this document could be required. 7425bb815Sopenharmony_ci 8425bb815Sopenharmony_ciIMPORTANT! 9425bb815Sopenharmony_ci 10425bb815Sopenharmony_ciAs the TP-Link WR1043ND is a mips based device and mips is a big-endian 11425bb815Sopenharmony_ciarchitecture a JerryScipt snapshot which was built on an little-endian 12425bb815Sopenharmony_cisystem will not work correctly. Thus it is advised that the 13425bb815Sopenharmony_cisnapshot functionally should be used with caution, that is 14425bb815Sopenharmony_ciDO NOT run snapshots generated on little-endian system(s) on 15425bb815Sopenharmony_cia big-endian system. 16425bb815Sopenharmony_ci 17425bb815Sopenharmony_ci## OpenWrt notes 18425bb815Sopenharmony_ci 19425bb815Sopenharmony_ciIn 2018 ~January the OpenWrt and LEDE project merged into one 20425bb815Sopenharmony_ciand thus the old OpenWrt parts are now usable only from 21425bb815Sopenharmony_cian archived repository: https://github.com/openwrt/archive 22425bb815Sopenharmony_ci 23425bb815Sopenharmony_ci## OpenWrt toolchain setup 24425bb815Sopenharmony_ci 25425bb815Sopenharmony_ciTo build the JerryScript for OpenWrt a toolchain is required for 26425bb815Sopenharmony_cithe target router/device. The toolchain setup in this document was 27425bb815Sopenharmony_citested on an Ubuntu 16.04.3 LTS Linux. 28425bb815Sopenharmony_ci 29425bb815Sopenharmony_ciSteps required for toolchain creation: 30425bb815Sopenharmony_ci 31425bb815Sopenharmony_ci### 0. Install OpenWrt build requirements 32425bb815Sopenharmony_ci```sh 33425bb815Sopenharmony_ci$ sudo apt-get install git-core build-essential libssl-dev libncurses5-dev unzip gawk zlib1g-dev subversion mercurial 34425bb815Sopenharmony_ci``` 35425bb815Sopenharmony_ci 36425bb815Sopenharmony_ci### 1. Clone OpenWrt (Chaos Calmer version) 37425bb815Sopenharmony_ci 38425bb815Sopenharmony_ci```sh 39425bb815Sopenharmony_ci$ git clone https://github.com/openwrt/archive openwrt -b chaos_calmer 40425bb815Sopenharmony_ci$ cd openwrt 41425bb815Sopenharmony_ci``` 42425bb815Sopenharmony_ci 43425bb815Sopenharmony_ci### 2. Run Menuconfig and configure the OpenWrt 44425bb815Sopenharmony_ci 45425bb815Sopenharmony_ci```sh 46425bb815Sopenharmony_ci$ make menuconfig 47425bb815Sopenharmony_ci``` 48425bb815Sopenharmony_ci 49425bb815Sopenharmony_ciOptions which should be set: 50425bb815Sopenharmony_ci* Set "Target System" to "Atheros AR7xxx/AR9xxx". 51425bb815Sopenharmony_ci* Set "Target Profile" to "TP-LINK TL-WR1043N/ND". 52425bb815Sopenharmony_ci 53425bb815Sopenharmony_ciSave the configuration (as .config) and exit from the menuconfig. 54425bb815Sopenharmony_ci 55425bb815Sopenharmony_ci### 3. Configure the environment variables 56425bb815Sopenharmony_ci 57425bb815Sopenharmony_ci```sh 58425bb815Sopenharmony_ci$ export BUILDROOT=$(pwd) # where the openwrt root dir is 59425bb815Sopenharmony_ci$ export STAGING_DIR=${BUILDROOT}/staging_dir/ # required by the compiler 60425bb815Sopenharmony_ci$ export PATH=$PATH:${STAGING_DIR}/host/bin:${STAGING_DIR}/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/ 61425bb815Sopenharmony_ci``` 62425bb815Sopenharmony_ci 63425bb815Sopenharmony_ciThe name `toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2` is created based on the menuconfig. 64425bb815Sopenharmony_ciThis changes depending on the target device! 65425bb815Sopenharmony_ci 66425bb815Sopenharmony_ci### 4. Build the OpenWrt 67425bb815Sopenharmony_ci 68425bb815Sopenharmony_ci```sh 69425bb815Sopenharmony_ci$ make 70425bb815Sopenharmony_ci``` 71425bb815Sopenharmony_ci 72425bb815Sopenharmony_ci### 5. Check if the compiler was built 73425bb815Sopenharmony_ci 74425bb815Sopenharmony_ci```sh 75425bb815Sopenharmony_ci$ mips-openwrt-linux-gcc --version # running this should print out the version information 76425bb815Sopenharmony_ci``` 77425bb815Sopenharmony_ci 78425bb815Sopenharmony_ciAt this point we have the required compiler for OpenWrt. 79425bb815Sopenharmony_ci 80425bb815Sopenharmony_ci## Build JerryScript for OpenWrt 81425bb815Sopenharmony_ci 82425bb815Sopenharmony_ci### 0. Check environment 83425bb815Sopenharmony_ci 84425bb815Sopenharmony_ciPlease check if the `STAGING_DIR` is configured correctly and that the toolchain binary is on the `PATH`. 85425bb815Sopenharmony_ci 86425bb815Sopenharmony_ci### 1. Run the build with the OpenWrt toolchain file 87425bb815Sopenharmony_ci 88425bb815Sopenharmony_ci``` 89425bb815Sopenharmony_ci$ ./tools/build.py --toolchain cmake/toolchain_openwrt_mips.cmake \ 90425bb815Sopenharmony_ci --lto OFF 91425bb815Sopenharmony_ci``` 92425bb815Sopenharmony_ci 93425bb815Sopenharmony_ci### 2. Copy the binary 94425bb815Sopenharmony_ci 95425bb815Sopenharmony_ciAfter a successful build the `build/bin/jerry` binary file can be copied to the target device. 96425bb815Sopenharmony_ciOn how to copy a binary file to an OpenWrt target device please see the OpenWrt manual(s). 97