##// END OF EJS Templates
raspberry userland...
Unknown -
r333:3ac1c76f0d04
parent child
Show More
@@ -0,0 +1,33
1 #
2 # Setup videocore - Raspberry Userland
3 #
4
5 # Load utility functions
6 . ./functions.sh
7
8 if [ "$ENABLE_VIDEOCORE" = true ] ; then
9 # Copy existing videocore sources into chroot directory
10 if [ -n "$VIDEOCORESRC_DIR" ] && [ -d "$VIDEOCORESRC_DIR" ] ; then
11 # Copy local U-Boot sources
12 cp -r "${VIDEOCORESRC_DIR}" "${R}/tmp"
13 else
14 # Create temporary directory for U-Boot sources
15 temp_dir=$(as_nobody mktemp -d)
16
17 # Fetch U-Boot sources
18 as_nobody git -C "${temp_dir}" clone "${VIDEOCORE_URL}"
19
20 # Copy downloaded U-Boot sources
21 mv "${temp_dir}/userland" "${R}/tmp/"
22
23 # Set permissions of the U-Boot sources
24 chown -R root:root "${R}/tmp/userland"
25
26 # Remove temporary directory for U-Boot sources
27 rm -fr "${temp_dir}"
28 fi
29
30 cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DARM64=ON -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_ASM_COMPILER=aarch64-linux-gnu-gcc -DVIDEOCORE_BUILD_DIR="${R}"/opt/vc
31 make -j $(nproc)
32 chroot_exec PATH=${PATH}:/opt/vc/bin
33 fi
@@ -1,481 +1,487
1 1 # rpi23-gen-image
2 2 ## Introduction
3 3 `rpi23-gen-image.sh` is an advanced Debian Linux bootstrapping shell script for generating Debian OS images for Raspberry Pi 2 (RPi2) and Raspberry Pi 3 (RPi3) computers. The script at this time supports the bootstrapping of the Debian (armhf) releases `stretch` and `buster`. Raspberry Pi 3 images are generated for 32-bit mode only. Raspberry Pi 3 64-bit images can be generated using custom configuration parameters (```templates/rpi3-stretch-arm64-4.11.y```).
4 4
5 5 ## Build dependencies
6 6 The following list of Debian packages must be installed on the build system because they are essentially required for the bootstrapping process. The script will check if all required packages are installed and missing packages will be installed automatically if confirmed by the user.
7 7
8 8 ```debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo```
9 9
10 10 It is recommended to configure the `rpi23-gen-image.sh` script to build and install the latest Raspberry Pi Linux kernel. For the RPi3 this is mandatory. Kernel compilation and linking will be performed on the build system using an ARM (armhf) cross-compiler toolchain.
11 11
12 12 The script has been tested using the default `crossbuild-essential-armhf` toolchain meta package on Debian Linux and `stretch` build systems. Please check the [Debian CrossToolchains Wiki](https://wiki.debian.org/CrossToolchains) for further information.
13 13
14 14 ## Command-line parameters
15 15 The script accepts certain command-line parameters to enable or disable specific OS features, services and configuration settings. These parameters are passed to the `rpi23-gen-image.sh` script via (simple) shell-variables. Unlike environment shell-variables (simple) shell-variables are defined at the beginning of the command-line call of the `rpi23-gen-image.sh` script.
16 16
17 17 ##### Command-line examples:
18 18 ```shell
19 19 ENABLE_UBOOT=true ./rpi23-gen-image.sh
20 20 ENABLE_CONSOLE=false ENABLE_IPV6=false ./rpi23-gen-image.sh
21 21 ENABLE_WM=xfce4 ENABLE_FBTURBO=true ENABLE_MINBASE=true ./rpi23-gen-image.sh
22 22 ENABLE_HARDNET=true ENABLE_IPTABLES=true /rpi23-gen-image.sh
23 23 APT_SERVER=ftp.de.debian.org APT_PROXY="http://127.0.0.1:3142/" ./rpi23-gen-image.sh
24 24 ENABLE_MINBASE=true ./rpi23-gen-image.sh
25 25 BUILD_KERNEL=true ENABLE_MINBASE=true ENABLE_IPV6=false ./rpi23-gen-image.sh
26 26 BUILD_KERNEL=true KERNELSRC_DIR=/tmp/linux ./rpi23-gen-image.sh
27 27 ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi23-gen-image.sh
28 28 ENABLE_CRYPTFS=true CRYPTFS_PASSWORD=changeme EXPANDROOT=false ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi23-gen-image.sh
29 29 RELEASE=stretch BUILD_KERNEL=true ./rpi23-gen-image.sh
30 30 RPI_MODEL=3 ENABLE_WIRELESS=true ENABLE_MINBASE=true BUILD_KERNEL=true ./rpi23-gen-image.sh
31 31 RELEASE=stretch RPI_MODEL=3 ENABLE_WIRELESS=true ENABLE_MINBASE=true BUILD_KERNEL=true ./rpi23-gen-image.sh
32 32 ```
33 33
34 34 ## Configuration template files
35 35 To avoid long lists of command-line parameters and to help to store the favourite parameter configurations the `rpi23-gen-image.sh` script supports so called configuration template files (`CONFIG_TEMPLATE`=template). These are simple text files located in the `./templates` directory that contain the list of configuration parameters that will be used. New configuration template files can be added to the `./templates` directory.
36 36
37 37 ##### Command-line examples:
38 38 ```shell
39 39 CONFIG_TEMPLATE=rpi3stretch ./rpi23-gen-image.sh
40 40 CONFIG_TEMPLATE=rpi2stretch ./rpi23-gen-image.sh
41 41 ```
42 42
43 43 ## Supported parameters and settings
44 44 #### APT settings:
45 45 ##### `APT_SERVER`="ftp.debian.org/debian"
46 46 Set Debian packages server address. Choose a server from the list of Debian worldwide [mirror sites](https://www.debian.org/mirror/list). Using a nearby server will probably speed-up all required downloads within the bootstrapping process.
47 47
48 48 ##### `APT_PROXY`=""
49 49 Set Proxy server address. Using a local Proxy-Cache like `apt-cacher-ng` will speed-up the bootstrapping process because all required Debian packages will only be downloaded from the Debian mirror site once.
50 50
51 51 ##### `APT_INCLUDES`=""
52 52 A comma separated list of additional packages to be installed by debootstrap during bootstrapping.
53 53
54 54 ##### `APT_INCLUDES_LATE`=""
55 55 A comma separated list of additional packages to be installed by apt after bootstrapping and after APT sources are set up. This is useful for packages with pre-depends, which debootstrap do not handle well.
56 56
57 57 ---
58 58
59 59 #### General system settings:
60 60 ##### `RPI_MODEL`=2
61 61 Specifiy the target Raspberry Pi hardware model. The script at this time supports the following Raspberry Pi models:
62 62 `0` = Used for Raspberry Pi 0 and Raspberry Pi 0 W
63 63 `1` = Used for Pi 1 model A and B
64 64 `1P` = Used for Pi 1 model B+ and A+
65 65 `2` = Used for Pi 2 model B
66 66 `3` = Used for Pi 3 model B
67 67 `3P` = Used for Pi 3 model B+
68 68 `BUILD_KERNEL`=true will automatically be set if the Raspberry Pi model `3` or `3P` is used.
69 69
70 70 ##### `RELEASE`="buster"
71 71 Set the desired Debian release name. The script at this time supports the bootstrapping of the Debian releases "stretch" and "buster". `BUILD_KERNEL`=true will automatically be set if the Debian releases `stretch` or `buster` are used.
72 72
73 73 ##### `RELEASE_ARCH`="armhf"
74 74 Set the desired Debian release architecture.
75 75
76 76 ##### `HOSTNAME`="rpi$RPI_MODEL-$RELEASE"
77 77 Set system host name. It's recommended that the host name is unique in the corresponding subnet.
78 78
79 79 ##### `PASSWORD`="raspberry"
80 80 Set system `root` password. It's **STRONGLY** recommended that you choose a custom password.
81 81
82 82 ##### `USER_PASSWORD`="raspberry"
83 83 Set password for the created non-root user `USER_NAME`=pi. Ignored if `ENABLE_USER`=false. It's **STRONGLY** recommended that you choose a custom password.
84 84
85 85 ##### `DEFLOCAL`="en_US.UTF-8"
86 86 Set default system locale. This setting can also be changed inside the running OS using the `dpkg-reconfigure locales` command. Please note that on using this parameter the script will automatically install the required packages `locales`, `keyboard-configuration` and `console-setup`.
87 87
88 88 ##### `TIMEZONE`="Europe/Berlin"
89 89 Set default system timezone. All available timezones can be found in the `/usr/share/zoneinfo/` directory. This setting can also be changed inside the running OS using the `dpkg-reconfigure tzdata` command.
90 90
91 91 ##### `EXPANDROOT`=true
92 92 Expand the root partition and filesystem automatically on first boot.
93 93
94 94 ##### `ENABLE_QEMU`=false
95 95 Generate kernel (`vexpress_defconfig`), file system image (`qcow2`) and DTB files that can be used for QEMU full system emulation (`vexpress-A15`). The output files are stored in the `$(pwd)/images/qemu` directory. You can find more information about running the generated image in the QEMU section of this readme file.
96 96
97 97 ---
98 98
99 99 #### Keyboard settings:
100 100 These options are used to configure keyboard layout in `/etc/default/keyboard` for console and Xorg. These settings can also be changed inside the running OS using the `dpkg-reconfigure keyboard-configuration` command.
101 101
102 102 ##### `XKB_MODEL`=""
103 103 Set the name of the model of your keyboard type.
104 104
105 105 ##### `XKB_LAYOUT`=""
106 106 Set the supported keyboard layout(s).
107 107
108 108 ##### `XKB_VARIANT`=""
109 109 Set the supported variant(s) of the keyboard layout(s).
110 110
111 111 ##### `XKB_OPTIONS`=""
112 112 Set extra xkb configuration options.
113 113
114 114 ---
115 115
116 116 #### Networking settings (DHCP):
117 117 This parameter is used to set up networking auto configuration in `/etc/systemd/network/eth.network`. The default location of network configuration files in the Debian `stretch` release was changed to `/lib/systemd/network`.`
118 118
119 119 ##### `ENABLE_DHCP`=true
120 120 Set the system to use DHCP. This requires an DHCP server.
121 121
122 122 ---
123 123
124 124 #### Networking settings (static):
125 125 These parameters are used to set up a static networking configuration in `/etc/systemd/network/eth.network`. The following static networking parameters are only supported if `ENABLE_DHCP` was set to `false`. The default location of network configuration files in the Debian `stretch` release was changed to `/lib/systemd/network`.
126 126
127 127 ##### `NET_ADDRESS`=""
128 128 Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24".
129 129
130 130 ##### `NET_GATEWAY`=""
131 131 Set the IP address for the default gateway.
132 132
133 133 ##### `NET_DNS_1`=""
134 134 Set the IP address for the first DNS server.
135 135
136 136 ##### `NET_DNS_2`=""
137 137 Set the IP address for the second DNS server.
138 138
139 139 ##### `NET_DNS_DOMAINS`=""
140 140 Set the default DNS search domains to use for non fully qualified host names.
141 141
142 142 ##### `NET_NTP_1`=""
143 143 Set the IP address for the first NTP server.
144 144
145 145 ##### `NET_NTP_2`=""
146 146 Set the IP address for the second NTP server.
147 147
148 148 ---
149 149
150 150 #### Basic system features:
151 151 ##### `ENABLE_CONSOLE`=true
152 152 Enable serial console interface. Recommended if no monitor or keyboard is connected to the RPi2/3. In case of problems fe. if the network (auto) configuration failed - the serial console can be used to access the system.
153 153
154 154 ##### `ENABLE_I2C`=false
155 155 Enable I2C interface on the RPi2/3. Please check the [RPi2/3 pinout diagrams](https://elinux.org/RPi_Low-level_peripherals) to connect the right GPIO pins.
156 156
157 157 ##### `ENABLE_SPI`=false
158 158 Enable SPI interface on the RPi2/3. Please check the [RPi2/3 pinout diagrams](https://elinux.org/RPi_Low-level_peripherals) to connect the right GPIO pins.
159 159
160 160 ##### `ENABLE_IPV6`=true
161 161 Enable IPv6 support. The network interface configuration is managed via systemd-networkd.
162 162
163 163 ##### `ENABLE_SSHD`=true
164 164 Install and enable OpenSSH service. The default configuration of the service doesn't allow `root` to login. Please use the user `pi` instead and `su -` or `sudo` to execute commands as root.
165 165
166 166 ##### `ENABLE_NONFREE`=false
167 167 Allow the installation of non-free Debian packages that do not comply with the DFSG. This is required to install closed-source firmware binary blobs.
168 168
169 169 ##### `ENABLE_WIRELESS`=false
170 170 Download and install the [closed-source firmware binary blob](https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm) that is required to run the internal wireless interface of the Raspberry Pi model `3`. This parameter is ignored if the specified `RPI_MODEL` is not `3`.
171 171
172 172 ##### `ENABLE_RSYSLOG`=true
173 173 If set to false, disable and uninstall rsyslog (so logs will be available only
174 174 in journal files)
175 175
176 176 ##### `ENABLE_SOUND`=true
177 177 Enable sound hardware and install Advanced Linux Sound Architecture.
178 178
179 179 ##### `ENABLE_HWRANDOM`=true
180 180 Enable Hardware Random Number Generator. Strong random numbers are important for most network based communications that use encryption. It's recommended to be enabled.
181 181
182 182 ##### `ENABLE_MINGPU`=false
183 183 Minimize the amount of shared memory reserved for the GPU. It doesn't seem to be possible to fully disable the GPU.
184 184
185 185 ##### `ENABLE_DBUS`=true
186 186 Install and enable D-Bus message bus. Please note that systemd should work without D-bus but it's recommended to be enabled.
187 187
188 188 ##### `ENABLE_XORG`=false
189 189 Install Xorg open-source X Window System.
190 190
191 191 ##### `ENABLE_WM`=""
192 192 Install a user defined window manager for the X Window System. To make sure all X related package dependencies are getting installed `ENABLE_XORG` will automatically get enabled if `ENABLE_WM` is used. The `rpi23-gen-image.sh` script has been tested with the following list of window managers: `blackbox`, `openbox`, `fluxbox`, `jwm`, `dwm`, `xfce4`, `awesome`.
193 193
194 194 ---
195 195
196 196 #### Advanced system features:
197 197 ##### `ENABLE_MINBASE`=false
198 198 Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB.
199 199
200 200 ##### `ENABLE_REDUCE`=false
201 201 Reduce the disk space usage by deleting packages and files. See `REDUCE_*` parameters for detailed information.
202 202
203 203 ##### `ENABLE_UBOOT`=false
204 204 Replace the default RPi2/3 second stage bootloader (bootcode.bin) with [U-Boot bootloader](https://git.denx.de/?p=u-boot.git;a=summary). U-Boot can boot images via the network using the BOOTP/TFTP protocol.
205 205
206 206 ##### `UBOOTSRC_DIR`=""
207 207 Path to a directory (`u-boot`) of [U-Boot bootloader sources](https://git.denx.de/?p=u-boot.git;a=summary) that will be copied, configured, build and installed inside the chroot.
208 208
209 209 ##### `ENABLE_FBTURBO`=false
210 210 Install and enable the [hardware accelerated Xorg video driver](https://github.com/ssvb/xf86-video-fbturbo) `fbturbo`. Please note that this driver is currently limited to hardware accelerated window moving and scrolling.
211 211
212 212 ##### `FBTURBOSRC_DIR`=""
213 213 Path to a directory (`xf86-video-fbturbo`) of [hardware accelerated Xorg video driver sources](https://github.com/ssvb/xf86-video-fbturbo) that will be copied, configured, build and installed inside the chroot.
214 214
215 ##### `ENABLE_VIDEOCORE`=false
216 Install and enable the [Source code for ARM side libraries for interfacing to Raspberry Pi GPU](https://github.com/raspberrypi/userland) `vcgencmd`. Please note that this driver is currently limited to hardware accelerated window moving and scrolling.
217
218 ##### `VIDEOCORESRC_DIR`=""
219 Path to a directory (`userland`) of [Source code for ARM side libraries for interfacing to Raspberry Pi GPU](https://github.com/raspberrypi/userland) that will be copied, configured, build and installed inside the chroot.
220
215 221 ##### `ENABLE_IPTABLES`=false
216 222 Enable iptables IPv4/IPv6 firewall. Simplified ruleset: Allow all outgoing connections. Block all incoming connections except to OpenSSH service.
217 223
218 224 ##### `ENABLE_USER`=true
219 225 Create non-root user with password `USER_PASSWORD`=raspberry. Unless overridden with `USER_NAME`=user, username will be `pi`.
220 226
221 227 ##### `USER_NAME`=pi
222 228 Non-root user to create. Ignored if `ENABLE_USER`=false
223 229
224 230 ##### `ENABLE_ROOT`=false
225 231 Set root user password so root login will be enabled
226 232
227 233 ##### `ENABLE_HARDNET`=false
228 234 Enable IPv4/IPv6 network stack hardening settings.
229 235
230 236 ##### `ENABLE_SPLITFS`=false
231 237 Enable having root partition on an USB drive by creating two image files: one for the `/boot/firmware` mount point, and another for `/`.
232 238
233 239 ##### `CHROOT_SCRIPTS`=""
234 240 Path to a directory with scripts that should be run in the chroot before the image is finally built. Every executable file in this directory is run in lexicographical order.
235 241
236 242 ##### `ENABLE_INITRAMFS`=false
237 243 Create an initramfs that that will be loaded during the Linux startup process. `ENABLE_INITRAMFS` will automatically get enabled if `ENABLE_CRYPTFS`=true. This parameter will be ignored if `BUILD_KERNEL`=false.
238 244
239 245 ##### `ENABLE_IFNAMES`=true
240 246 Enable automatic assignment of predictable, stable network interface names for all local Ethernet, WLAN interfaces. This might create complex and long interface names. This parameter is only supported if the Debian releases `stretch` or `buster` are used.
241 247
242 248 ##### `DISABLE_UNDERVOLT_WARNINGS`=
243 249 Disable RPi2/3 under-voltage warnings and overlays. Setting the parameter to `1` will disable the warning overlay. Setting it to `2` will additionally allow RPi2/3 turbo mode when low-voltage is present.
244 250
245 251 ---
246 252
247 253 #### SSH settings:
248 254 ##### `SSH_ENABLE_ROOT`=false
249 255 Enable password root login via SSH. This may be a security risk with default password, use only in trusted environments. `ENABLE_ROOT` must be set to `true`.
250 256
251 257 ##### `SSH_DISABLE_PASSWORD_AUTH`=false
252 258 Disable password based SSH authentication. Only public key based SSH (v2) authentication will be supported.
253 259
254 260 ##### `SSH_LIMIT_USERS`=false
255 261 Limit the users that are allowed to login via SSH. Only allow user `USER_NAME`=pi and root if `SSH_ENABLE_ROOT`=true to login. This parameter will be ignored if `dropbear` SSH is used (`REDUCE_SSHD`=true).
256 262
257 263 ##### `SSH_ROOT_PUB_KEY`=""
258 264 Add SSH (v2) public key(s) from specified file to `authorized_keys` file to enable public key based SSH (v2) authentication of user `root`. The specified file can also contain multiple SSH (v2) public keys. SSH protocol version 1 is not supported. `ENABLE_ROOT` **and** `SSH_ENABLE_ROOT` must be set to `true`.
259 265
260 266 ##### `SSH_USER_PUB_KEY`=""
261 267 Add SSH (v2) public key(s) from specified file to `authorized_keys` file to enable public key based SSH (v2) authentication of user `USER_NAME`=pi. The specified file can also contain multiple SSH (v2) public keys. SSH protocol version 1 is not supported.
262 268
263 269 ---
264 270
265 271 #### Kernel compilation:
266 272 ##### `BUILD_KERNEL`=false
267 273 Build and install the latest RPi2/3 Linux kernel. Currently only the default RPi2/3 kernel configuration is used. `BUILD_KERNEL`=true will automatically be set if the Raspberry Pi model `3` is used.
268 274
269 275 ##### `CROSS_COMPILE`="arm-linux-gnueabihf-"
270 276 This sets the cross compile enviornment for the compiler.
271 277
272 278 ##### `KERNEL_ARCH`="arm"
273 279 This sets the kernel architecture for the compiler.
274 280
275 281 ##### `KERNEL_IMAGE`="kernel7.img"
276 282 Name of the image file in the boot partition. If not set, `KERNEL_IMAGE` will be set to "kernel8.img" automatically if building for arm64.
277 283
278 284 ##### `KERNEL_BRANCH`=""
279 285 Name of the requested branch from the GIT location for the RPi Kernel. Default is using the current default branch from the GIT site.
280 286
281 287 ##### `QEMU_BINARY`="/usr/bin/qemu-arm-static"
282 288 Sets the QEMU enviornment for the Debian archive. If not set, `QEMU_BINARY` will be set to "/usr/bin/qemu-aarch64-static" automatically if building for arm64.
283 289
284 290 ##### `KERNEL_DEFCONFIG`="bcm2709_defconfig"
285 291 Sets the default config for kernel compiling. If not set, `KERNEL_DEFCONFIG` will be set to "bcmrpi3\_defconfig" automatically if building for arm64.
286 292
287 293 ##### `KERNEL_REDUCE`=false
288 294 Reduce the size of the generated kernel by removing unwanted device, network and filesystem drivers (experimental).
289 295
290 296 ##### `KERNEL_THREADS`=1
291 297 Number of parallel kernel building threads. If the parameter is left untouched the script will automatically determine the number of CPU cores to set the number of parallel threads to speed the kernel compilation.
292 298
293 299 ##### `KERNEL_HEADERS`=true
294 300 Install kernel headers with built kernel.
295 301
296 302 ##### `KERNEL_MENUCONFIG`=false
297 303 Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated.
298 304
299 305 ##### `KERNEL_OLDDEFCONFIG`=false
300 306 Run `make olddefconfig` to automatically set all new kernel configuration options to their recommended default values.
301 307
302 308 ##### `KERNEL_CCACHE`=false
303 309 Compile the kernel using ccache. This speeds up kernel recompilation by caching previous compilations and detecting when the same compilation is being done again.
304 310
305 311 ##### `KERNEL_REMOVESRC`=true
306 312 Remove all kernel sources from the generated OS image after it was built and installed.
307 313
308 314 ##### `KERNELSRC_DIR`=""
309 315 Path to a directory (`linux`) of [RaspberryPi Linux kernel sources](https://github.com/raspberrypi/linux) that will be copied, configured, build and installed inside the chroot.
310 316
311 317 ##### `KERNELSRC_CLEAN`=false
312 318 Clean the existing kernel sources directory `KERNELSRC_DIR` (using `make mrproper`) after it was copied to the chroot and before the compilation of the kernel has started. This parameter will be ignored if no `KERNELSRC_DIR` was specified or if `KERNELSRC_PREBUILT`=true.
313 319
314 320 ##### `KERNELSRC_CONFIG`=true
315 321 Run `make bcm2709_defconfig` (and optional `make menuconfig`) to configure the kernel sources before building. This parameter is automatically set to `true` if no existing kernel sources directory was specified using `KERNELSRC_DIR`. This parameter is ignored if `KERNELSRC_PREBUILT`=true.
316 322
317 323 ##### `KERNELSRC_USRCONFIG`=""
318 324 Copy own config file to kernel `.config`. If `KERNEL_MENUCONFIG`=true then running after copy.
319 325
320 326 ##### `KERNELSRC_PREBUILT`=false
321 327 With this parameter set to true the script expects the existing kernel sources directory to be already successfully cross-compiled. The parameters `KERNELSRC_CLEAN`, `KERNELSRC_CONFIG`, `KERNELSRC_USRCONFIG` and `KERNEL_MENUCONFIG` are ignored and no kernel compilation tasks are performed.
322 328
323 329 ##### `RPI_FIRMWARE_DIR`=""
324 330 The directory (`firmware`) containing a local copy of the firmware from the [RaspberryPi firmware project](https://github.com/raspberrypi/firmware). Default is to download the latest firmware directly from the project.
325 331
326 332 ---
327 333
328 334 #### Reduce disk usage:
329 335 The following list of parameters is ignored if `ENABLE_REDUCE`=false.
330 336
331 337 ##### `REDUCE_APT`=true
332 338 Configure APT to use compressed package repository lists and no package caching files.
333 339
334 340 ##### `REDUCE_DOC`=true
335 341 Remove all doc files (harsh). Configure APT to not include doc files on future `apt-get` package installations.
336 342
337 343 ##### `REDUCE_MAN`=true
338 344 Remove all man pages and info files (harsh). Configure APT to not include man pages on future `apt-get` package installations.
339 345
340 346 ##### `REDUCE_VIM`=false
341 347 Replace `vim-tiny` package by `levee` a tiny vim clone.
342 348
343 349 ##### `REDUCE_BASH`=false
344 350 Remove `bash` package and switch to `dash` shell (experimental).
345 351
346 352 ##### `REDUCE_HWDB`=true
347 353 Remove PCI related hwdb files (experimental).
348 354
349 355 ##### `REDUCE_SSHD`=true
350 356 Replace `openssh-server` with `dropbear`.
351 357
352 358 ##### `REDUCE_LOCALE`=true
353 359 Remove all `locale` translation files.
354 360
355 361 ---
356 362
357 363 #### Encrypted root partition:
358 364 ##### `ENABLE_CRYPTFS`=false
359 365 Enable full system encryption with dm-crypt. Setup a fully LUKS encrypted root partition (aes-xts-plain64:sha512) and generate required initramfs. The /boot directory will not be encrypted. This parameter will be ignored if `BUILD_KERNEL`=false. `ENABLE_CRYPTFS` is experimental. SSH-to-initramfs is currently not supported but will be soon - feel free to help.
360 366
361 367 ##### `CRYPTFS_PASSWORD`=""
362 368 Set password of the encrypted root partition. This parameter is mandatory if `ENABLE_CRYPTFS`=true.
363 369
364 370 ##### `CRYPTFS_MAPPING`="secure"
365 371 Set name of dm-crypt managed device-mapper mapping.
366 372
367 373 ##### `CRYPTFS_CIPHER`="aes-xts-plain64:sha512"
368 374 Set cipher specification string. `aes-xts*` ciphers are strongly recommended.
369 375
370 376 ##### `CRYPTFS_XTSKEYSIZE`=512
371 377 Sets key size in bits. The argument has to be a multiple of 8.
372 378
373 379 ---
374 380
375 381 #### Build settings:
376 382 ##### `BASEDIR`=$(pwd)/images/${RELEASE}
377 383 Set a path to a working directory used by the script to generate an image.
378 384
379 385 ##### `IMAGE_NAME`=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}
380 386 Set a filename for the output file(s). Note: the script will create $IMAGE_NAME.img if `ENABLE_SPLITFS`=false or $IMAGE_NAME-frmw.img and $IMAGE_NAME-root.img if `ENABLE_SPLITFS`=true. Note 2: If the KERNEL_BRANCH is not set, the word "CURRENT" is used.
381 387
382 388 ## Understanding the script
383 389 The functions of this script that are required for the different stages of the bootstrapping are split up into single files located inside the `bootstrap.d` directory. During the bootstrapping every script in this directory gets executed in lexicographical order:
384 390
385 391 | Script | Description |
386 392 | --- | --- |
387 393 | `10-bootstrap.sh` | Debootstrap basic system |
388 394 | `11-apt.sh` | Setup APT repositories |
389 395 | `12-locale.sh` | Setup Locales and keyboard settings |
390 396 | `13-kernel.sh` | Build and install RPi2/3 Kernel |
391 397 | `14-fstab.sh` | Setup fstab and initramfs |
392 398 | `15-rpi-config.sh` | Setup RPi2/3 config and cmdline |
393 399 | `20-networking.sh` | Setup Networking |
394 400 | `21-firewall.sh` | Setup Firewall |
395 401 | `30-security.sh` | Setup Users and Security settings |
396 402 | `31-logging.sh` | Setup Logging |
397 403 | `32-sshd.sh` | Setup SSH and public keys |
398 404 | `41-uboot.sh` | Build and Setup U-Boot |
399 405 | `42-fbturbo.sh` | Build and Setup fbturbo Xorg driver |
400 406 | `50-firstboot.sh` | First boot actions |
401 407 | `99-reduce.sh` | Reduce the disk space usage |
402 408
403 409 All the required configuration files that will be copied to the generated OS image are located inside the `files` directory. It is not recommended to modify these configuration files manually.
404 410
405 411 | Directory | Description |
406 412 | --- | --- |
407 413 | `apt` | APT management configuration files |
408 414 | `boot` | Boot and RPi2/3 configuration files |
409 415 | `dpkg` | Package Manager configuration |
410 416 | `etc` | Configuration files and rc scripts |
411 417 | `firstboot` | Scripts that get executed on first boot |
412 418 | `initramfs` | Initramfs scripts |
413 419 | `iptables` | Firewall configuration files |
414 420 | `locales` | Locales configuration |
415 421 | `modules` | Kernel Modules configuration |
416 422 | `mount` | Fstab configuration |
417 423 | `network` | Networking configuration files |
418 424 | `sysctl.d` | Swapping and Network Hardening configuration |
419 425 | `xorg` | fbturbo Xorg driver configuration |
420 426
421 427 ## Custom packages and scripts
422 428 Debian custom packages, i.e. those not in the debian repositories, can be installed by placing them in the `packages` directory. They are installed immediately after packages from the repositories are installed. Any dependencies listed in the custom packages will be downloaded automatically from the repositories. Do not list these custom packages in `APT_INCLUDES`.
423 429
424 430 Scripts in the custom.d directory will be executed after all other installation is complete but before the image is created.
425 431
426 432 ## Logging of the bootstrapping process
427 433 All information related to the bootstrapping process and the commands executed by the `rpi23-gen-image.sh` script can easily be saved into a logfile. The common shell command `script` can be used for this purpose:
428 434
429 435 ```shell
430 436 script -c 'APT_SERVER=ftp.de.debian.org ./rpi23-gen-image.sh' ./build.log
431 437 ```
432 438
433 439 ## Flashing the image file
434 440 After the image file was successfully created by the `rpi23-gen-image.sh` script it can be copied to the microSD card that will be used by the RPi2/3 computer. This can be performed by using the tools `bmaptool` or `dd`. Using `bmaptool` will probably speed-up the copy process because `bmaptool` copies more wisely than `dd`.
435 441
436 442 ##### Flashing examples:
437 443 ```shell
438 444 bmaptool copy ./images/jessie/2017-01-23-rpi3-jessie.img /dev/mmcblk0
439 445 dd bs=4M if=./images/jessie/2017-01-23-rpi3-jessie.img of=/dev/mmcblk0
440 446 ```
441 447 If you have set `ENABLE_SPLITFS`, copy the `-frmw` image on the microSD card, then the `-root` one on the USB drive:
442 448 ```shell
443 449 bmaptool copy ./images/jessie/2017-01-23-rpi3-jessie-frmw.img /dev/mmcblk0
444 450 bmaptool copy ./images/jessie/2017-01-23-rpi3-jessie-root.img /dev/sdc
445 451 ```
446 452
447 453 ## QEMU emulation
448 454 Start QEMU full system emulation:
449 455 ```shell
450 456 qemu-system-arm -m 2048M -M vexpress-a15 -cpu cortex-a15 -kernel kernel7.img -no-reboot -dtb vexpress-v2p-ca15_a7.dtb -sd ${IMAGE_NAME}.qcow2 -append "root=/dev/mmcblk0p2 rw rootfstype=ext4 console=tty1"
451 457 ```
452 458
453 459 Start QEMU full system emulation and output to console:
454 460 ```shell
455 461 qemu-system-arm -m 2048M -M vexpress-a15 -cpu cortex-a15 -kernel kernel7.img -no-reboot -dtb vexpress-v2p-ca15_a7.dtb -sd ${IMAGE_NAME}.qcow2 -append "root=/dev/mmcblk0p2 rw rootfstype=ext4 console=ttyAMA0,115200 init=/bin/systemd" -serial stdio
456 462 ```
457 463
458 464 Start QEMU full system emulation with SMP and output to console:
459 465 ```shell
460 466 qemu-system-arm -m 2048M -M vexpress-a15 -cpu cortex-a15 -smp cpus=2,maxcpus=2 -kernel kernel7.img -no-reboot -dtb vexpress-v2p-ca15_a7.dtb -sd ${IMAGE_NAME}.qcow2 -append "root=/dev/mmcblk0p2 rw rootfstype=ext4 console=ttyAMA0,115200 init=/bin/systemd" -serial stdio
461 467 ```
462 468
463 469 Start QEMU full system emulation with cryptfs, initramfs and output to console:
464 470 ```shell
465 471 qemu-system-arm -m 2048M -M vexpress-a15 -cpu cortex-a15 -kernel kernel7.img -no-reboot -dtb vexpress-v2p-ca15_a7.dtb -sd ${IMAGE_NAME}.qcow2 -initrd "initramfs-${KERNEL_VERSION}" -append "root=/dev/mapper/secure cryptdevice=/dev/mmcblk0p2:secure rw rootfstype=ext4 console=ttyAMA0,115200 init=/bin/systemd" -serial stdio
466 472 ```
467 473
468 474 ## Weekly image builds
469 475 The image files are provided by JRWR'S I/O PORT and are built once a Sunday at midnight UTC!
470 476 * [Debian Stretch Raspberry Pi2/3 Weekly Image Builds](https://jrwr.io/doku.php?id=projects:debianpi)
471 477
472 478 ## External links and references
473 479 * [Debian worldwide mirror sites](https://www.debian.org/mirror/list)
474 480 * [Debian Raspberry Pi 2 Wiki](https://wiki.debian.org/RaspberryPi2)
475 481 * [Debian CrossToolchains Wiki](https://wiki.debian.org/CrossToolchains)
476 482 * [Official Raspberry Pi Firmware on github](https://github.com/raspberrypi/firmware)
477 483 * [Official Raspberry Pi Kernel on github](https://github.com/raspberrypi/linux)
478 484 * [U-BOOT git repository](https://git.denx.de/?p=u-boot.git;a=summary)
479 485 * [Xorg DDX driver fbturbo](https://github.com/ssvb/xf86-video-fbturbo)
480 486 * [RPi3 Wireless interface firmware](https://github.com/RPi-Distro/firmware-nonfree/tree/master/brcm80211/brcm)
481 487 * [Collabora RPi2 Kernel precompiled](https://repositories.collabora.co.uk/debian/)
@@ -1,784 +1,797
1 1 #!/bin/bash
2 2 ########################################################################
3 3 # rpi23-gen-image.sh 2015-2017
4 4 #
5 5 # Advanced Debian "stretch" and "buster" bootstrap script for RPi2/3
6 6 #
7 7 # This program is free software; you can redistribute it and/or
8 8 # modify it under the terms of the GNU General Public License
9 9 # as published by the Free Software Foundation; either version 2
10 10 # of the License, or (at your option) any later version.
11 11 #
12 12 # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
13 13 #
14 14 # Big thanks for patches and enhancements by 20+ github contributors!
15 15 ########################################################################
16 16
17 17 # Are we running as root?
18 18 if [ "$(id -u)" -ne "0" ] ; then
19 19 echo "error: this script must be executed with root privileges!"
20 20 exit 1
21 21 fi
22 22
23 23 # Check if ./functions.sh script exists
24 24 if [ ! -r "./functions.sh" ] ; then
25 25 echo "error: './functions.sh' required script not found!"
26 26 exit 1
27 27 fi
28 28
29 29 # Load utility functions
30 30 . ./functions.sh
31 31
32 32 # Load parameters from configuration template file
33 33 if [ -n "$CONFIG_TEMPLATE" ] ; then
34 34 use_template
35 35 fi
36 36
37 37 # Introduce settings
38 38 set -e
39 39 echo -n -e "\n#\n# RPi2/3 Bootstrap Settings\n#\n"
40 40 set -x
41 41
42 42 # Raspberry Pi model configuration
43 43 export RPI_MODEL=${RPI_MODEL:=2}
44 44
45 45 # Debian release
46 46 export RELEASE=${RELEASE:=buster}
47 47
48 48 #Kernel Branch
49 49 export KERNEL_BRANCH=${KERNEL_BRANCH:=""}
50 50
51 51 # URLs
52 52 export KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
53 53 export FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
54 54 export WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm}
55 55 export FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
56 56 export UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git}
57 export VIDEOCORE_URL=${VIDEOCORE_URL=https://github.com/raspberrypi/userland}
57 58
58 59 # Firmware directory: Blank if download from github
59 60 export RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
60 61
61 62 # Build directories
62 63 export BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}}
63 64 export BUILDDIR="${BASEDIR}/build"
64 65
65 66 # Prepare date string for default image file name
66 67 DATE="$(date +%Y-%m-%d)"
67 68 if [ -z "$KERNEL_BRANCH" ] ; then
68 69 export IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
69 70 else
70 71 export IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
71 72 fi
72 73
73 74 # Chroot directories
74 75 export R="${BUILDDIR}/chroot"
75 76 export ETC_DIR="${R}/etc"
76 77 export LIB_DIR="${R}/lib"
77 78 export BOOT_DIR="${R}/boot/firmware"
78 79 export KERNEL_DIR="${R}/usr/src/linux"
79 80 export WLAN_FIRMWARE_DIR="${R}/lib/firmware/brcm"
80 81
81 82 # General settings
82 83 export SET_ARCH=${SET_ARCH:=32}
83 84 export HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
84 85 export PASSWORD=${PASSWORD:=raspberry}
85 86 export USER_PASSWORD=${USER_PASSWORD:=raspberry}
86 87 export DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
87 88 export TIMEZONE=${TIMEZONE:="Europe/Berlin"}
88 89 export EXPANDROOT=${EXPANDROOT:=true}
89 90
90 91 # Keyboard settings
91 92 export XKB_MODEL=${XKB_MODEL:=""}
92 93 export XKB_LAYOUT=${XKB_LAYOUT:=""}
93 94 export XKB_VARIANT=${XKB_VARIANT:=""}
94 95 export XKB_OPTIONS=${XKB_OPTIONS:=""}
95 96
96 97 # Network settings (DHCP)
97 98 export ENABLE_DHCP=${ENABLE_DHCP:=true}
98 99
99 100 # Network settings (static)
100 101 export NET_ADDRESS=${NET_ADDRESS:=""}
101 102 export NET_GATEWAY=${NET_GATEWAY:=""}
102 103 export NET_DNS_1=${NET_DNS_1:=""}
103 104 export NET_DNS_2=${NET_DNS_2:=""}
104 105 export NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
105 106 export NET_NTP_1=${NET_NTP_1:=""}
106 107 export NET_NTP_2=${NET_NTP_2:=""}
107 108
108 109 # APT settings
109 110 export APT_PROXY=${APT_PROXY:=""}
110 111 export APT_SERVER=${APT_SERVER:="ftp.debian.org"}
111 112
112 113 # Feature settings
113 114 export ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
114 115 export ENABLE_I2C=${ENABLE_I2C:=false}
115 116 export ENABLE_SPI=${ENABLE_SPI:=false}
116 117 export ENABLE_IPV6=${ENABLE_IPV6:=true}
117 118 export ENABLE_SSHD=${ENABLE_SSHD:=true}
118 119 export ENABLE_NONFREE=${ENABLE_NONFREE:=false}
119 120 export ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
120 121 export ENABLE_SOUND=${ENABLE_SOUND:=true}
121 122 export ENABLE_DBUS=${ENABLE_DBUS:=true}
122 123 export ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
123 124 export ENABLE_MINGPU=${ENABLE_MINGPU:=false}
124 125 export ENABLE_XORG=${ENABLE_XORG:=false}
125 126 export ENABLE_WM=${ENABLE_WM:=""}
126 127 export ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
127 128 export ENABLE_USER=${ENABLE_USER:=true}
128 129 export USER_NAME=${USER_NAME:="pi"}
129 130 export ENABLE_ROOT=${ENABLE_ROOT:=false}
130 131 export ENABLE_QEMU=${ENABLE_QEMU:=false}
131 132
132 133 # SSH settings
133 134 export SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
134 135 export SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
135 136 export SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
136 137 export SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
137 138 export SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
138 139
139 140 # Advanced settings
140 141 export ENABLE_MINBASE=${ENABLE_MINBASE:=false}
141 142 export ENABLE_REDUCE=${ENABLE_REDUCE:=false}
142 143 export ENABLE_UBOOT=${ENABLE_UBOOT:=false}
143 144 export UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
144 145 export ENABLE_UBOOTUSB=${ENABLE_UBOOTUSB=false}
145 146 export ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
147 export ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=true}
148 export VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""}
146 149 export FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
147 150 export ENABLE_HARDNET=${ENABLE_HARDNET:=false}
148 151 export ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
149 152 export ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
150 153 export ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
151 154 export ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
152 155 export DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
153 156
154 157 # Kernel compilation settings
155 158 export BUILD_KERNEL=${BUILD_KERNEL:=true}
156 159 export KERNEL_REDUCE=${KERNEL_REDUCE:=false}
157 160 export KERNEL_THREADS=${KERNEL_THREADS:=1}
158 161 export KERNEL_HEADERS=${KERNEL_HEADERS:=true}
159 162 export KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
160 163 export KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
161 164 export KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
162 165 export KERNEL_CCACHE=${KERNEL_CCACHE:=false}
163 166
164 167 # Kernel compilation from source directory settings
165 168 export KERNELSRC_DIR=${KERNELSRC_DIR:=""}
166 169 export KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
167 170 export KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
168 171 export KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
169 172
170 173 # Reduce disk usage settings
171 174 export REDUCE_APT=${REDUCE_APT:=true}
172 175 export REDUCE_DOC=${REDUCE_DOC:=true}
173 176 export REDUCE_MAN=${REDUCE_MAN:=true}
174 177 export REDUCE_VIM=${REDUCE_VIM:=false}
175 178 export REDUCE_BASH=${REDUCE_BASH:=false}
176 179 export REDUCE_HWDB=${REDUCE_HWDB:=true}
177 180 export REDUCE_SSHD=${REDUCE_SSHD:=true}
178 181 export REDUCE_LOCALE=${REDUCE_LOCALE:=true}
179 182
180 183 # Encrypted filesystem settings
181 184 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
182 185 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
183 186 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
184 187 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
185 188 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
186 189
187 190 # Chroot scripts directory
188 191 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
189 192
190 193 # Packages required in the chroot build environment
191 194 export APT_INCLUDES=${APT_INCLUDES:=""}
192 195 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup"
193 196
194 197 # Packages required for bootstrapping
195 198 export REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo netselect-apt"
196 199 export MISSING_PACKAGES=""
197 200
198 201 # Packages installed for c/c++ build environment in chroot (keep empty)
199 202 export COMPILER_PACKAGES=""
200 203
201 204 #autconfigure best apt server to not spam ftp.debian.org
202 205 #rm files/apt/sources.list
203 206 #netselect-apt does not know buster yet
204 207 if [ "$RELEASE" = "buster" ] ; then
205 208 RLS=testing
206 209 else
207 210 RLS="$RELEASE"
208 211 fi
209 212
210 213 if [ -f "$(pwd)/files/apt/sources.list" ] ; then
211 214 rm "$(pwd)/files/apt/sources.list"
212 215 fi
213 216
214 217 if [ "$ENABLE_NONFREE" = true ] ; then
215 218 netselect-apt --arch "$RELEASE_ARCH" --tests 10 --sources --nonfree --outfile "$(pwd)/files/apt/sources.list" -d "$RLS"
216 219 else
217 220 netselect-apt --arch "$RELEASE_ARCH" --tests 10 --sources --outfile "$(pwd)/files/apt/sources.list" -d "$RLS"
218 221 fi
219 222 APT_SERVER=$(grep -m 1 http files/apt/sources.list | sed "s|http://| |g" | cut -d ' ' -f 3)
220 223 APT_SERVER=${APT_SERVER::-1}
221 224
222 225 #make script easier and more stable to use with convenient setup switch. Just setup SET_ARCH and RPI_MODEL and your good to go!
223 226 if [ -n "$SET_ARCH" ] ; then
224 227 echo "Setting Architecture specific settings"
225 228 ##################################
226 229 # 64 bit config
227 230 ##################################
228 231 if [ "$SET_ARCH" = 64 ] ; then
229 232 echo "64 bit mode selected - Setting up enviroment"
230 233 # 64 bit depended settings
231 234 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static}
232 235 KERNEL_ARCH=${KERNEL_ARCH:=arm64}
233 236 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
234 237
235 238 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
236 239 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
237 240 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig}
238 241 RELEASE_ARCH=${RELEASE_ARCH:=arm64}
239 242 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img}
240 243 CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-}
241 244 else
242 245 echo "error: At the moment Raspberry PI 3 and 3B+ are the only Models which support 64bit"
243 246 exit 1
244 247 fi
245 248 fi
246 249
247 250 ##################################
248 251 # 32 bit config
249 252 ##################################
250 253 if [ "$SET_ARCH" = 32 ] ; then
251 254 echo "32 bit mode selected - Setting up enviroment"
252 255 #General 32bit configuration
253 256 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
254 257 KERNEL_ARCH=${KERNEL_ARCH:=arm}
255 258 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
256 259
257 260 #Raspberry setting grouped by board compability
258 261 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then
259 262 echo "Setting settings for bcm2835 Raspberry PI boards"
260 263 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel"
261 264 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
262 265 RELEASE_ARCH=${RELEASE_ARCH:=armel}
263 266 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img}
264 267 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-}
265 268 fi
266 269 if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
267 270 echo "Setting settings for bcm2837 Raspberry PI boards"
268 271 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
269 272 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
270 273 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
271 274 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
272 275 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
273 276 fi
274 277 fi
275 278 #SET_ARCH not set
276 279 else
277 280 echo "error: Please set '32' or '64' as value for SET_ARCH"
278 281 exit 1
279 282 fi
280 283
281 284 #Device specific configuration
282 285 echo "Select DTB-File"
283 286 case "$RPI_MODEL" in
284 287 0)
285 288 DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
286 289 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
287 290 ;;
288 291 1)
289 292 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
290 293 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
291 294 ;;
292 295 1P)
293 296 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
294 297 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
295 298 ;;
296 299 2)
297 300 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
298 301 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
299 302 ;;
300 303 3)
301 304 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
302 305 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
303 306 ;;
304 307 3P)
305 308 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
306 309 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
307 310 ;;
308 311 *)
309 312 echo "error: Raspberry Pi model $RPI_MODEL is not supported!"
310 313 exit 1
311 314 ;;
312 315 esac
313 316 echo "$DTB_FILE selected"
314 317
315 318 #DEBUG off
316 319 set +x
317 320
318 321 # Check if the internal wireless interface is supported by the RPi model
319 322 if [ "$ENABLE_WIRELESS" = true ] ; then
320 323 if [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ] ; then
321 324 echo "error: The selected Raspberry Pi model has no internal wireless interface"
322 325 exit 1
323 326 else
324 327 echo "Raspberry Pi $RPI_MODEL has WIFI support"
325 328 fi
326 329 fi
327 330
328 331 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
329 332 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
330 333 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
331 334 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
332 335 exit 1
333 336 fi
334 337 fi
335 338
339 if [ "$ENABLE_VIDEOCORE" = true ] ; then
340 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake"
341 fi
342
336 343 # Add libncurses5 to enable kernel menuconfig
337 344 if [ "$KERNEL_MENUCONFIG" = true ] ; then
338 345 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
339 346 fi
340 347
341 348 # Add ccache compiler cache for (faster) kernel cross (re)compilation
342 349 if [ "$KERNEL_CCACHE" = true ] ; then
343 350 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
344 351 fi
345 352
346 353 # Add cryptsetup package to enable filesystem encryption
347 354 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
348 355 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
349 356 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
350 357
351 358 if [ -z "$CRYPTFS_PASSWORD" ] ; then
352 359 echo "error: no password defined (CRYPTFS_PASSWORD)!"
353 360 exit 1
354 361 fi
355 362 ENABLE_INITRAMFS=true
356 363 fi
357 364
358 365 # Add initramfs generation tools
359 366 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
360 367 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
361 368 fi
362 369
363 370 # Add device-tree-compiler required for building the U-Boot bootloader
364 371 if [ "$ENABLE_UBOOT" = true ] ; then
365 372 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc"
366 373 else
367 374 if [ "$ENABLE_UBOOTUSB" = true ] ; then
368 375 echo "error: Enabling UBOOTUSB requires u-boot to be enabled"
369 376 exit 1
370 377 fi
371 378 fi
372 379
373 380 # Check if root SSH (v2) public key file exists
374 381 if [ -n "$SSH_ROOT_PUB_KEY" ] ; then
375 382 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
376 383 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
377 384 exit 1
378 385 fi
379 386 fi
380 387
381 388 # Check if $USER_NAME SSH (v2) public key file exists
382 389 if [ -n "$SSH_USER_PUB_KEY" ] ; then
383 390 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
384 391 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
385 392 exit 1
386 393 fi
387 394 fi
388 395
389 396 # Check if all required packages are installed on the build system
390 397 for package in $REQUIRED_PACKAGES ; do
391 398 if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then
392 399 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
393 400 fi
394 401 done
395 402
396 403 # If there are missing packages ask confirmation for install, or exit
397 404 if [ -n "$MISSING_PACKAGES" ] ; then
398 405 echo "the following packages needed by this script are not installed:"
399 406 echo "$MISSING_PACKAGES"
400 407
401 408 printf "\ndo you want to install the missing packages right now? [y/n] "
402 409 read -r confirm
403 410 [ "$confirm" != "y" ] && exit 1
404 411
405 412 # Make sure all missing required packages are installed
406 413 apt-get -qq -y install "${MISSING_PACKAGES}"
407 414 fi
408 415
409 416 # Check if ./bootstrap.d directory exists
410 417 if [ ! -d "./bootstrap.d/" ] ; then
411 418 echo "error: './bootstrap.d' required directory not found!"
412 419 exit 1
413 420 fi
414 421
415 422 # Check if ./files directory exists
416 423 if [ ! -d "./files/" ] ; then
417 424 echo "error: './files' required directory not found!"
418 425 exit 1
419 426 fi
420 427
421 428 # Check if specified KERNELSRC_DIR directory exists
422 429 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
423 430 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
424 431 exit 1
425 432 fi
426 433
427 434 # Check if specified UBOOTSRC_DIR directory exists
428 435 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
429 436 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
430 437 exit 1
431 438 fi
432 439
440 # Check if specified VIDEOCORESRC_DIR directory exists
441 if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then
442 echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!"
443 exit 1
444 fi
445
433 446 # Check if specified FBTURBOSRC_DIR directory exists
434 447 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
435 448 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
436 449 exit 1
437 450 fi
438 451
439 452 # Check if specified CHROOT_SCRIPTS directory exists
440 453 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
441 454 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
442 455 exit 1
443 456 fi
444 457
445 458 # Check if specified device mapping already exists (will be used by cryptsetup)
446 459 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
447 460 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
448 461 exit 1
449 462 fi
450 463
451 464 # Don't clobber an old build
452 465 if [ -e "$BUILDDIR" ] ; then
453 466 echo "error: directory ${BUILDDIR} already exists, not proceeding"
454 467 exit 1
455 468 fi
456 469
457 470 # Setup chroot directory
458 471 mkdir -p "${R}"
459 472
460 473 # Check if build directory has enough of free disk space >512MB
461 474 if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then
462 475 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
463 476 exit 1
464 477 fi
465 478
466 479 # Call "cleanup" function on various signals and errors
467 480 trap cleanup 0 1 2 3 6
468 481
469 482 # Add required packages for the minbase installation
470 483 if [ "$ENABLE_MINBASE" = true ] ; then
471 484 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
472 485 fi
473 486
474 487 # Add parted package, required to get partprobe utility
475 488 if [ "$EXPANDROOT" = true ] ; then
476 489 APT_INCLUDES="${APT_INCLUDES},parted"
477 490 fi
478 491
479 492 # Add dbus package, recommended if using systemd
480 493 if [ "$ENABLE_DBUS" = true ] ; then
481 494 APT_INCLUDES="${APT_INCLUDES},dbus"
482 495 fi
483 496
484 497 # Add iptables IPv4/IPv6 package
485 498 if [ "$ENABLE_IPTABLES" = true ] ; then
486 499 APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent"
487 500 fi
488 501
489 502 # Add openssh server package
490 503 if [ "$ENABLE_SSHD" = true ] ; then
491 504 APT_INCLUDES="${APT_INCLUDES},openssh-server"
492 505 fi
493 506
494 507 # Add alsa-utils package
495 508 if [ "$ENABLE_SOUND" = true ] ; then
496 509 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
497 510 fi
498 511
499 512 # Add rng-tools package
500 513 if [ "$ENABLE_HWRANDOM" = true ] ; then
501 514 APT_INCLUDES="${APT_INCLUDES},rng-tools"
502 515 fi
503 516
504 517 # Add fbturbo video driver
505 518 if [ "$ENABLE_FBTURBO" = true ] ; then
506 519 # Enable xorg package dependencies
507 520 ENABLE_XORG=true
508 521 fi
509 522
510 523 # Add user defined window manager package
511 524 if [ -n "$ENABLE_WM" ] ; then
512 525 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
513 526
514 527 # Enable xorg package dependencies
515 528 ENABLE_XORG=true
516 529 fi
517 530
518 531 # Add xorg package
519 532 if [ "$ENABLE_XORG" = true ] ; then
520 533 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
521 534 fi
522 535
523 536 # Replace selected packages with smaller clones
524 537 if [ "$ENABLE_REDUCE" = true ] ; then
525 538 # Add levee package instead of vim-tiny
526 539 if [ "$REDUCE_VIM" = true ] ; then
527 540 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
528 541 fi
529 542
530 543 # Add dropbear package instead of openssh-server
531 544 if [ "$REDUCE_SSHD" = true ] ; then
532 545 APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")"
533 546 fi
534 547 fi
535 548
536 549 # Configure kernel sources if no KERNELSRC_DIR
537 550 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
538 551 KERNELSRC_CONFIG=true
539 552 fi
540 553
541 554 # Configure reduced kernel
542 555 if [ "$KERNEL_REDUCE" = true ] ; then
543 556 KERNELSRC_CONFIG=false
544 557 fi
545 558
546 559 set -x
547 560
548 561 # Execute bootstrap scripts
549 562 for SCRIPT in bootstrap.d/*.sh; do
550 563 head -n 4 "$SCRIPT"
551 564 . "$SCRIPT"
552 565 done
553 566
554 567 ## Execute custom bootstrap scripts
555 568 if [ -d "custom.d" ] ; then
556 569 for SCRIPT in custom.d/*.sh; do
557 570 . "$SCRIPT"
558 571 done
559 572 fi
560 573
561 574 # Execute custom scripts inside the chroot
562 575 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
563 576 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
564 577 chroot_exec /bin/bash -x <<'EOF'
565 578 for SCRIPT in /chroot_scripts/* ; do
566 579 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
567 580 $SCRIPT
568 581 fi
569 582 done
570 583 EOF
571 584 rm -rf "${R}/chroot_scripts"
572 585 fi
573 586
574 587 # Remove c/c++ build environment from the chroot
575 588 chroot_remove_cc
576 589
577 590 # Generate required machine-id
578 591 MACHINE_ID=$(dbus-uuidgen)
579 592 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
580 593 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
581 594
582 595 # APT Cleanup
583 596 chroot_exec apt-get -y clean
584 597 chroot_exec apt-get -y autoclean
585 598 chroot_exec apt-get -y autoremove
586 599
587 600 # Unmount mounted filesystems
588 601 umount -l "${R}/proc"
589 602 umount -l "${R}/sys"
590 603
591 604 # Clean up directories
592 605 rm -rf "${R}/run/*"
593 606 rm -rf "${R}/tmp/*"
594 607
595 608 # Clean up files
596 609 rm -f "${ETC_DIR}/ssh/ssh_host_*"
597 610 rm -f "${ETC_DIR}/dropbear/dropbear_*"
598 611 rm -f "${ETC_DIR}/apt/sources.list.save"
599 612 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
600 613 rm -f "${ETC_DIR}/*-"
601 614 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
602 615 rm -f "${ETC_DIR}/resolv.conf"
603 616 rm -f "${R}/root/.bash_history"
604 617 rm -f "${R}/var/lib/urandom/random-seed"
605 618 rm -f "${R}/initrd.img"
606 619 rm -f "${R}/vmlinuz"
607 620 rm -f "${R}${QEMU_BINARY}"
608 621
609 622 if [ "$ENABLE_QEMU" = true ] ; then
610 623 # Configure qemu compatible kernel
611 624 DTB_FILE=vexpress-v2p-ca15_a7.dtb
612 625 UBOOT_CONFIG=vexpress_ca15_tc2_defconfig
613 626 KERNEL_DEFCONFIG="vexpress_defconfig"
614 627 if [ "$KERNEL_MENUCONFIG" = false ] ; then
615 628 KERNEL_OLDDEFCONFIG=true
616 629 fi
617 630
618 631 # Setup QEMU directory
619 632 mkdir "${BASEDIR}/qemu"
620 633
621 634 # Copy kernel image to QEMU directory
622 635 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
623 636
624 637 # Copy kernel config to QEMU directory
625 638 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
626 639
627 640 # Copy kernel dtbs to QEMU directory
628 641 for dtb in "${BOOT_DIR}/"*.dtb ; do
629 642 if [ -f "${dtb}" ] ; then
630 643 install_readonly "${dtb}" "${BASEDIR}/qemu/"
631 644 fi
632 645 done
633 646
634 647 # Copy kernel overlays to QEMU directory
635 648 if [ -d "${BOOT_DIR}/overlays" ] ; then
636 649 # Setup overlays dtbs directory
637 650 mkdir "${BASEDIR}/qemu/overlays"
638 651
639 652 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
640 653 if [ -f "${dtb}" ] ; then
641 654 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
642 655 fi
643 656 done
644 657 fi
645 658
646 659 # Copy u-boot files to QEMU directory
647 660 if [ "$ENABLE_UBOOT" = true ] ; then
648 661 if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then
649 662 install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin"
650 663 fi
651 664 if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then
652 665 install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage"
653 666 fi
654 667 if [ -f "${BOOT_DIR}/boot.scr" ] ; then
655 668 install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr"
656 669 fi
657 670 fi
658 671
659 672 # Copy initramfs to QEMU directory
660 673 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
661 674 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
662 675 fi
663 676 fi
664 677
665 678 # Calculate size of the chroot directory in KB
666 679 CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')")
667 680
668 681 # Calculate the amount of needed 512 Byte sectors
669 682 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
670 683 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
671 684 ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}")
672 685
673 686 # The root partition is EXT4
674 687 # This means more space than the actual used space of the chroot is used.
675 688 # As overhead for journaling and reserved blocks 35% are added.
676 689 ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512)
677 690
678 691 # Calculate required image size in 512 Byte sectors
679 692 IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}")
680 693
681 694 # Prepare image file
682 695 if [ "$ENABLE_SPLITFS" = true ] ; then
683 696 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}"
684 697 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}"
685 698 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}"
686 699 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}"
687 700
688 701 # Write firmware/boot partition tables
689 702 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
690 703 "${TABLE_SECTORS}","${FRMW_SECTORS}",c,*
691 704 EOM
692 705
693 706 # Write root partition table
694 707 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
695 708 "${TABLE_SECTORS}","${ROOT_SECTORS}",83
696 709 EOM
697 710
698 711 # Setup temporary loop devices
699 712 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)"
700 713 ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)"
701 714 else # ENABLE_SPLITFS=false
702 715 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}"
703 716 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}"
704 717
705 718 # Write partition table
706 719 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
707 720 "${TABLE_SECTORS}","${FRMW_SECTORS}",c,*
708 721 "${ROOT_OFFSET}","${ROOT_SECTORS}",83
709 722 EOM
710 723
711 724 # Setup temporary loop devices
712 725 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)"
713 726 ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)"
714 727 fi
715 728
716 729 if [ "$ENABLE_CRYPTFS" = true ] ; then
717 730 # Create dummy ext4 fs
718 731 mkfs.ext4 "$ROOT_LOOP"
719 732
720 733 # Setup password keyfile
721 734 touch .password
722 735 chmod 600 .password
723 736 echo -n "${CRYPTFS_PASSWORD}" > .password
724 737
725 738 # Initialize encrypted partition
726 739 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
727 740
728 741 # Open encrypted partition and setup mapping
729 742 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
730 743
731 744 # Secure delete password keyfile
732 745 shred -zu .password
733 746
734 747 # Update temporary loop device
735 748 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
736 749
737 750 # Wipe encrypted partition (encryption cipher is used for randomness)
738 751 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")"
739 752 fi
740 753
741 754 # Build filesystems
742 755 mkfs.vfat "$FRMW_LOOP"
743 756 mkfs.ext4 "$ROOT_LOOP"
744 757
745 758 # Mount the temporary loop devices
746 759 mkdir -p "$BUILDDIR/mount"
747 760 mount "$ROOT_LOOP" "$BUILDDIR/mount"
748 761
749 762 mkdir -p "$BUILDDIR/mount/boot/firmware"
750 763 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
751 764
752 765 # Copy all files from the chroot to the loop device mount point directory
753 766 rsync -a "${R}/" "$BUILDDIR/mount/"
754 767
755 768 # Unmount all temporary loop devices and mount points
756 769 cleanup
757 770
758 771 # Create block map file(s) of image(s)
759 772 if [ "$ENABLE_SPLITFS" = true ] ; then
760 773 # Create block map files for "bmaptool"
761 774 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
762 775 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
763 776
764 777 # Image was successfully created
765 778 echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
766 779 echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
767 780 else
768 781 # Create block map file for "bmaptool"
769 782 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
770 783
771 784 # Image was successfully created
772 785 echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
773 786
774 787 # Create qemu qcow2 image
775 788 if [ "$ENABLE_QEMU" = true ] ; then
776 789 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
777 790 QEMU_SIZE=16G
778 791
779 792 qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2
780 793 qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE
781 794
782 795 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
783 796 fi
784 797 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant