Update Iot.js
[platform/upstream/iotjs.git] / tools / docs / build / Build-for-RPi2.md
1 ## Build IoT.js with Raspberry Pi 2
2
3 IoT.js supports two build types:
4
5 1. Build on your desktop. We support Linux(Ubuntu) and macOS. - Cross compile
6 2. Build on Raspberry Pi 2.
7
8 ### Setting Raspberry Pi
9
10 IoT.js officially supports Raspbian. For more information, please visit [the official site](https://www.raspberrypi.org/downloads/raspbian/).
11
12 #### Enable the I2C interface
13
14 To use I2C module, the I2C interface must be enabled.
15
16 From the command line type:
17 ```bash
18 sudo raspi-config
19 ```
20 This will launch raspi-config utility.
21    * Select "9 Advanced Options"
22    * Select "A6 I2C"
23
24 The screen will ask you to enable I2C interface.
25    * Select "Yes"
26    * Select "Ok"
27    * Select "Finish" to return to the command line.
28
29 Reboot your Raspberry Pi.
30
31 #### Enable the PWM interface
32
33 Raspberry Pi2 has two PWM outputs on the following pins.
34
35 | PWM Number | GPIO PIN(FUNC) |
36 | :---: | :---: |
37 | PWM0 | GPIO12(4), GPIO18(2) |
38 | PWM1 | GPIO13(4), GPIO19(2) |
39
40 To use PWM module, you must add PWM overlays in `/boot/config.txt` file.
41
42 For example, to get a single PWM on GPIO18, add overlays like below.
43 ```
44 dtoverlay=pwm,pin=18,func=2
45 ```
46
47 For example, to get multi PWM on GPIO18 and GPIO19, add overlays like below.
48 ```
49 dtoverlay=pwm-2chan,pin=18,func=2,pin2=19,func2=2
50 ```
51
52 For more information about overlays, refer to [README](https://github.com/raspberrypi/linux/blob/rpi-4.9.y/arch/arm/boot/dts/overlays/README).
53
54 * Note that it is necessary to have root privileges in order to run PWM module.
55
56 #### Enable the UART interface
57
58 To use UART module, the UART interface must be enabled.
59
60 In `/boot/config.txt` file, change the value of enable_uart from 0 to 1.
61 ```
62 enable_uart=1
63 ```
64
65 To disable the serial console, edit the file `/boot/cmdline.txt`.
66 remove the word phase ```"console=serial0,115200"``` or ```"console=ttyAMA0,115200"```
67
68 To enable the serial console, edit the file `/boot/cmdline.txt`.
69 add the word phase ```"console=serial0,115200"``` or ```"console=ttyAMA0,115200"```
70
71 Reboot your Raspberry Pi.
72
73 * Note for Raspberry Pi 3 : You should use /dev/ttyS0 instead of /dev/ttyAMA0 in RPI3.
74
75 ### Build IoT.js on your desktop.
76
77 #### Prerequisite
78 ##### Linux
79
80 Install arm linux cross compiler.
81
82 ``` bash
83 sudo apt-get install gcc-arm-linux-gnueabihf
84 ```
85
86 ##### macOS
87
88 Install arm linux cross compiler via [this site](http://www.welzels.de/blog/en/arm-cross-compiling-with-mac-os-x/).
89
90 The default location for arm linux compiler toolchain is **"/usr/local/linaro/arm-linux-gnueabihf-raspbian"**.
91
92 Then you need to locate c_compiler.
93 In **"./cmake/config/arm-linux.cmake"**,
94 ``` cmake
95 SET(EXTERNAL_CMAKE_C_COMPILER
96     /usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
97 ```
98 In **"./deps/libtuv/cmake/config/config_arm-linux.cmake"**,
99 ``` cmake
100 SET(CMAKE_C_COMPILER
101     /usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
102 ```
103
104 #### Build IoT.js (Cross compile)
105 Give `target-arch`, `target-os` and `target-board` options to the script named 'build.py', then the script do the rest for you.
106
107 ``` bash
108 ./tools/build.py --buildtype=[release|debug] --target-arch=arm \
109  --target-os=linux --target-board=rpi2
110 ```
111
112 #### Running in Raspberry Pi 2
113
114 This script gives you `build/arm-linux/release/iotjs/iotjs` or `build/arm-linux/debug/iotjs/iotjs`.
115 Copy this binary with your favorite tool or `scp` like below.
116
117 ``` bash
118 scp build/arm-linux/release/iotjs/iotjs pi@(your RPi2 IP):/home/pi/.
119 ```
120
121 Lastly, open a shell and run with your test program.
122
123 ``` bash
124 ssh pi@(your RPi2 IP)
125 ./iotjs (your test program)
126 ```
127
128 ### Build IoT.js on Raspberry Pi 2
129
130 #### Prerequisite
131 Install cmake.
132 ```bash
133 sudo apt-get update
134 sudo apt-get install cmake
135 ```
136
137 #### Build IoT.js
138 Executing below command will build IoT.js and run our testsuite.
139
140 ``` bash
141 ./tools/build.py --target-board=rpi2
142 ```