summaryrefslogtreecommitdiff
path: root/docs/iotgateimx8_building_running.md
blob: 49b1688dfc9cc295e3eef091aab48edc3f5533af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
iot-gate-imx8 TBBR Building/Running Documents
================================================

This document describes the steps for building and running related
softwares for iot-gate-imx8.

## Debrick Process

Before doing anything. Make sure that you can boot into U-boot prompt by this way because we will easily break things on EMMC later.

### Preparing

First, prepare a SDCard and a USB Stick.
Format the USB stick with VFAT.

Download https://drive.google.com/file/d/14dD9sFTsZ5kfJrhrlahp1P0SrcAx9aKa/view?usp=sharing

Flash the SDCard by "sudo dd if=flash.bin of=/dev/sdX bs=512 seek=66 status=progress; sudo dd if=u-boot.itb of=/dev/sdX bs=512 seek=768"
Put flash.bin and u-boot.itb on USB Stick VFAT partition too.

Insert the SDCard to P14. Insert the USB stick to the USB-A hole on the front panel.

### Debrick

 1. Power Off the machine
 2. Close Jumper E1
 3. Power on the machine
 4. Stop the U-boot auto boot by pressing Enter
 5. You should be U-boot prompt now "IOT-GATE-iMX8 ="
 6. Run "usb reset"
 7. Run "load usb 0 ${loadaddr} flash.bin"
 8. Run "mmc dev 2 1; mmc write ${loadaddr} 0x42 0x250"
 9. Run "load usb 0 ${loadaddr} u-boot.itb"
 10. Run "mmc dev 2 1; mmc write ${loadaddr} 0x300 0x1B00"
 11. Power off the machine
 12. Open Jumper E1


## Building boot images

Build the following images in sequence. They have dependencies.

### U-boot

Source: https://git.linaro.org/people/paul.liu/systemready/u-boot.git
Result: u-boot.bin

Steps:
 1. git clone https://git.linaro.org/people/paul.liu/systemready/u-boot.git
 2. git -C u-boot checkout iot-gate-imx8-paulliu-master
 3. mkdir -p /tmp/u-boot-imx
 4. make -C u-boot O=/tmp/u-boot-imx ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- iot-gate-imx8_defconfig
 5. make -C u-boot O=/tmp/u-boot-imx ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

You should find u-boot.bin in /tmp/u-boot-imx


### OpTEE

Source: https://source.codeaurora.org/external/imx/imx-optee-os
Result: tee-*_v2.bin

Steps: 
 1. git clone https://source.codeaurora.org/external/imx/imx-optee-os
 2. git -C imx-optee-os checkout ${NXP_RELEASE}
 3. git -C imx-optee-os am ${LAYER_DIR}/recipes-security/optee-imx/compulab/imx8mm/*.patch
 4. git -C imx-optee-os cherry-pick 331ebf7eab80eb41828979ff4ba8372691117f30
 5. git -C imx-optee-os cherry-pick b836bfb07cfeadda4a1d90227ffbf9cec14a726d
 6. export ARCH=arm
 7. export CROSS_COMPILE=arm-linux-gnueabihf-
 8. export CROSS_COMPILE64=aarch64-linux-gnu-
 9. cd imx-optee-os
 10. ./scripts/nxp_build.sh mx8mmevk

You should find those binaries in imx-optee-os/build.*/core

### TF-A

Source: https://git.linaro.org/people/paul.liu/systemready/trusted-firmware-a.git
Input: u-boot.bin tee-*_v2.bin
Output: bl2.bin fip.bin

Steps:
 1. git clone https://git.linaro.org/people/paul.liu/systemready/trusted-firmware-a.git
 2. git -C trusted-firmware-a checkout imx8-tbbr-3
 3. git clone https://github.com/ARMmbed/mbedtls.git
 4. make -C trusted-firmware-a ARCH=aarch64 CROSS_COMPILE=aarch64-linux-gnu- \
    PLAT=imx8mm \
    SPD=opteed BL32_BASE=0x7e000000 IMX_BOOT_UART_BASE=0x30880000 \
    NEED_BL32=yes NEED_BL33=yes BUILD_BL2=1 \
    LOG_LEVEL=50 \
    USE_TBBR_DEFS=1 GENERATE_COT=1 TRUSTED_BOARD_BOOT=1 \
    MBEDTLS_DIR=`pwd`/mbedtls \
    BL32=`pwd`/imx-optee-os/build.mx8mmevk/core/tee-header_v2.bin \
    BL32_EXTRA1=`pwd`/imx-optee-os/build.mx8mmevk/core/tee-pager_v2.bin \
    BL32_EXTRA2=`pwd`/imx-optee-os/build.mx8mmevk/core/tee-pageable_v2.bin \
    BL33=/tmp/u-boot-imx/u-boot.bin \
    fip bl2 bl31

You should get bl2.bin and fip.bin in trusted-firmware-a/build/imx8mm/release/

### Flash.bin

We will use u-boot's binman to generate flash.bin
Source: as same as u-boot
Input: bl2.bin fip.bin u-boot-spl.bin
Result: flash.bin
Pre-built image: https://drive.google.com/file/d/14dD9sFTsZ5kfJrhrlahp1P0SrcAx9aKa/view?usp=sharing

And you should get flash.bin and u-boot.itb for replacing the one on board.

## Building Debian related images

### Linux
Source: https://git.linaro.org/people/paul.liu/systemready/linux.git
Branch: linux-compulab
Result: Image sb-iotgimx8.dtb

Steps:
 1. mkdir -p /tmp/linux-imx8
 2. make O=/tmp/linux-imx8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- iot-gate-imx8_defconfig
 3. make O=/tmp/linux-imx8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

You should get the kernel “Image” and the dtb “sb-iotgimx8.dtb”

### Debian Installer EFI image.
Pre-built image: 
https://drive.google.com/file/d/1PGLqCIKzCj0HkOaRe1GFmJu7rDFH1AXq/view?usp=sharing
Input: Image sb-iotgimx8.dtb 

To use the pre-built image, just extract it to a USB stick.

How to build the pre-built D-I EFI image

First, download the Debian installer from 
http://ftp.nl.debian.org/debian/dists/buster/main/installer-arm64/current/images/netboot/
Download the netboot.tar.gz

 1. Extract the tarball. Replace “linux” by “Image”. 
 2. Put sb-iotimx8.dtb to root directory.
 3. Copy efi binaries to EFI/BOOT. 
 4. Add console parameters to grub.cfg 

### Debian kernel package
Result: linux-image-*.deb linux-headers-*.deb
Pre-built image: https://drive.google.com/file/d/1vgN-sRm6a2Gkz1S3VvM13zaAL2jcQHGI/view?usp=sharing


Inside the linux tree
Steps:
 1. export ARCH=arm64
 2. export CROSS_COMPILE=aarch64-linux-gnu-
 3. make iot-gate-imx8_defconfig
 4. make LOCALVERSION=.paulliu-1-arm64 KDEB_PKGVERSION=$(make kernelversion)-1 deb-pkg