@@ -1,498 +1,498 | |||||
1 | # |
|
1 | # | |
2 | # Build and Setup RPi2/3 Kernel |
|
2 | # Build and Setup RPi2/3 Kernel | |
3 | # |
|
3 | # | |
4 |
|
4 | |||
5 | # Load utility functions |
|
5 | # Load utility functions | |
6 | . ./functions.sh |
|
6 | . ./functions.sh | |
7 |
|
7 | |||
|
8 | # Use kali kernel src if nexmon is enabled | |||
|
9 | if [ "$ENABLE_NEXMON" = true ] ; then | |||
|
10 | KERNEL_URL="${NEXMON_URL}" | |||
|
11 | fi | |||
|
12 | ||||
8 | # Fetch and build latest raspberry kernel |
|
13 | # Fetch and build latest raspberry kernel | |
9 | if [ "$BUILD_KERNEL" = true ] ; then |
|
14 | if [ "$BUILD_KERNEL" = true ] ; then | |
10 | # Setup source directory |
|
15 | # Setup source directory | |
11 | mkdir -p "${KERNEL_DIR}" |
|
16 | mkdir -p "${KERNEL_DIR}" | |
12 |
|
17 | |||
13 | # Copy existing kernel sources into chroot directory |
|
18 | # Copy existing kernel sources into chroot directory | |
14 | if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then |
|
19 | if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then | |
15 | # Copy kernel sources and include hidden files |
|
20 | # Copy kernel sources and include hidden files | |
16 | cp -r "${KERNELSRC_DIR}/". "${KERNEL_DIR}" |
|
21 | cp -r "${KERNELSRC_DIR}/". "${KERNEL_DIR}" | |
17 |
|
22 | |||
18 | # Clean the kernel sources |
|
23 | # Clean the kernel sources | |
19 | if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then |
|
24 | if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then | |
20 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper |
|
25 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper | |
21 | fi |
|
26 | fi | |
22 | else # KERNELSRC_DIR="" |
|
27 | else # KERNELSRC_DIR="" | |
23 | # Create temporary directory for kernel sources |
|
28 | # Create temporary directory for kernel sources | |
24 | temp_dir=$(as_nobody mktemp -d) |
|
29 | temp_dir=$(as_nobody mktemp -d) | |
25 |
|
30 | |||
26 | # Use kali kernel src if nexmon is enabled |
|
|||
27 | if [ "$ENABLE_NEXMON" = true ] ; then |
|
|||
28 | KERNEL_URL="${NEXMON_URL}" |
|
|||
29 | fi |
|
|||
30 |
|
||||
31 | # Fetch current RPi2/3 kernel sources |
|
31 | # Fetch current RPi2/3 kernel sources | |
32 | if [ -z "${KERNEL_BRANCH}" ] ; then |
|
32 | if [ -z "${KERNEL_BRANCH}" ] ; then | |
33 | as_nobody -H git -C "${temp_dir}" clone --depth=1 "${KERNEL_URL}" linux |
|
33 | as_nobody -H git -C "${temp_dir}" clone --depth=1 "${KERNEL_URL}" linux | |
34 | else |
|
34 | else | |
35 | as_nobody -H git -C "${temp_dir}" clone --depth=1 --branch "${KERNEL_BRANCH}" "${KERNEL_URL}" linux |
|
35 | as_nobody -H git -C "${temp_dir}" clone --depth=1 --branch "${KERNEL_BRANCH}" "${KERNEL_URL}" linux | |
36 | fi |
|
36 | fi | |
37 |
|
37 | |||
38 | # Copy downloaded kernel sources |
|
38 | # Copy downloaded kernel sources | |
39 | cp -r "${temp_dir}/linux/"* "${KERNEL_DIR}" |
|
39 | cp -r "${temp_dir}/linux/"* "${KERNEL_DIR}" | |
40 |
|
40 | |||
41 | # Remove temporary directory for kernel sources |
|
41 | # Remove temporary directory for kernel sources | |
42 | rm -fr "${temp_dir}" |
|
42 | rm -fr "${temp_dir}" | |
43 |
|
43 | |||
44 | # Set permissions of the kernel sources |
|
44 | # Set permissions of the kernel sources | |
45 | chown -R root:root "${R}/usr/src" |
|
45 | chown -R root:root "${R}/usr/src" | |
46 | fi |
|
46 | fi | |
47 |
|
47 | |||
48 | # Calculate optimal number of kernel building threads |
|
48 | # Calculate optimal number of kernel building threads | |
49 | if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then |
|
49 | if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then | |
50 | KERNEL_THREADS=$(grep -c processor /proc/cpuinfo) |
|
50 | KERNEL_THREADS=$(grep -c processor /proc/cpuinfo) | |
51 | fi |
|
51 | fi | |
52 |
|
52 | |||
53 | # Configure and build kernel |
|
53 | # Configure and build kernel | |
54 | if [ "$KERNELSRC_PREBUILT" = false ] ; then |
|
54 | if [ "$KERNELSRC_PREBUILT" = false ] ; then | |
55 | # Remove device, network and filesystem drivers from kernel configuration |
|
55 | # Remove device, network and filesystem drivers from kernel configuration | |
56 | if [ "$KERNEL_REDUCE" = true ] ; then |
|
56 | if [ "$KERNEL_REDUCE" = true ] ; then | |
57 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" |
|
57 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" | |
58 | sed -i\ |
|
58 | sed -i\ | |
59 | -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\ |
|
59 | -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\ | |
60 | -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\ |
|
60 | -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\ | |
61 | -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\ |
|
61 | -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\ | |
62 | -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\ |
|
62 | -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\ | |
63 | -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\ |
|
63 | -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\ | |
64 | -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\ |
|
64 | -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\ | |
65 | -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\ |
|
65 | -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\ | |
66 | -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\ |
|
66 | -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\ | |
67 | -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\ |
|
67 | -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\ | |
68 | -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\ |
|
68 | -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\ | |
69 | -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\ |
|
69 | -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\ | |
70 | -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\ |
|
70 | -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\ | |
71 | -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\ |
|
71 | -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\ | |
72 | -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\ |
|
72 | -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\ | |
73 | -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\ |
|
73 | -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\ | |
74 | -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\ |
|
74 | -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\ | |
75 | -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\ |
|
75 | -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\ | |
76 | -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\ |
|
76 | -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\ | |
77 | -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\ |
|
77 | -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\ | |
78 | -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\ |
|
78 | -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\ | |
79 | -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\ |
|
79 | -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\ | |
80 | -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\ |
|
80 | -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\ | |
81 | -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\ |
|
81 | -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\ | |
82 | -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\ |
|
82 | -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\ | |
83 | -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\ |
|
83 | -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\ | |
84 | -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\ |
|
84 | -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\ | |
85 | -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\ |
|
85 | -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\ | |
86 | -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\ |
|
86 | -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\ | |
87 | -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\ |
|
87 | -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\ | |
88 | "${KERNEL_DIR}/.config" |
|
88 | "${KERNEL_DIR}/.config" | |
89 | fi |
|
89 | fi | |
90 |
|
90 | |||
91 | if [ "$KERNELSRC_CONFIG" = true ] ; then |
|
91 | if [ "$KERNELSRC_CONFIG" = true ] ; then | |
92 | # Load default raspberry kernel configuration |
|
92 | # Load default raspberry kernel configuration | |
93 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" |
|
93 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" | |
94 |
|
94 | |||
95 | #Switch to KERNELSRC_DIR so we can use set_kernel_config |
|
95 | #Switch to KERNELSRC_DIR so we can use set_kernel_config | |
96 | cd "${KERNEL_DIR}" || exit |
|
96 | cd "${KERNEL_DIR}" || exit | |
97 |
|
97 | |||
98 | # enable ZSWAP see https://askubuntu.com/a/472227 or https://wiki.archlinux.org/index.php/zswap |
|
98 | # enable ZSWAP see https://askubuntu.com/a/472227 or https://wiki.archlinux.org/index.php/zswap | |
99 | if [ "$KERNEL_ZSWAP" = true ] ; then |
|
99 | if [ "$KERNEL_ZSWAP" = true ] ; then | |
100 | set_kernel_config CONFIG_ZPOOL y |
|
100 | set_kernel_config CONFIG_ZPOOL y | |
101 | set_kernel_config CONFIG_ZSWAP y |
|
101 | set_kernel_config CONFIG_ZSWAP y | |
102 | set_kernel_config CONFIG_ZBUD y |
|
102 | set_kernel_config CONFIG_ZBUD y | |
103 | set_kernel_config CONFIG_Z3FOLD y |
|
103 | set_kernel_config CONFIG_Z3FOLD y | |
104 | set_kernel_config CONFIG_ZSMALLOC y |
|
104 | set_kernel_config CONFIG_ZSMALLOC y | |
105 | set_kernel_config CONFIG_PGTABLE_MAPPING y |
|
105 | set_kernel_config CONFIG_PGTABLE_MAPPING y | |
106 | fi |
|
106 | fi | |
107 |
|
107 | |||
108 | # enable basic KVM support; see https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=210546&start=25#p1300453 |
|
108 | # enable basic KVM support; see https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=210546&start=25#p1300453 | |
109 | if [ "$KERNEL_VIRT" = true ] && { [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then |
|
109 | if [ "$KERNEL_VIRT" = true ] && { [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then | |
110 | set_kernel_config CONFIG_VIRTUALIZATION y |
|
110 | set_kernel_config CONFIG_VIRTUALIZATION y | |
111 | set_kernel_config CONFIG_KVM y |
|
111 | set_kernel_config CONFIG_KVM y | |
112 | set_kernel_config CONFIG_VHOST_NET m |
|
112 | set_kernel_config CONFIG_VHOST_NET m | |
113 | set_kernel_config CONFIG_VHOST_CROSS_ENDIAN_LEGACY y |
|
113 | set_kernel_config CONFIG_VHOST_CROSS_ENDIAN_LEGACY y | |
114 | fi |
|
114 | fi | |
115 |
|
115 | |||
116 | # Netfilter kernel support See https://github.com/raspberrypi/linux/issues/2177#issuecomment-354647406 |
|
116 | # Netfilter kernel support See https://github.com/raspberrypi/linux/issues/2177#issuecomment-354647406 | |
117 | if [ "$KERNEL_NF" = true ] ; then |
|
117 | if [ "$KERNEL_NF" = true ] ; then | |
118 | set_kernel_config CONFIG_IP_NF_TARGET_SYNPROXY m |
|
118 | set_kernel_config CONFIG_IP_NF_TARGET_SYNPROXY m | |
119 | set_kernel_config CONFIG_NETFILTER_XT_MATCH_CGROUP m |
|
119 | set_kernel_config CONFIG_NETFILTER_XT_MATCH_CGROUP m | |
120 | set_kernel_config CONFIG_NETFILTER_XT_MATCH_IPCOMP m |
|
120 | set_kernel_config CONFIG_NETFILTER_XT_MATCH_IPCOMP m | |
121 | set_kernel_config CONFIG_NETFILTER_XT_MATCH_SOCKET m |
|
121 | set_kernel_config CONFIG_NETFILTER_XT_MATCH_SOCKET m | |
122 | set_kernel_config CONFIG_NFT_FIB_INET m |
|
122 | set_kernel_config CONFIG_NFT_FIB_INET m | |
123 | set_kernel_config CONFIG_NFT_FIB_IPV4 m |
|
123 | set_kernel_config CONFIG_NFT_FIB_IPV4 m | |
124 | set_kernel_config CONFIG_NFT_FIB_IPV6 m |
|
124 | set_kernel_config CONFIG_NFT_FIB_IPV6 m | |
125 | set_kernel_config CONFIG_NFT_FIB_NETDEV m |
|
125 | set_kernel_config CONFIG_NFT_FIB_NETDEV m | |
126 | set_kernel_config CONFIG_NFT_OBJREF m |
|
126 | set_kernel_config CONFIG_NFT_OBJREF m | |
127 | set_kernel_config CONFIG_NFT_RT m |
|
127 | set_kernel_config CONFIG_NFT_RT m | |
128 | set_kernel_config CONFIG_NFT_SET_BITMAP m |
|
128 | set_kernel_config CONFIG_NFT_SET_BITMAP m | |
129 | set_kernel_config CONFIG_NF_CONNTRACK_TIMEOUT y |
|
129 | set_kernel_config CONFIG_NF_CONNTRACK_TIMEOUT y | |
130 | set_kernel_config CONFIG_NF_LOG_ARP m |
|
130 | set_kernel_config CONFIG_NF_LOG_ARP m | |
131 | set_kernel_config CONFIG_NF_SOCKET_IPV4 m |
|
131 | set_kernel_config CONFIG_NF_SOCKET_IPV4 m | |
132 | set_kernel_config CONFIG_NF_SOCKET_IPV6 m |
|
132 | set_kernel_config CONFIG_NF_SOCKET_IPV6 m | |
133 | set_kernel_config CONFIG_BRIDGE_EBT_BROUTE m |
|
133 | set_kernel_config CONFIG_BRIDGE_EBT_BROUTE m | |
134 | set_kernel_config CONFIG_BRIDGE_EBT_T_FILTER m |
|
134 | set_kernel_config CONFIG_BRIDGE_EBT_T_FILTER m | |
135 | set_kernel_config CONFIG_BRIDGE_NF_EBTABLES m |
|
135 | set_kernel_config CONFIG_BRIDGE_NF_EBTABLES m | |
136 | set_kernel_config CONFIG_IP6_NF_IPTABLES m |
|
136 | set_kernel_config CONFIG_IP6_NF_IPTABLES m | |
137 | set_kernel_config CONFIG_IP6_NF_MATCH_AH m |
|
137 | set_kernel_config CONFIG_IP6_NF_MATCH_AH m | |
138 | set_kernel_config CONFIG_IP6_NF_MATCH_EUI64 m |
|
138 | set_kernel_config CONFIG_IP6_NF_MATCH_EUI64 m | |
139 | set_kernel_config CONFIG_IP6_NF_NAT m |
|
139 | set_kernel_config CONFIG_IP6_NF_NAT m | |
140 | set_kernel_config CONFIG_IP6_NF_TARGET_MASQUERADE m |
|
140 | set_kernel_config CONFIG_IP6_NF_TARGET_MASQUERADE m | |
141 | set_kernel_config CONFIG_IP6_NF_TARGET_NPT m |
|
141 | set_kernel_config CONFIG_IP6_NF_TARGET_NPT m | |
142 | set_kernel_config CONFIG_IP_SET_BITMAP_IPMAC m |
|
142 | set_kernel_config CONFIG_IP_SET_BITMAP_IPMAC m | |
143 | set_kernel_config CONFIG_IP_SET_BITMAP_PORT m |
|
143 | set_kernel_config CONFIG_IP_SET_BITMAP_PORT m | |
144 | set_kernel_config CONFIG_IP_SET_HASH_IP m |
|
144 | set_kernel_config CONFIG_IP_SET_HASH_IP m | |
145 | set_kernel_config CONFIG_IP_SET_HASH_IPMARK m |
|
145 | set_kernel_config CONFIG_IP_SET_HASH_IPMARK m | |
146 | set_kernel_config CONFIG_IP_SET_HASH_IPPORT m |
|
146 | set_kernel_config CONFIG_IP_SET_HASH_IPPORT m | |
147 | set_kernel_config CONFIG_IP_SET_HASH_IPPORTIP m |
|
147 | set_kernel_config CONFIG_IP_SET_HASH_IPPORTIP m | |
148 | set_kernel_config CONFIG_IP_SET_HASH_IPPORTNET m |
|
148 | set_kernel_config CONFIG_IP_SET_HASH_IPPORTNET m | |
149 | set_kernel_config CONFIG_IP_SET_HASH_MAC m |
|
149 | set_kernel_config CONFIG_IP_SET_HASH_MAC m | |
150 | set_kernel_config CONFIG_IP_SET_HASH_NET m |
|
150 | set_kernel_config CONFIG_IP_SET_HASH_NET m | |
151 | set_kernel_config CONFIG_IP_SET_HASH_NETIFACE m |
|
151 | set_kernel_config CONFIG_IP_SET_HASH_NETIFACE m | |
152 | set_kernel_config CONFIG_IP_SET_HASH_NETNET m |
|
152 | set_kernel_config CONFIG_IP_SET_HASH_NETNET m | |
153 | set_kernel_config CONFIG_IP_SET_HASH_NETPORT m |
|
153 | set_kernel_config CONFIG_IP_SET_HASH_NETPORT m | |
154 | set_kernel_config CONFIG_IP_SET_HASH_NETPORTNET m |
|
154 | set_kernel_config CONFIG_IP_SET_HASH_NETPORTNET m | |
155 | set_kernel_config CONFIG_IP_SET_LIST_SET m |
|
155 | set_kernel_config CONFIG_IP_SET_LIST_SET m | |
156 | set_kernel_config CONFIG_NETFILTER_XTABLES m |
|
156 | set_kernel_config CONFIG_NETFILTER_XTABLES m | |
157 | set_kernel_config CONFIG_NETFILTER_XTABLES m |
|
157 | set_kernel_config CONFIG_NETFILTER_XTABLES m | |
158 | set_kernel_config CONFIG_NFT_BRIDGE_META m |
|
158 | set_kernel_config CONFIG_NFT_BRIDGE_META m | |
159 | set_kernel_config CONFIG_NFT_BRIDGE_REJECT m |
|
159 | set_kernel_config CONFIG_NFT_BRIDGE_REJECT m | |
160 | set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV4 m |
|
160 | set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV4 m | |
161 | set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV6 m |
|
161 | set_kernel_config CONFIG_NFT_CHAIN_NAT_IPV6 m | |
162 | set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV4 m |
|
162 | set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV4 m | |
163 | set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV6 m |
|
163 | set_kernel_config CONFIG_NFT_CHAIN_ROUTE_IPV6 m | |
164 | set_kernel_config CONFIG_NFT_COMPAT m |
|
164 | set_kernel_config CONFIG_NFT_COMPAT m | |
165 | set_kernel_config CONFIG_NFT_COUNTER m |
|
165 | set_kernel_config CONFIG_NFT_COUNTER m | |
166 | set_kernel_config CONFIG_NFT_CT m |
|
166 | set_kernel_config CONFIG_NFT_CT m | |
167 | set_kernel_config CONFIG_NFT_DUP_IPV4 m |
|
167 | set_kernel_config CONFIG_NFT_DUP_IPV4 m | |
168 | set_kernel_config CONFIG_NFT_DUP_IPV6 m |
|
168 | set_kernel_config CONFIG_NFT_DUP_IPV6 m | |
169 | set_kernel_config CONFIG_NFT_DUP_NETDEV m |
|
169 | set_kernel_config CONFIG_NFT_DUP_NETDEV m | |
170 | set_kernel_config CONFIG_NFT_EXTHDR m |
|
170 | set_kernel_config CONFIG_NFT_EXTHDR m | |
171 | set_kernel_config CONFIG_NFT_FWD_NETDEV m |
|
171 | set_kernel_config CONFIG_NFT_FWD_NETDEV m | |
172 | set_kernel_config CONFIG_NFT_HASH m |
|
172 | set_kernel_config CONFIG_NFT_HASH m | |
173 | set_kernel_config CONFIG_NFT_LIMIT m |
|
173 | set_kernel_config CONFIG_NFT_LIMIT m | |
174 | set_kernel_config CONFIG_NFT_LOG m |
|
174 | set_kernel_config CONFIG_NFT_LOG m | |
175 | set_kernel_config CONFIG_NFT_MASQ m |
|
175 | set_kernel_config CONFIG_NFT_MASQ m | |
176 | set_kernel_config CONFIG_NFT_MASQ_IPV4 m |
|
176 | set_kernel_config CONFIG_NFT_MASQ_IPV4 m | |
177 | set_kernel_config CONFIG_NFT_MASQ_IPV6 m |
|
177 | set_kernel_config CONFIG_NFT_MASQ_IPV6 m | |
178 | set_kernel_config CONFIG_NFT_META m |
|
178 | set_kernel_config CONFIG_NFT_META m | |
179 | set_kernel_config CONFIG_NFT_NAT m |
|
179 | set_kernel_config CONFIG_NFT_NAT m | |
180 | set_kernel_config CONFIG_NFT_NUMGEN m |
|
180 | set_kernel_config CONFIG_NFT_NUMGEN m | |
181 | set_kernel_config CONFIG_NFT_QUEUE m |
|
181 | set_kernel_config CONFIG_NFT_QUEUE m | |
182 | set_kernel_config CONFIG_NFT_QUOTA m |
|
182 | set_kernel_config CONFIG_NFT_QUOTA m | |
183 | set_kernel_config CONFIG_NFT_REDIR m |
|
183 | set_kernel_config CONFIG_NFT_REDIR m | |
184 | set_kernel_config CONFIG_NFT_REDIR_IPV4 m |
|
184 | set_kernel_config CONFIG_NFT_REDIR_IPV4 m | |
185 | set_kernel_config CONFIG_NFT_REDIR_IPV6 m |
|
185 | set_kernel_config CONFIG_NFT_REDIR_IPV6 m | |
186 | set_kernel_config CONFIG_NFT_REJECT m |
|
186 | set_kernel_config CONFIG_NFT_REJECT m | |
187 | set_kernel_config CONFIG_NFT_REJECT_INET m |
|
187 | set_kernel_config CONFIG_NFT_REJECT_INET m | |
188 | set_kernel_config CONFIG_NFT_REJECT_IPV4 m |
|
188 | set_kernel_config CONFIG_NFT_REJECT_IPV4 m | |
189 | set_kernel_config CONFIG_NFT_REJECT_IPV6 m |
|
189 | set_kernel_config CONFIG_NFT_REJECT_IPV6 m | |
190 | set_kernel_config CONFIG_NFT_SET_HASH m |
|
190 | set_kernel_config CONFIG_NFT_SET_HASH m | |
191 | set_kernel_config CONFIG_NFT_SET_RBTREE m |
|
191 | set_kernel_config CONFIG_NFT_SET_RBTREE m | |
192 | set_kernel_config CONFIG_NF_CONNTRACK_IPV4 m |
|
192 | set_kernel_config CONFIG_NF_CONNTRACK_IPV4 m | |
193 | set_kernel_config CONFIG_NF_CONNTRACK_IPV6 m |
|
193 | set_kernel_config CONFIG_NF_CONNTRACK_IPV6 m | |
194 | set_kernel_config CONFIG_NF_DEFRAG_IPV4 m |
|
194 | set_kernel_config CONFIG_NF_DEFRAG_IPV4 m | |
195 | set_kernel_config CONFIG_NF_DEFRAG_IPV6 m |
|
195 | set_kernel_config CONFIG_NF_DEFRAG_IPV6 m | |
196 | set_kernel_config CONFIG_NF_DUP_IPV4 m |
|
196 | set_kernel_config CONFIG_NF_DUP_IPV4 m | |
197 | set_kernel_config CONFIG_NF_DUP_IPV6 m |
|
197 | set_kernel_config CONFIG_NF_DUP_IPV6 m | |
198 | set_kernel_config CONFIG_NF_DUP_NETDEV m |
|
198 | set_kernel_config CONFIG_NF_DUP_NETDEV m | |
199 | set_kernel_config CONFIG_NF_LOG_BRIDGE m |
|
199 | set_kernel_config CONFIG_NF_LOG_BRIDGE m | |
200 | set_kernel_config CONFIG_NF_LOG_IPV4 m |
|
200 | set_kernel_config CONFIG_NF_LOG_IPV4 m | |
201 | set_kernel_config CONFIG_NF_LOG_IPV6 m |
|
201 | set_kernel_config CONFIG_NF_LOG_IPV6 m | |
202 | set_kernel_config CONFIG_NF_NAT_IPV4 m |
|
202 | set_kernel_config CONFIG_NF_NAT_IPV4 m | |
203 | set_kernel_config CONFIG_NF_NAT_IPV6 m |
|
203 | set_kernel_config CONFIG_NF_NAT_IPV6 m | |
204 | set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV4 m |
|
204 | set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV4 m | |
205 | set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV6 m |
|
205 | set_kernel_config CONFIG_NF_NAT_MASQUERADE_IPV6 m | |
206 | set_kernel_config CONFIG_NF_NAT_PPTP m |
|
206 | set_kernel_config CONFIG_NF_NAT_PPTP m | |
207 | set_kernel_config CONFIG_NF_NAT_PROTO_GRE m |
|
207 | set_kernel_config CONFIG_NF_NAT_PROTO_GRE m | |
208 | set_kernel_config CONFIG_NF_NAT_REDIRECT m |
|
208 | set_kernel_config CONFIG_NF_NAT_REDIRECT m | |
209 | set_kernel_config CONFIG_NF_NAT_SIP m |
|
209 | set_kernel_config CONFIG_NF_NAT_SIP m | |
210 | set_kernel_config CONFIG_NF_NAT_SNMP_BASIC m |
|
210 | set_kernel_config CONFIG_NF_NAT_SNMP_BASIC m | |
211 | set_kernel_config CONFIG_NF_NAT_TFTP m |
|
211 | set_kernel_config CONFIG_NF_NAT_TFTP m | |
212 | set_kernel_config CONFIG_NF_REJECT_IPV4 m |
|
212 | set_kernel_config CONFIG_NF_REJECT_IPV4 m | |
213 | set_kernel_config CONFIG_NF_REJECT_IPV6 m |
|
213 | set_kernel_config CONFIG_NF_REJECT_IPV6 m | |
214 | set_kernel_config CONFIG_NF_TABLES m |
|
214 | set_kernel_config CONFIG_NF_TABLES m | |
215 | set_kernel_config CONFIG_NF_TABLES_ARP m |
|
215 | set_kernel_config CONFIG_NF_TABLES_ARP m | |
216 | set_kernel_config CONFIG_NF_TABLES_BRIDGE m |
|
216 | set_kernel_config CONFIG_NF_TABLES_BRIDGE m | |
217 | set_kernel_config CONFIG_NF_TABLES_INET m |
|
217 | set_kernel_config CONFIG_NF_TABLES_INET m | |
218 | set_kernel_config CONFIG_NF_TABLES_IPV4 m |
|
218 | set_kernel_config CONFIG_NF_TABLES_IPV4 m | |
219 | set_kernel_config CONFIG_NF_TABLES_IPV6 m |
|
219 | set_kernel_config CONFIG_NF_TABLES_IPV6 m | |
220 | set_kernel_config CONFIG_NF_TABLES_NETDEV m |
|
220 | set_kernel_config CONFIG_NF_TABLES_NETDEV m | |
221 | fi |
|
221 | fi | |
222 |
|
222 | |||
223 | # Enables BPF syscall for systemd-journald see https://github.com/torvalds/linux/blob/master/init/Kconfig#L848 or https://groups.google.com/forum/#!topic/linux.gentoo.user/_2aSc_ztGpA |
|
223 | # Enables BPF syscall for systemd-journald see https://github.com/torvalds/linux/blob/master/init/Kconfig#L848 or https://groups.google.com/forum/#!topic/linux.gentoo.user/_2aSc_ztGpA | |
224 | if [ "$KERNEL_BPF" = true ] ; then |
|
224 | if [ "$KERNEL_BPF" = true ] ; then | |
225 | set_kernel_config CONFIG_BPF_SYSCALL y |
|
225 | set_kernel_config CONFIG_BPF_SYSCALL y | |
226 | set_kernel_config CONFIG_BPF_EVENTS y |
|
226 | set_kernel_config CONFIG_BPF_EVENTS y | |
227 | set_kernel_config CONFIG_BPF_STREAM_PARSER y |
|
227 | set_kernel_config CONFIG_BPF_STREAM_PARSER y | |
228 | set_kernel_config CONFIG_CGROUP_BPF y |
|
228 | set_kernel_config CONFIG_CGROUP_BPF y | |
229 | fi |
|
229 | fi | |
230 |
|
230 | |||
231 | # KERNEL_DEFAULT_GOV was set by user |
|
231 | # KERNEL_DEFAULT_GOV was set by user | |
232 | if ! [ "$KERNEL_DEFAULT_GOV" = POWERSAVE ] && [ -n "$KERNEL_DEFAULT_GOV" ]; then |
|
232 | if ! [ "$KERNEL_DEFAULT_GOV" = POWERSAVE ] && [ -n "$KERNEL_DEFAULT_GOV" ]; then | |
233 | # unset default governor |
|
233 | # unset default governor | |
234 | unset_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE |
|
234 | unset_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE | |
235 |
|
235 | |||
236 | case "$KERNEL_DEFAULT_GOV" in |
|
236 | case "$KERNEL_DEFAULT_GOV" in | |
237 | "PERFORMANCE") |
|
237 | "PERFORMANCE") | |
238 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE y |
|
238 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE y | |
239 | ;; |
|
239 | ;; | |
240 | "USERSPACE") |
|
240 | "USERSPACE") | |
241 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE y |
|
241 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE y | |
242 | ;; |
|
242 | ;; | |
243 | "ONDEMAND") |
|
243 | "ONDEMAND") | |
244 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND y |
|
244 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND y | |
245 | ;; |
|
245 | ;; | |
246 | "CONSERVATIVE") |
|
246 | "CONSERVATIVE") | |
247 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE y |
|
247 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE y | |
248 | ;; |
|
248 | ;; | |
249 | "CONSERVATIVE") |
|
249 | "CONSERVATIVE") | |
250 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL y |
|
250 | set_kernel_config CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL y | |
251 | ;; |
|
251 | ;; | |
252 | *) |
|
252 | *) | |
253 | echo "error: unsupported default cpu governor" |
|
253 | echo "error: unsupported default cpu governor" | |
254 | exit 1 |
|
254 | exit 1 | |
255 | ;; |
|
255 | ;; | |
256 | esac |
|
256 | esac | |
257 | fi |
|
257 | fi | |
258 |
|
258 | |||
259 |
|
259 | |||
260 |
|
260 | |||
261 | #Revert to previous directory |
|
261 | #Revert to previous directory | |
262 | cd "${WORKDIR}" || exit |
|
262 | cd "${WORKDIR}" || exit | |
263 |
|
263 | |||
264 | # Set kernel configuration parameters to enable qemu emulation |
|
264 | # Set kernel configuration parameters to enable qemu emulation | |
265 | if [ "$ENABLE_QEMU" = true ] ; then |
|
265 | if [ "$ENABLE_QEMU" = true ] ; then | |
266 | echo "CONFIG_FHANDLE=y" >> "${KERNEL_DIR}"/.config |
|
266 | echo "CONFIG_FHANDLE=y" >> "${KERNEL_DIR}"/.config | |
267 | echo "CONFIG_LBDAF=y" >> "${KERNEL_DIR}"/.config |
|
267 | echo "CONFIG_LBDAF=y" >> "${KERNEL_DIR}"/.config | |
268 |
|
268 | |||
269 | if [ "$ENABLE_CRYPTFS" = true ] ; then |
|
269 | if [ "$ENABLE_CRYPTFS" = true ] ; then | |
270 | { |
|
270 | { | |
271 | echo "CONFIG_EMBEDDED=y" |
|
271 | echo "CONFIG_EMBEDDED=y" | |
272 | echo "CONFIG_EXPERT=y" |
|
272 | echo "CONFIG_EXPERT=y" | |
273 | echo "CONFIG_DAX=y" |
|
273 | echo "CONFIG_DAX=y" | |
274 | echo "CONFIG_MD=y" |
|
274 | echo "CONFIG_MD=y" | |
275 | echo "CONFIG_BLK_DEV_MD=y" |
|
275 | echo "CONFIG_BLK_DEV_MD=y" | |
276 | echo "CONFIG_MD_AUTODETECT=y" |
|
276 | echo "CONFIG_MD_AUTODETECT=y" | |
277 | echo "CONFIG_BLK_DEV_DM=y" |
|
277 | echo "CONFIG_BLK_DEV_DM=y" | |
278 | echo "CONFIG_BLK_DEV_DM_BUILTIN=y" |
|
278 | echo "CONFIG_BLK_DEV_DM_BUILTIN=y" | |
279 | echo "CONFIG_DM_CRYPT=y" |
|
279 | echo "CONFIG_DM_CRYPT=y" | |
280 | echo "CONFIG_CRYPTO_BLKCIPHER=y" |
|
280 | echo "CONFIG_CRYPTO_BLKCIPHER=y" | |
281 | echo "CONFIG_CRYPTO_CBC=y" |
|
281 | echo "CONFIG_CRYPTO_CBC=y" | |
282 | echo "CONFIG_CRYPTO_XTS=y" |
|
282 | echo "CONFIG_CRYPTO_XTS=y" | |
283 | echo "CONFIG_CRYPTO_SHA512=y" |
|
283 | echo "CONFIG_CRYPTO_SHA512=y" | |
284 | echo "CONFIG_CRYPTO_MANAGER=y" |
|
284 | echo "CONFIG_CRYPTO_MANAGER=y" | |
285 | } >> "${KERNEL_DIR}"/.config |
|
285 | } >> "${KERNEL_DIR}"/.config | |
286 | fi |
|
286 | fi | |
287 | fi |
|
287 | fi | |
288 |
|
288 | |||
289 | # Copy custom kernel configuration file |
|
289 | # Copy custom kernel configuration file | |
290 | if [ -n "$KERNELSRC_USRCONFIG" ] ; then |
|
290 | if [ -n "$KERNELSRC_USRCONFIG" ] ; then | |
291 | cp "$KERNELSRC_USRCONFIG" "${KERNEL_DIR}"/.config |
|
291 | cp "$KERNELSRC_USRCONFIG" "${KERNEL_DIR}"/.config | |
292 | fi |
|
292 | fi | |
293 |
|
293 | |||
294 | # Set kernel configuration parameters to their default values |
|
294 | # Set kernel configuration parameters to their default values | |
295 | if [ "$KERNEL_OLDDEFCONFIG" = true ] ; then |
|
295 | if [ "$KERNEL_OLDDEFCONFIG" = true ] ; then | |
296 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" olddefconfig |
|
296 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" olddefconfig | |
297 | fi |
|
297 | fi | |
298 |
|
298 | |||
299 | # Start menu-driven kernel configuration (interactive) |
|
299 | # Start menu-driven kernel configuration (interactive) | |
300 | if [ "$KERNEL_MENUCONFIG" = true ] ; then |
|
300 | if [ "$KERNEL_MENUCONFIG" = true ] ; then | |
301 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig |
|
301 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig | |
302 | fi |
|
302 | fi | |
303 | # end if "$KERNELSRC_CONFIG" = true |
|
303 | # end if "$KERNELSRC_CONFIG" = true | |
304 | fi |
|
304 | fi | |
305 |
|
305 | |||
306 | # Use ccache to cross compile the kernel |
|
306 | # Use ccache to cross compile the kernel | |
307 | if [ "$KERNEL_CCACHE" = true ] ; then |
|
307 | if [ "$KERNEL_CCACHE" = true ] ; then | |
308 | cc="ccache ${CROSS_COMPILE}gcc" |
|
308 | cc="ccache ${CROSS_COMPILE}gcc" | |
309 | else |
|
309 | else | |
310 | cc="${CROSS_COMPILE}gcc" |
|
310 | cc="${CROSS_COMPILE}gcc" | |
311 | fi |
|
311 | fi | |
312 |
|
312 | |||
313 | # Cross compile kernel and dtbs |
|
313 | # Cross compile kernel and dtbs | |
314 | make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" "${KERNEL_BIN_IMAGE}" dtbs |
|
314 | make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" "${KERNEL_BIN_IMAGE}" dtbs | |
315 |
|
315 | |||
316 | # Cross compile kernel modules |
|
316 | # Cross compile kernel modules | |
317 | if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then |
|
317 | if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then | |
318 | make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" modules |
|
318 | make -C "${KERNEL_DIR}" -j"${KERNEL_THREADS}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" modules | |
319 | fi |
|
319 | fi | |
320 | # end if "$KERNELSRC_PREBUILT" = false |
|
320 | # end if "$KERNELSRC_PREBUILT" = false | |
321 | fi |
|
321 | fi | |
322 |
|
322 | |||
323 | # Check if kernel compilation was successful |
|
323 | # Check if kernel compilation was successful | |
324 | if [ ! -r "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" ] ; then |
|
324 | if [ ! -r "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" ] ; then | |
325 | echo "error: kernel compilation failed! (kernel image not found)" |
|
325 | echo "error: kernel compilation failed! (kernel image not found)" | |
326 | cleanup |
|
326 | cleanup | |
327 | exit 1 |
|
327 | exit 1 | |
328 | fi |
|
328 | fi | |
329 |
|
329 | |||
330 | # Install kernel modules |
|
330 | # Install kernel modules | |
331 | if [ "$ENABLE_REDUCE" = true ] ; then |
|
331 | if [ "$ENABLE_REDUCE" = true ] ; then | |
332 | if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then |
|
332 | if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then | |
333 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install |
|
333 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install | |
334 | fi |
|
334 | fi | |
335 | else |
|
335 | else | |
336 | if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then |
|
336 | if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then | |
337 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install |
|
337 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install | |
338 | fi |
|
338 | fi | |
339 |
|
339 | |||
340 | # Install kernel firmware |
|
340 | # Install kernel firmware | |
341 | if grep -q "^firmware_install:" "${KERNEL_DIR}/Makefile" ; then |
|
341 | if grep -q "^firmware_install:" "${KERNEL_DIR}/Makefile" ; then | |
342 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install |
|
342 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install | |
343 | fi |
|
343 | fi | |
344 | fi |
|
344 | fi | |
345 |
|
345 | |||
346 | # Install kernel headers |
|
346 | # Install kernel headers | |
347 | if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then |
|
347 | if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then | |
348 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install |
|
348 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install | |
349 | fi |
|
349 | fi | |
350 | # make tar.gz kernel package - missing os bzw. modules |
|
350 | # make tar.gz kernel package - missing os bzw. modules | |
351 | #** ** ** WARNING ** ** ** |
|
351 | #** ** ** WARNING ** ** ** | |
352 | #Your architecture did not define any architecture-dependent files |
|
352 | #Your architecture did not define any architecture-dependent files | |
353 | #to be placed into the tarball. Please add those to ./scripts/package/buildtar . |
|
353 | #to be placed into the tarball. Please add those to ./scripts/package/buildtar . | |
354 | # make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" targz-pkg |
|
354 | # make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" CC="${cc}" targz-pkg | |
355 |
|
355 | |||
356 | # Prepare boot (firmware) directory |
|
356 | # Prepare boot (firmware) directory | |
357 | mkdir "${BOOT_DIR}" |
|
357 | mkdir "${BOOT_DIR}" | |
358 |
|
358 | |||
359 | # Get kernel release version |
|
359 | # Get kernel release version | |
360 | KERNEL_VERSION=$(cat "${KERNEL_DIR}/include/config/kernel.release") |
|
360 | KERNEL_VERSION=$(cat "${KERNEL_DIR}/include/config/kernel.release") | |
361 |
|
361 | |||
362 | # Copy kernel configuration file to the boot directory |
|
362 | # Copy kernel configuration file to the boot directory | |
363 | install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}" |
|
363 | install_readonly "${KERNEL_DIR}/.config" "${R}/boot/config-${KERNEL_VERSION}" | |
364 |
|
364 | |||
365 | # Prepare device tree directory |
|
365 | # Prepare device tree directory | |
366 | mkdir "${BOOT_DIR}/overlays" |
|
366 | mkdir "${BOOT_DIR}/overlays" | |
367 |
|
367 | |||
368 | # Ensure the proper .dtb is located |
|
368 | # Ensure the proper .dtb is located | |
369 | if [ "$KERNEL_ARCH" = "arm" ] ; then |
|
369 | if [ "$KERNEL_ARCH" = "arm" ] ; then | |
370 | for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb ; do |
|
370 | for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb ; do | |
371 | if [ -f "${dtb}" ] ; then |
|
371 | if [ -f "${dtb}" ] ; then | |
372 | install_readonly "${dtb}" "${BOOT_DIR}/" |
|
372 | install_readonly "${dtb}" "${BOOT_DIR}/" | |
373 | fi |
|
373 | fi | |
374 | done |
|
374 | done | |
375 | else |
|
375 | else | |
376 | for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb ; do |
|
376 | for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/broadcom/"*.dtb ; do | |
377 | if [ -f "${dtb}" ] ; then |
|
377 | if [ -f "${dtb}" ] ; then | |
378 | install_readonly "${dtb}" "${BOOT_DIR}/" |
|
378 | install_readonly "${dtb}" "${BOOT_DIR}/" | |
379 | fi |
|
379 | fi | |
380 | done |
|
380 | done | |
381 | fi |
|
381 | fi | |
382 |
|
382 | |||
383 | # Copy compiled dtb device tree files |
|
383 | # Copy compiled dtb device tree files | |
384 | if [ -d "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays" ] ; then |
|
384 | if [ -d "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays" ] ; then | |
385 | for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb ; do |
|
385 | for dtb in "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb ; do | |
386 | if [ -f "${dtb}" ] ; then |
|
386 | if [ -f "${dtb}" ] ; then | |
387 | install_readonly "${dtb}" "${BOOT_DIR}/overlays/" |
|
387 | install_readonly "${dtb}" "${BOOT_DIR}/overlays/" | |
388 | fi |
|
388 | fi | |
389 | done |
|
389 | done | |
390 |
|
390 | |||
391 | if [ -f "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" ] ; then |
|
391 | if [ -f "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" ] ; then | |
392 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README" |
|
392 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOT_DIR}/overlays/README" | |
393 | fi |
|
393 | fi | |
394 | fi |
|
394 | fi | |
395 |
|
395 | |||
396 | if [ "$ENABLE_UBOOT" = false ] ; then |
|
396 | if [ "$ENABLE_UBOOT" = false ] ; then | |
397 | # Convert and copy kernel image to the boot directory |
|
397 | # Convert and copy kernel image to the boot directory | |
398 | "${KERNEL_DIR}/scripts/mkknlimg" "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}" |
|
398 | "${KERNEL_DIR}/scripts/mkknlimg" "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}" | |
399 | else |
|
399 | else | |
400 | # Copy kernel image to the boot directory |
|
400 | # Copy kernel image to the boot directory | |
401 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}" |
|
401 | install_readonly "${KERNEL_DIR}/arch/${KERNEL_ARCH}/boot/${KERNEL_BIN_IMAGE}" "${BOOT_DIR}/${KERNEL_IMAGE}" | |
402 | fi |
|
402 | fi | |
403 |
|
403 | |||
404 | # Remove kernel sources |
|
404 | # Remove kernel sources | |
405 | if [ "$KERNEL_REMOVESRC" = true ] ; then |
|
405 | if [ "$KERNEL_REMOVESRC" = true ] ; then | |
406 | rm -fr "${KERNEL_DIR}" |
|
406 | rm -fr "${KERNEL_DIR}" | |
407 | else |
|
407 | else | |
408 | # Prepare compiled kernel modules |
|
408 | # Prepare compiled kernel modules | |
409 | if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then |
|
409 | if grep -q "CONFIG_MODULES=y" "${KERNEL_DIR}/.config" ; then | |
410 | if grep -q "^modules_prepare:" "${KERNEL_DIR}/Makefile" ; then |
|
410 | if grep -q "^modules_prepare:" "${KERNEL_DIR}/Makefile" ; then | |
411 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare |
|
411 | make -C "${KERNEL_DIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" modules_prepare | |
412 | fi |
|
412 | fi | |
413 |
|
413 | |||
414 | # Create symlinks for kernel modules |
|
414 | # Create symlinks for kernel modules | |
415 | chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/build" |
|
415 | chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/build" | |
416 | chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/source" |
|
416 | chroot_exec ln -sf /usr/src/linux "/lib/modules/${KERNEL_VERSION}/source" | |
417 | fi |
|
417 | fi | |
418 | fi |
|
418 | fi | |
419 |
|
419 | |||
420 | else # BUILD_KERNEL=false |
|
420 | else # BUILD_KERNEL=false | |
421 | # echo Install precompiled kernel... |
|
421 | # echo Install precompiled kernel... | |
422 | # echo error: not implemented |
|
422 | # echo error: not implemented | |
423 | if [ "$SET_ARCH" = 64 ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then |
|
423 | if [ "$SET_ARCH" = 64 ] && { [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; } ; then | |
424 |
|
424 | |||
425 | # Use Sakakis modified kernel if ZSWAP is active |
|
425 | # Use Sakakis modified kernel if ZSWAP is active | |
426 | if [ "$KERNEL_ZSWAP" = true ] || [ "$KERNEL_VIRT" = true ] || [ "$KERNEL_NF" = true ] || [ "$KERNEL_BPF" = true ] ; then |
|
426 | if [ "$KERNEL_ZSWAP" = true ] || [ "$KERNEL_VIRT" = true ] || [ "$KERNEL_NF" = true ] || [ "$KERNEL_BPF" = true ] ; then | |
427 | RPI3_64_KERNEL_URL=RPI3_64_BIS_KERNEL_URL |
|
427 | RPI3_64_KERNEL_URL=RPI3_64_BIS_KERNEL_URL | |
428 | fi |
|
428 | fi | |
429 |
|
429 | |||
430 | # Create temporary directory for dl |
|
430 | # Create temporary directory for dl | |
431 | temp_dir=$(as_nobody mktemp -d) |
|
431 | temp_dir=$(as_nobody mktemp -d) | |
432 |
|
432 | |||
433 | # Fetch kernel dl |
|
433 | # Fetch kernel dl | |
434 | as_nobody wget -O "${temp_dir}"/kernel.tar.xz -c "$RPI3_64_KERNEL_URL" |
|
434 | as_nobody wget -O "${temp_dir}"/kernel.tar.xz -c "$RPI3_64_KERNEL_URL" | |
435 |
|
435 | |||
436 | #extract download |
|
436 | #extract download | |
437 | tar -xJf "${temp_dir}"/kernel.tar.xz -C "${temp_dir}" |
|
437 | tar -xJf "${temp_dir}"/kernel.tar.xz -C "${temp_dir}" | |
438 |
|
438 | |||
439 | #move extracted kernel to /boot/firmware |
|
439 | #move extracted kernel to /boot/firmware | |
440 | mkdir "${R}/boot/firmware" |
|
440 | mkdir "${R}/boot/firmware" | |
441 | cp "${temp_dir}"/boot/* "${R}"/boot/firmware/ |
|
441 | cp "${temp_dir}"/boot/* "${R}"/boot/firmware/ | |
442 | cp -r "${temp_dir}"/lib/* "${R}"/lib/ |
|
442 | cp -r "${temp_dir}"/lib/* "${R}"/lib/ | |
443 |
|
443 | |||
444 | # Remove temporary directory for kernel sources |
|
444 | # Remove temporary directory for kernel sources | |
445 | rm -fr "${temp_dir}" |
|
445 | rm -fr "${temp_dir}" | |
446 |
|
446 | |||
447 | # Set permissions of the kernel sources |
|
447 | # Set permissions of the kernel sources | |
448 | chown -R root:root "${R}/boot/firmware" |
|
448 | chown -R root:root "${R}/boot/firmware" | |
449 | chown -R root:root "${R}/lib/modules" |
|
449 | chown -R root:root "${R}/lib/modules" | |
450 | fi |
|
450 | fi | |
451 |
|
451 | |||
452 | # INstall Kernel from hypriot comptabile with all Raspberry PI |
|
452 | # INstall Kernel from hypriot comptabile with all Raspberry PI | |
453 | if [ "$SET_ARCH" = 32 ] ; then |
|
453 | if [ "$SET_ARCH" = 32 ] ; then | |
454 | # Create temporary directory for dl |
|
454 | # Create temporary directory for dl | |
455 | temp_dir=$(as_nobody mktemp -d) |
|
455 | temp_dir=$(as_nobody mktemp -d) | |
456 |
|
456 | |||
457 | # Fetch kernel |
|
457 | # Fetch kernel | |
458 | as_nobody wget -O "${temp_dir}"/kernel.deb -c "$RPI_32_KERNEL_URL" |
|
458 | as_nobody wget -O "${temp_dir}"/kernel.deb -c "$RPI_32_KERNEL_URL" | |
459 |
|
459 | |||
460 | # Copy downloaded U-Boot sources |
|
460 | # Copy downloaded U-Boot sources | |
461 | mv "${temp_dir}"/kernel.deb "${R}"/tmp/kernel.deb |
|
461 | mv "${temp_dir}"/kernel.deb "${R}"/tmp/kernel.deb | |
462 |
|
462 | |||
463 | # Set permissions |
|
463 | # Set permissions | |
464 | chown -R root:root "${R}"/tmp/kernel.deb |
|
464 | chown -R root:root "${R}"/tmp/kernel.deb | |
465 |
|
465 | |||
466 | # Install kernel |
|
466 | # Install kernel | |
467 | chroot_exec dpkg -i /tmp/kernel.deb |
|
467 | chroot_exec dpkg -i /tmp/kernel.deb | |
468 |
|
468 | |||
469 | # move /boot to /boot/firmware to fit script env. |
|
469 | # move /boot to /boot/firmware to fit script env. | |
470 | #mkdir "${BOOT_DIR}" |
|
470 | #mkdir "${BOOT_DIR}" | |
471 | mkdir "${temp_dir}"/firmware |
|
471 | mkdir "${temp_dir}"/firmware | |
472 | mv "${R}"/boot/* "${temp_dir}"/firmware/ |
|
472 | mv "${R}"/boot/* "${temp_dir}"/firmware/ | |
473 | mv "${temp_dir}"/firmware "${R}"/boot/ |
|
473 | mv "${temp_dir}"/firmware "${R}"/boot/ | |
474 |
|
474 | |||
475 | #same for kernel headers |
|
475 | #same for kernel headers | |
476 | if [ "$KERNEL_HEADERS" = true ] ; then |
|
476 | if [ "$KERNEL_HEADERS" = true ] ; then | |
477 | # Fetch kernel header |
|
477 | # Fetch kernel header | |
478 | as_nobody wget -O "${temp_dir}"/kernel-header.deb -c "$RPI_32_KERNELHEADER_URL" |
|
478 | as_nobody wget -O "${temp_dir}"/kernel-header.deb -c "$RPI_32_KERNELHEADER_URL" | |
479 | mv "${temp_dir}"/kernel-header.deb "${R}"/tmp/kernel-header.deb |
|
479 | mv "${temp_dir}"/kernel-header.deb "${R}"/tmp/kernel-header.deb | |
480 | chown -R root:root "${R}"/tmp/kernel-header.deb |
|
480 | chown -R root:root "${R}"/tmp/kernel-header.deb | |
481 | # Install kernel header |
|
481 | # Install kernel header | |
482 | chroot_exec dpkg -i /tmp/kernel-header.deb |
|
482 | chroot_exec dpkg -i /tmp/kernel-header.deb | |
483 | rm -f "${R}"/tmp/kernel-header.deb |
|
483 | rm -f "${R}"/tmp/kernel-header.deb | |
484 | fi |
|
484 | fi | |
485 |
|
485 | |||
486 | # Remove temporary directory and files |
|
486 | # Remove temporary directory and files | |
487 | rm -fr "${temp_dir}" |
|
487 | rm -fr "${temp_dir}" | |
488 | rm -f "${R}"/tmp/kernel.deb |
|
488 | rm -f "${R}"/tmp/kernel.deb | |
489 | fi |
|
489 | fi | |
490 |
|
490 | |||
491 | # Check if kernel installation was successful |
|
491 | # Check if kernel installation was successful | |
492 | KERNEL="$(ls -1 "${R}"/boot/firmware/kernel* | sort | tail -n 1)" |
|
492 | KERNEL="$(ls -1 "${R}"/boot/firmware/kernel* | sort | tail -n 1)" | |
493 | if [ -z "$KERNEL" ] ; then |
|
493 | if [ -z "$KERNEL" ] ; then | |
494 | echo "error: kernel installation failed! (/boot/kernel* not found)" |
|
494 | echo "error: kernel installation failed! (/boot/kernel* not found)" | |
495 | cleanup |
|
495 | cleanup | |
496 | exit 1 |
|
496 | exit 1 | |
497 | fi |
|
497 | fi | |
498 | fi |
|
498 | fi |
@@ -1,271 +1,273 | |||||
1 | # |
|
1 | # | |
2 | # Setup RPi2/3 config and cmdline |
|
2 | # Setup RPi2/3 config and cmdline | |
3 | # |
|
3 | # | |
4 |
|
4 | |||
5 | # Load utility functions |
|
5 | # Load utility functions | |
6 | . ./functions.sh |
|
6 | . ./functions.sh | |
7 |
|
7 | |||
8 | #if [ "$BUILD_KERNEL" = true ] ; then |
|
8 | #if [ "$BUILD_KERNEL" = true ] ; then | |
9 | if [ -n "$RPI_FIRMWARE_DIR" ] && [ -d "$RPI_FIRMWARE_DIR" ] ; then |
|
9 | if [ -n "$RPI_FIRMWARE_DIR" ] && [ -d "$RPI_FIRMWARE_DIR" ] ; then | |
10 | # Install boot binaries from local directory |
|
10 | # Install boot binaries from local directory | |
11 | cp "${RPI_FIRMWARE_DIR}"/boot/bootcode.bin "${BOOT_DIR}"/bootcode.bin |
|
11 | cp "${RPI_FIRMWARE_DIR}"/boot/bootcode.bin "${BOOT_DIR}"/bootcode.bin | |
12 | cp "${RPI_FIRMWARE_DIR}"/boot/fixup.dat "${BOOT_DIR}"/fixup.dat |
|
12 | cp "${RPI_FIRMWARE_DIR}"/boot/fixup.dat "${BOOT_DIR}"/fixup.dat | |
13 | cp "${RPI_FIRMWARE_DIR}"/boot/fixup_cd.dat "${BOOT_DIR}"/fixup_cd.dat |
|
13 | cp "${RPI_FIRMWARE_DIR}"/boot/fixup_cd.dat "${BOOT_DIR}"/fixup_cd.dat | |
14 | cp "${RPI_FIRMWARE_DIR}"/boot/fixup_x.dat "${BOOT_DIR}"/fixup_x.dat |
|
14 | cp "${RPI_FIRMWARE_DIR}"/boot/fixup_x.dat "${BOOT_DIR}"/fixup_x.dat | |
15 | cp "${RPI_FIRMWARE_DIR}"/boot/start.elf "${BOOT_DIR}"/start.elf |
|
15 | cp "${RPI_FIRMWARE_DIR}"/boot/start.elf "${BOOT_DIR}"/start.elf | |
16 | cp "${RPI_FIRMWARE_DIR}"/boot/start_cd.elf "${BOOT_DIR}"/start_cd.elf |
|
16 | cp "${RPI_FIRMWARE_DIR}"/boot/start_cd.elf "${BOOT_DIR}"/start_cd.elf | |
17 | cp "${RPI_FIRMWARE_DIR}"/boot/start_x.elf "${BOOT_DIR}"/start_x.elf |
|
17 | cp "${RPI_FIRMWARE_DIR}"/boot/start_x.elf "${BOOT_DIR}"/start_x.elf | |
18 | else |
|
18 | else | |
19 | # Create temporary directory for boot binaries |
|
19 | # Create temporary directory for boot binaries | |
20 | temp_dir=$(as_nobody mktemp -d) |
|
20 | temp_dir=$(as_nobody mktemp -d) | |
21 |
|
21 | |||
22 | # Install latest boot binaries from raspberry/firmware github |
|
22 | # Install latest boot binaries from raspberry/firmware github | |
23 | as_nobody wget -q -O "${temp_dir}/bootcode.bin" "${FIRMWARE_URL}/bootcode.bin" |
|
23 | as_nobody wget -q -O "${temp_dir}/bootcode.bin" "${FIRMWARE_URL}/bootcode.bin" | |
24 | as_nobody wget -q -O "${temp_dir}/fixup.dat" "${FIRMWARE_URL}/fixup.dat" |
|
24 | as_nobody wget -q -O "${temp_dir}/fixup.dat" "${FIRMWARE_URL}/fixup.dat" | |
25 | as_nobody wget -q -O "${temp_dir}/fixup_cd.dat" "${FIRMWARE_URL}/fixup_cd.dat" |
|
25 | as_nobody wget -q -O "${temp_dir}/fixup_cd.dat" "${FIRMWARE_URL}/fixup_cd.dat" | |
26 | as_nobody wget -q -O "${temp_dir}/fixup_x.dat" "${FIRMWARE_URL}/fixup_x.dat" |
|
26 | as_nobody wget -q -O "${temp_dir}/fixup_x.dat" "${FIRMWARE_URL}/fixup_x.dat" | |
27 | as_nobody wget -q -O "${temp_dir}/start.elf" "${FIRMWARE_URL}/start.elf" |
|
27 | as_nobody wget -q -O "${temp_dir}/start.elf" "${FIRMWARE_URL}/start.elf" | |
28 | as_nobody wget -q -O "${temp_dir}/start_cd.elf" "${FIRMWARE_URL}/start_cd.elf" |
|
28 | as_nobody wget -q -O "${temp_dir}/start_cd.elf" "${FIRMWARE_URL}/start_cd.elf" | |
29 | as_nobody wget -q -O "${temp_dir}/start_x.elf" "${FIRMWARE_URL}/start_x.elf" |
|
29 | as_nobody wget -q -O "${temp_dir}/start_x.elf" "${FIRMWARE_URL}/start_x.elf" | |
30 |
|
30 | |||
31 | # Move downloaded boot binaries |
|
31 | # Move downloaded boot binaries | |
32 | mv "${temp_dir}/"* "${BOOT_DIR}/" |
|
32 | mv "${temp_dir}/"* "${BOOT_DIR}/" | |
33 |
|
33 | |||
34 | # Remove temporary directory for boot binaries |
|
34 | # Remove temporary directory for boot binaries | |
35 | rm -fr "${temp_dir}" |
|
35 | rm -fr "${temp_dir}" | |
36 |
|
36 | |||
37 | # Set permissions of the boot binaries |
|
37 | # Set permissions of the boot binaries | |
38 | chown -R root:root "${BOOT_DIR}" |
|
38 | chown -R root:root "${BOOT_DIR}" | |
39 | chmod -R 600 "${BOOT_DIR}" |
|
39 | chmod -R 600 "${BOOT_DIR}" | |
40 | fi |
|
40 | fi | |
41 | #fi |
|
41 | #fi | |
42 |
|
42 | |||
43 | # Setup firmware boot cmdline |
|
43 | # Setup firmware boot cmdline | |
44 | if [ "$ENABLE_UBOOTUSB" = true ] ; then |
|
44 | if [ "$ENABLE_UBOOTUSB" = true ] ; then | |
45 | CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd" |
|
45 | CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd" | |
46 | else |
|
46 | else | |
47 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
47 | if [ "$ENABLE_SPLITFS" = true ] ; then | |
48 | CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd" |
|
48 | CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd" | |
49 | else |
|
49 | else | |
50 | CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd" |
|
50 | CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1 init=/bin/systemd" | |
51 | fi |
|
51 | fi | |
52 | fi |
|
52 | fi | |
53 |
|
53 | |||
54 | # Add encrypted root partition to cmdline.txt |
|
54 | # Add encrypted root partition to cmdline.txt | |
55 | if [ "$ENABLE_CRYPTFS" = true ] ; then |
|
55 | if [ "$ENABLE_CRYPTFS" = true ] ; then | |
56 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
56 | if [ "$ENABLE_SPLITFS" = true ] ; then | |
57 | CMDLINE=$(echo "${CMDLINE}" | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/") |
|
57 | CMDLINE=$(echo "${CMDLINE}" | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/") | |
58 | else |
|
58 | else | |
59 | if [ "$ENABLE_UBOOTUSB" = true ] ; then |
|
59 | if [ "$ENABLE_UBOOTUSB" = true ] ; then | |
60 | CMDLINE=$(echo "${CMDLINE}" | sed "s/sda2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda2:${CRYPTFS_MAPPING}/") |
|
60 | CMDLINE=$(echo "${CMDLINE}" | sed "s/sda2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda2:${CRYPTFS_MAPPING}/") | |
61 | else |
|
61 | else | |
62 | CMDLINE=$(echo "${CMDLINE}" | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/") |
|
62 | CMDLINE=$(echo "${CMDLINE}" | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/") | |
63 | fi |
|
63 | fi | |
64 | fi |
|
64 | fi | |
65 | fi |
|
65 | fi | |
66 |
|
66 | |||
67 | if [ "$ENABLE_PRINTK" = true ] ; then |
|
67 | if [ "$ENABLE_PRINTK" = true ] ; then | |
68 | install_readonly files/sysctl.d/83-rpi-printk.conf "${ETC_DIR}/sysctl.d/83-rpi-printk.conf" |
|
68 | install_readonly files/sysctl.d/83-rpi-printk.conf "${ETC_DIR}/sysctl.d/83-rpi-printk.conf" | |
69 | fi |
|
69 | fi | |
70 |
|
70 | |||
71 | # Install udev rule for serial alias - serial0 = console serial1=bluetooth |
|
71 | # Install udev rule for serial alias - serial0 = console serial1=bluetooth | |
72 | install_readonly files/etc/99-com.rules "${LIB_DIR}/udev/rules.d/99-com.rules" |
|
72 | install_readonly files/etc/99-com.rules "${LIB_DIR}/udev/rules.d/99-com.rules" | |
73 |
|
73 | |||
74 | # Remove IPv6 networking support |
|
74 | # Remove IPv6 networking support | |
75 | if [ "$ENABLE_IPV6" = false ] ; then |
|
75 | if [ "$ENABLE_IPV6" = false ] ; then | |
76 | CMDLINE="${CMDLINE} ipv6.disable=1" |
|
76 | CMDLINE="${CMDLINE} ipv6.disable=1" | |
77 | fi |
|
77 | fi | |
78 |
|
78 | |||
79 | # Automatically assign predictable network interface names |
|
79 | # Automatically assign predictable network interface names | |
80 | if [ "$ENABLE_IFNAMES" = false ] ; then |
|
80 | if [ "$ENABLE_IFNAMES" = false ] ; then | |
81 | CMDLINE="${CMDLINE} net.ifnames=0" |
|
81 | CMDLINE="${CMDLINE} net.ifnames=0" | |
82 | else |
|
82 | else | |
83 | CMDLINE="${CMDLINE} net.ifnames=1" |
|
83 | CMDLINE="${CMDLINE} net.ifnames=1" | |
84 | fi |
|
84 | fi | |
85 |
|
85 | |||
86 | # Install firmware config |
|
86 | # Install firmware config | |
87 | install_readonly files/boot/config.txt "${BOOT_DIR}/config.txt" |
|
87 | install_readonly files/boot/config.txt "${BOOT_DIR}/config.txt" | |
88 |
|
88 | |||
89 | #locks cpu at max frequency |
|
89 | #locks cpu at max frequency | |
90 | if [ "$ENABLE_TURBO" = true ] ; then |
|
90 | if [ "$ENABLE_TURBO" = true ] ; then | |
91 | echo "force_turbo=1" >> "${BOOT_DIR}/config.txt" |
|
91 | echo "force_turbo=1" >> "${BOOT_DIR}/config.txt" | |
92 | # helps to avoid sdcard corruption when force_turbo is enabled. |
|
92 | # helps to avoid sdcard corruption when force_turbo is enabled. | |
93 | echo "boot_delay=1" >> "${BOOT_DIR}/config.txt" |
|
93 | echo "boot_delay=1" >> "${BOOT_DIR}/config.txt" | |
94 | fi |
|
94 | fi | |
95 |
|
95 | |||
96 | if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then |
|
96 | if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then | |
97 |
|
97 | |||
98 | # Bluetooth enabled |
|
98 | # Bluetooth enabled | |
99 | if [ "$ENABLE_BLUETOOTH" = true ] ; then |
|
99 | if [ "$ENABLE_BLUETOOTH" = true ] ; then | |
100 | # Create temporary directory for Bluetooth sources |
|
100 | # Create temporary directory for Bluetooth sources | |
101 | temp_dir=$(as_nobody mktemp -d) |
|
101 | temp_dir=$(as_nobody mktemp -d) | |
102 |
|
102 | |||
103 | # Fetch Bluetooth sources |
|
103 | # Fetch Bluetooth sources | |
104 | as_nobody git -C "${temp_dir}" clone "${BLUETOOTH_URL}" |
|
104 | as_nobody git -C "${temp_dir}" clone "${BLUETOOTH_URL}" | |
105 |
|
105 | |||
106 | # Copy downloaded sources |
|
106 | # Copy downloaded sources | |
107 | mv "${temp_dir}/pi-bluetooth" "${R}/tmp/" |
|
107 | mv "${temp_dir}/pi-bluetooth" "${R}/tmp/" | |
108 |
|
108 | |||
109 | # Bluetooth firmware from arch aur https://aur.archlinux.org/packages/pi-bluetooth/ |
|
109 | # Bluetooth firmware from arch aur https://aur.archlinux.org/packages/pi-bluetooth/ | |
110 | as_nobody wget -q -O "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" https://aur.archlinux.org/cgit/aur.git/plain/LICENCE.broadcom_bcm43xx?h=pi-bluetooth |
|
110 | as_nobody wget -q -O "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" https://aur.archlinux.org/cgit/aur.git/plain/LICENCE.broadcom_bcm43xx?h=pi-bluetooth | |
111 | as_nobody wget -q -O "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth |
|
111 | as_nobody wget -q -O "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth | |
112 |
|
112 | |||
113 | # Set permissions |
|
113 | # Set permissions | |
114 | chown -R root:root "${R}/tmp/pi-bluetooth" |
|
114 | chown -R root:root "${R}/tmp/pi-bluetooth" | |
115 |
|
115 | |||
116 | # Install tools |
|
116 | # Install tools | |
117 | install_readonly "${R}/tmp/pi-bluetooth/usr/bin/btuart" "${R}/usr/bin/btuart" |
|
117 | install_readonly "${R}/tmp/pi-bluetooth/usr/bin/btuart" "${R}/usr/bin/btuart" | |
118 | install_readonly "${R}/tmp/pi-bluetooth/usr/bin/bthelper" "${R}/usr/bin/bthelper" |
|
118 | install_readonly "${R}/tmp/pi-bluetooth/usr/bin/bthelper" "${R}/usr/bin/bthelper" | |
|
119 | chmod +x "${R}/usr/bin/bthelper" | |||
|
120 | chmod +x "${R}/usr/bin/btuart" | |||
119 |
|
121 | |||
120 | # Install bluetooth udev rule |
|
122 | # Install bluetooth udev rule | |
121 | install_readonly "${R}/tmp/pi-bluetooth/lib/udev/rules.d/90-pi-bluetooth.rules" "${LIB_DIR}/udev/rules.d/90-pi-bluetooth.rules" |
|
123 | install_readonly "${R}/tmp/pi-bluetooth/lib/udev/rules.d/90-pi-bluetooth.rules" "${LIB_DIR}/udev/rules.d/90-pi-bluetooth.rules" | |
122 |
|
124 | |||
123 | # Install Firmware Flash file and apropiate licence |
|
125 | # Install Firmware Flash file and apropiate licence | |
124 | mkdir -p "$BLUETOOTH_FIRMWARE_DIR" |
|
126 | mkdir -p "$BLUETOOTH_FIRMWARE_DIR" | |
125 | install_readonly "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx" |
|
127 | install_readonly "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx" | |
126 | install_readonly "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx" |
|
128 | install_readonly "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx" | |
127 | install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.bthelper@.service" "${ETC_DIR}/systemd/system/pi-bluetooth.bthelper@.service" |
|
129 | install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.bthelper@.service" "${ETC_DIR}/systemd/system/pi-bluetooth.bthelper@.service" | |
128 | install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.hciuart.service" "${ETC_DIR}/systemd/system/pi-bluetooth.hciuart.service" |
|
130 | install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.hciuart.service" "${ETC_DIR}/systemd/system/pi-bluetooth.hciuart.service" | |
129 |
|
131 | |||
130 | # Remove temporary directories |
|
132 | # Remove temporary directories | |
131 | rm -fr "${temp_dir}" |
|
133 | rm -fr "${temp_dir}" | |
132 | rm -fr "${R}"/tmp/pi-bluetooth |
|
134 | rm -fr "${R}"/tmp/pi-bluetooth | |
133 |
|
135 | |||
134 | # Switch Pi3 Bluetooth function to use the mini-UART (ttyS0) and restore UART0/ttyAMA0 over GPIOs 14 & 15. Slow Bluetooth and slow cpu. Use /dev/ttyS0 instead of /dev/ttyAMA0 |
|
136 | # Switch Pi3 Bluetooth function to use the mini-UART (ttyS0) and restore UART0/ttyAMA0 over GPIOs 14 & 15. Slow Bluetooth and slow cpu. Use /dev/ttyS0 instead of /dev/ttyAMA0 | |
135 | if [ "$ENABLE_MINIUART_OVERLAY" = true ] ; then |
|
137 | if [ "$ENABLE_MINIUART_OVERLAY" = true ] ; then | |
136 |
|
138 | |||
137 | # set overlay to swap ttyAMA0 and ttyS0 |
|
139 | # set overlay to swap ttyAMA0 and ttyS0 | |
138 | echo "dtoverlay=pi3-miniuart-bt" >> "${BOOT_DIR}/config.txt" |
|
140 | echo "dtoverlay=pi3-miniuart-bt" >> "${BOOT_DIR}/config.txt" | |
139 |
|
141 | |||
140 | # if force_turbo didn't lock cpu at high speed, lock it at low speed (XOR logic) or miniuart will be broken |
|
142 | # if force_turbo didn't lock cpu at high speed, lock it at low speed (XOR logic) or miniuart will be broken | |
141 | if [ "$ENABLE_TURBO" = false ] ; then |
|
143 | if [ "$ENABLE_TURBO" = false ] ; then | |
142 | echo "core_freq=250" >> "${BOOT_DIR}/config.txt" |
|
144 | echo "core_freq=250" >> "${BOOT_DIR}/config.txt" | |
143 | fi |
|
145 | fi | |
144 | fi |
|
146 | fi | |
145 |
|
147 | |||
146 | # Activate services |
|
148 | # Activate services | |
147 | chroot_exec systemctl enable pi-bluetooth.hciuart.service |
|
149 | chroot_exec systemctl enable pi-bluetooth.hciuart.service | |
148 | chroot_exec systemctl enable pi-bluetooth.bthelper@serial1.service |
|
150 | chroot_exec systemctl enable pi-bluetooth.bthelper@serial1.service | |
149 |
|
151 | |||
150 | else # if ENABLE_BLUETOOTH = false |
|
152 | else # if ENABLE_BLUETOOTH = false | |
151 | # set overlay to disable bluetooth |
|
153 | # set overlay to disable bluetooth | |
152 | echo "dtoverlay=pi3-disable-bt" >> "${BOOT_DIR}/config.txt" |
|
154 | echo "dtoverlay=pi3-disable-bt" >> "${BOOT_DIR}/config.txt" | |
153 | fi # ENABLE_BLUETOOTH end |
|
155 | fi # ENABLE_BLUETOOTH end | |
154 | fi |
|
156 | fi | |
155 |
|
157 | |||
156 | # may need sudo systemctl disable hciuart |
|
158 | # may need sudo systemctl disable hciuart | |
157 | if [ "$ENABLE_CONSOLE" = true ] ; then |
|
159 | if [ "$ENABLE_CONSOLE" = true ] ; then | |
158 | echo "enable_uart=1" >> "${BOOT_DIR}/config.txt" |
|
160 | echo "enable_uart=1" >> "${BOOT_DIR}/config.txt" | |
159 | # add string to cmdline |
|
161 | # add string to cmdline | |
160 | CMDLINE="${CMDLINE} console=serial0,115200" |
|
162 | CMDLINE="${CMDLINE} console=serial0,115200" | |
161 |
|
163 | |||
162 | # Enable serial console systemd style |
|
164 | # Enable serial console systemd style | |
163 | chroot_exec systemctl enable serial-getty@serial0.service |
|
165 | chroot_exec systemctl enable serial-getty@serial0.service | |
164 | else |
|
166 | else | |
165 | echo "enable_uart=0" >> "${BOOT_DIR}/config.txt" |
|
167 | echo "enable_uart=0" >> "${BOOT_DIR}/config.txt" | |
166 | # disable serial console systemd style |
|
168 | # disable serial console systemd style | |
167 | #chroot_exec systemctl disable serial-getty@serial0.service |
|
169 | #chroot_exec systemctl disable serial-getty@serial0.service | |
168 | fi |
|
170 | fi | |
169 |
|
171 | |||
170 | # Remove cmdline.txt entry of starting zswap |
|
172 | # Remove cmdline.txt entry of starting zswap | |
171 | if [ "$KERNEL_ZSWAP" = true ] ; then |
|
173 | if [ "$KERNEL_ZSWAP" = true ] ; then | |
172 | CMDLINE="${CMDLINE} zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4" |
|
174 | CMDLINE="${CMDLINE} zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4" | |
173 | fi |
|
175 | fi | |
174 |
|
176 | |||
175 | if [ "$ENABLE_SYSTEMDSWAP" = true ] ; then |
|
177 | if [ "$ENABLE_SYSTEMDSWAP" = true ] ; then | |
176 |
|
178 | |||
177 | # Remove cmdline.txt entry of starting zswap |
|
179 | # Remove cmdline.txt entry of starting zswap | |
178 | if [ "$KERNEL_ZSWAP" = true ] ; then |
|
180 | if [ "$KERNEL_ZSWAP" = true ] ; then | |
179 | sed -i 's|zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4||g' |
|
181 | sed -i 's|zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4||g' | |
180 | fi |
|
182 | fi | |
181 | # Create temporary directory for systemd-swap sources |
|
183 | # Create temporary directory for systemd-swap sources | |
182 | temp_dir=$(as_nobody mktemp -d) |
|
184 | temp_dir=$(as_nobody mktemp -d) | |
183 |
|
185 | |||
184 | # Fetch systemd-swap sources |
|
186 | # Fetch systemd-swap sources | |
185 | as_nobody git -C "${temp_dir}" clone "${ZSWAP_URL}" |
|
187 | as_nobody git -C "${temp_dir}" clone "${ZSWAP_URL}" | |
186 |
|
188 | |||
187 | # Copy downloaded systemd-swap sources |
|
189 | # Copy downloaded systemd-swap sources | |
188 | mv "${temp_dir}/systemd-swap" "${R}/tmp/" |
|
190 | mv "${temp_dir}/systemd-swap" "${R}/tmp/" | |
189 |
|
191 | |||
190 | # Set permissions of the systemd-swap sources |
|
192 | # Set permissions of the systemd-swap sources | |
191 | chown -R root:root "${R}/tmp/systemd-swap" |
|
193 | chown -R root:root "${R}/tmp/systemd-swap" | |
192 |
|
194 | |||
193 | # Remove temporary directory for systemd-swap sources |
|
195 | # Remove temporary directory for systemd-swap sources | |
194 | rm -fr "${temp_dir}" |
|
196 | rm -fr "${temp_dir}" | |
195 |
|
197 | |||
196 | # Change into downloaded src dir |
|
198 | # Change into downloaded src dir | |
197 | cd "${R}/tmp/systemd-swap" || exit |
|
199 | cd "${R}/tmp/systemd-swap" || exit | |
198 |
|
200 | |||
199 | # Build package |
|
201 | # Build package | |
200 | . ./systemd-swap/package.sh debian |
|
202 | . ./systemd-swap/package.sh debian | |
201 |
|
203 | |||
202 | # Install package |
|
204 | # Install package | |
203 | chroot_exec dpkg -i /tmp/systemd-swap/systemd-swap-*any.deb |
|
205 | chroot_exec dpkg -i /tmp/systemd-swap/systemd-swap-*any.deb | |
204 |
|
206 | |||
205 | # Enable service |
|
207 | # Enable service | |
206 | chroot_exec systemctl enable systemd-swap |
|
208 | chroot_exec systemctl enable systemd-swap | |
207 |
|
209 | |||
208 | # Change back into script root dir |
|
210 | # Change back into script root dir | |
209 | cd "${WORKDIR}" || exit |
|
211 | cd "${WORKDIR}" || exit | |
210 | fi |
|
212 | fi | |
211 |
|
213 | |||
212 | # Install firmware boot cmdline |
|
214 | # Install firmware boot cmdline | |
213 | echo "${CMDLINE}" > "${BOOT_DIR}/cmdline.txt" |
|
215 | echo "${CMDLINE}" > "${BOOT_DIR}/cmdline.txt" | |
214 |
|
216 | |||
215 | # Setup minimal GPU memory allocation size: 16MB (no X) |
|
217 | # Setup minimal GPU memory allocation size: 16MB (no X) | |
216 | if [ "$ENABLE_MINGPU" = true ] ; then |
|
218 | if [ "$ENABLE_MINGPU" = true ] ; then | |
217 | echo "gpu_mem=16" >> "${BOOT_DIR}/config.txt" |
|
219 | echo "gpu_mem=16" >> "${BOOT_DIR}/config.txt" | |
218 | fi |
|
220 | fi | |
219 |
|
221 | |||
220 | # Setup boot with initramfs |
|
222 | # Setup boot with initramfs | |
221 | if [ "$ENABLE_INITRAMFS" = true ] ; then |
|
223 | if [ "$ENABLE_INITRAMFS" = true ] ; then | |
222 | echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "${BOOT_DIR}/config.txt" |
|
224 | echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "${BOOT_DIR}/config.txt" | |
223 | fi |
|
225 | fi | |
224 |
|
226 | |||
225 | # Create firmware configuration and cmdline symlinks |
|
227 | # Create firmware configuration and cmdline symlinks | |
226 | ln -sf firmware/config.txt "${R}/boot/config.txt" |
|
228 | ln -sf firmware/config.txt "${R}/boot/config.txt" | |
227 | ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt" |
|
229 | ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt" | |
228 |
|
230 | |||
229 | # Install and setup kernel modules to load at boot |
|
231 | # Install and setup kernel modules to load at boot | |
230 | mkdir -p "${LIB_DIR}/modules-load.d/" |
|
232 | mkdir -p "${LIB_DIR}/modules-load.d/" | |
231 | install_readonly files/modules/rpi2.conf "${LIB_DIR}/modules-load.d/rpi2.conf" |
|
233 | install_readonly files/modules/rpi2.conf "${LIB_DIR}/modules-load.d/rpi2.conf" | |
232 |
|
234 | |||
233 | # Load hardware random module at boot |
|
235 | # Load hardware random module at boot | |
234 | if [ "$ENABLE_HWRANDOM" = true ] && [ "$BUILD_KERNEL" = false ] ; then |
|
236 | if [ "$ENABLE_HWRANDOM" = true ] && [ "$BUILD_KERNEL" = false ] ; then | |
235 | sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${LIB_DIR}/modules-load.d/rpi2.conf" |
|
237 | sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${LIB_DIR}/modules-load.d/rpi2.conf" | |
236 | fi |
|
238 | fi | |
237 |
|
239 | |||
238 | # Load sound module at boot |
|
240 | # Load sound module at boot | |
239 | if [ "$ENABLE_SOUND" = true ] ; then |
|
241 | if [ "$ENABLE_SOUND" = true ] ; then | |
240 | sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf" |
|
242 | sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf" | |
241 | else |
|
243 | else | |
242 | echo "dtparam=audio=off" >> "${BOOT_DIR}/config.txt" |
|
244 | echo "dtparam=audio=off" >> "${BOOT_DIR}/config.txt" | |
243 | fi |
|
245 | fi | |
244 |
|
246 | |||
245 | # Enable I2C interface |
|
247 | # Enable I2C interface | |
246 | if [ "$ENABLE_I2C" = true ] ; then |
|
248 | if [ "$ENABLE_I2C" = true ] ; then | |
247 | echo "dtparam=i2c_arm=on" >> "${BOOT_DIR}/config.txt" |
|
249 | echo "dtparam=i2c_arm=on" >> "${BOOT_DIR}/config.txt" | |
248 | sed -i "s/^# i2c-bcm2708/i2c-bcm2708/" "${LIB_DIR}/modules-load.d/rpi2.conf" |
|
250 | sed -i "s/^# i2c-bcm2708/i2c-bcm2708/" "${LIB_DIR}/modules-load.d/rpi2.conf" | |
249 | sed -i "s/^# i2c-dev/i2c-dev/" "${LIB_DIR}/modules-load.d/rpi2.conf" |
|
251 | sed -i "s/^# i2c-dev/i2c-dev/" "${LIB_DIR}/modules-load.d/rpi2.conf" | |
250 | fi |
|
252 | fi | |
251 |
|
253 | |||
252 | # Enable SPI interface |
|
254 | # Enable SPI interface | |
253 | if [ "$ENABLE_SPI" = true ] ; then |
|
255 | if [ "$ENABLE_SPI" = true ] ; then | |
254 | echo "dtparam=spi=on" >> "${BOOT_DIR}/config.txt" |
|
256 | echo "dtparam=spi=on" >> "${BOOT_DIR}/config.txt" | |
255 | echo "spi-bcm2708" >> "${LIB_DIR}/modules-load.d/rpi2.conf" |
|
257 | echo "spi-bcm2708" >> "${LIB_DIR}/modules-load.d/rpi2.conf" | |
256 | if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ]; then |
|
258 | if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ]; then | |
257 | sed -i "s/spi-bcm2708/spi-bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf" |
|
259 | sed -i "s/spi-bcm2708/spi-bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf" | |
258 | fi |
|
260 | fi | |
259 | fi |
|
261 | fi | |
260 |
|
262 | |||
261 | # Disable RPi2/3 under-voltage warnings |
|
263 | # Disable RPi2/3 under-voltage warnings | |
262 | if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then |
|
264 | if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then | |
263 | echo "avoid_warnings=${DISABLE_UNDERVOLT_WARNINGS}" >> "${BOOT_DIR}/config.txt" |
|
265 | echo "avoid_warnings=${DISABLE_UNDERVOLT_WARNINGS}" >> "${BOOT_DIR}/config.txt" | |
264 | fi |
|
266 | fi | |
265 |
|
267 | |||
266 | # Install kernel modules blacklist |
|
268 | # Install kernel modules blacklist | |
267 | mkdir -p "${ETC_DIR}/modprobe.d/" |
|
269 | mkdir -p "${ETC_DIR}/modprobe.d/" | |
268 | install_readonly files/modules/raspi-blacklist.conf "${ETC_DIR}/modprobe.d/raspi-blacklist.conf" |
|
270 | install_readonly files/modules/raspi-blacklist.conf "${ETC_DIR}/modprobe.d/raspi-blacklist.conf" | |
269 |
|
271 | |||
270 | # Install sysctl.d configuration files |
|
272 | # Install sysctl.d configuration files | |
271 | install_readonly files/sysctl.d/81-rpi-vm.conf "${ETC_DIR}/sysctl.d/81-rpi-vm.conf" |
|
273 | install_readonly files/sysctl.d/81-rpi-vm.conf "${ETC_DIR}/sysctl.d/81-rpi-vm.conf" |
@@ -1,862 +1,867 | |||||
1 | #!/bin/sh |
|
1 | #!/bin/sh | |
2 | ######################################################################## |
|
2 | ######################################################################## | |
3 | # rpi23-gen-image.sh 2015-2017 |
|
3 | # rpi23-gen-image.sh 2015-2017 | |
4 | # |
|
4 | # | |
5 | # Advanced Debian "stretch" and "buster" bootstrap script for Raspberry Pi |
|
5 | # Advanced Debian "stretch" and "buster" bootstrap script for Raspberry Pi | |
6 | # |
|
6 | # | |
7 | # This program is free software; you can redistribute it and/or |
|
7 | # This program is free software; you can redistribute it and/or | |
8 | # modify it under the terms of the GNU General Public License |
|
8 | # modify it under the terms of the GNU General Public License | |
9 | # as published by the Free Software Foundation; either version 2 |
|
9 | # as published by the Free Software Foundation; either version 2 | |
10 | # of the License, or (at your option) any later version. |
|
10 | # of the License, or (at your option) any later version. | |
11 | # |
|
11 | # | |
12 | # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu> |
|
12 | # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu> | |
13 | # |
|
13 | # | |
14 | # Big thanks for patches and enhancements by 20+ github contributors! |
|
14 | # Big thanks for patches and enhancements by 20+ github contributors! | |
15 | ######################################################################## |
|
15 | ######################################################################## | |
16 |
|
16 | |||
17 | # Are we running as root? |
|
17 | # Are we running as root? | |
18 | if [ "$(id -u)" -ne "0" ] ; then |
|
18 | if [ "$(id -u)" -ne "0" ] ; then | |
19 | echo "error: this script must be executed with root privileges!" |
|
19 | echo "error: this script must be executed with root privileges!" | |
20 | exit 1 |
|
20 | exit 1 | |
21 | fi |
|
21 | fi | |
22 |
|
22 | |||
23 | # Check if ./functions.sh script exists |
|
23 | # Check if ./functions.sh script exists | |
24 | if [ ! -r "./functions.sh" ] ; then |
|
24 | if [ ! -r "./functions.sh" ] ; then | |
25 | echo "error: './functions.sh' required script not found!" |
|
25 | echo "error: './functions.sh' required script not found!" | |
26 | exit 1 |
|
26 | exit 1 | |
27 | fi |
|
27 | fi | |
28 |
|
28 | |||
29 | # Load utility functions |
|
29 | # Load utility functions | |
30 | . ./functions.sh |
|
30 | . ./functions.sh | |
31 |
|
31 | |||
32 | # Load parameters from configuration template file |
|
32 | # Load parameters from configuration template file | |
33 | if [ -n "$CONFIG_TEMPLATE" ] ; then |
|
33 | if [ -n "$CONFIG_TEMPLATE" ] ; then | |
34 | use_template |
|
34 | use_template | |
35 | fi |
|
35 | fi | |
36 |
|
36 | |||
37 | # Introduce settings |
|
37 | # Introduce settings | |
38 | set -e |
|
38 | set -e | |
39 | echo -n -e "\n#\n# RPi 0/1/2/3 Bootstrap Settings\n#\n" |
|
39 | echo -n -e "\n#\n# RPi 0/1/2/3 Bootstrap Settings\n#\n" | |
40 | set -x |
|
40 | set -x | |
41 |
|
41 | |||
42 | # Raspberry Pi model configuration |
|
42 | # Raspberry Pi model configuration | |
43 | RPI_MODEL=${RPI_MODEL:=2} |
|
43 | RPI_MODEL=${RPI_MODEL:=2} | |
44 |
|
44 | |||
45 | # Debian release |
|
45 | # Debian release | |
46 | RELEASE=${RELEASE:=buster} |
|
46 | RELEASE=${RELEASE:=buster} | |
47 |
|
47 | |||
48 | # Kernel Branch |
|
48 | # Kernel Branch | |
49 | KERNEL_BRANCH=${KERNEL_BRANCH:=""} |
|
49 | KERNEL_BRANCH=${KERNEL_BRANCH:=""} | |
50 |
|
50 | |||
51 | # URLs |
|
51 | # URLs | |
52 | KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux} |
|
52 | KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux} | |
53 | FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot} |
|
53 | FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot} | |
54 | WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm} |
|
54 | WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm} | |
55 | COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian} |
|
55 | COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian} | |
56 | FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git} |
|
56 | FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git} | |
57 | UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git} |
|
57 | UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git} | |
58 | VIDEOCORE_URL=${VIDEOCORE_URL:=https://github.com/raspberrypi/userland} |
|
58 | VIDEOCORE_URL=${VIDEOCORE_URL:=https://github.com/raspberrypi/userland} | |
59 | BLUETOOTH_URL=${BLUETOOTH_URL:=https://github.com/RPi-Distro/pi-bluetooth.git} |
|
59 | BLUETOOTH_URL=${BLUETOOTH_URL:=https://github.com/RPi-Distro/pi-bluetooth.git} | |
60 | NEXMON_URL=${NEXMON_URL:=https://github.com/seemoo-lab/nexmon.git} |
|
60 | NEXMON_URL=${NEXMON_URL:=https://github.com/seemoo-lab/nexmon.git} | |
61 | SYSTEMDSWAP_URL=${SYSTEMDSWAP_URL:=https://github.com/Nefelim4ag/systemd-swap.git} |
|
61 | SYSTEMDSWAP_URL=${SYSTEMDSWAP_URL:=https://github.com/Nefelim4ag/systemd-swap.git} | |
62 |
|
62 | |||
63 | # Kernel deb packages for 32bit kernel |
|
63 | # Kernel deb packages for 32bit kernel | |
64 | RPI_32_KERNEL_URL=${RPI_32_KERNEL_URL:=https://github.com/hypriot/rpi-kernel/releases/download/v4.14.34/raspberrypi-kernel_20180422-141901_armhf.deb} |
|
64 | RPI_32_KERNEL_URL=${RPI_32_KERNEL_URL:=https://github.com/hypriot/rpi-kernel/releases/download/v4.14.34/raspberrypi-kernel_20180422-141901_armhf.deb} | |
65 | RPI_32_KERNELHEADER_URL=${RPI_32_KERNELHEADER_URL:=https://github.com/hypriot/rpi-kernel/releases/download/v4.14.34/raspberrypi-kernel-headers_20180422-141901_armhf.deb} |
|
65 | RPI_32_KERNELHEADER_URL=${RPI_32_KERNELHEADER_URL:=https://github.com/hypriot/rpi-kernel/releases/download/v4.14.34/raspberrypi-kernel-headers_20180422-141901_armhf.deb} | |
66 | # Kernel has KVM and zswap enabled - use if KERNEL_* parameters and precompiled kernel are used |
|
66 | # Kernel has KVM and zswap enabled - use if KERNEL_* parameters and precompiled kernel are used | |
67 | RPI3_64_BIS_KERNEL_URL=${RPI3_64_BIS_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel-bis/releases/download/4.14.80.20181113/bcmrpi3-kernel-bis-4.14.80.20181113.tar.xz} |
|
67 | RPI3_64_BIS_KERNEL_URL=${RPI3_64_BIS_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel-bis/releases/download/4.14.80.20181113/bcmrpi3-kernel-bis-4.14.80.20181113.tar.xz} | |
68 | # Default precompiled 64bit kernel |
|
68 | # Default precompiled 64bit kernel | |
69 | RPI3_64_DEF_KERNEL_URL=${RPI3_64_DEF_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel/releases/download/4.14.80.20181113/bcmrpi3-kernel-4.14.80.20181113.tar.xz} |
|
69 | RPI3_64_DEF_KERNEL_URL=${RPI3_64_DEF_KERNEL_URL:=https://github.com/sakaki-/bcmrpi3-kernel/releases/download/4.14.80.20181113/bcmrpi3-kernel-4.14.80.20181113.tar.xz} | |
70 | # Generic |
|
70 | # Generic | |
71 | RPI3_64_KERNEL_URL=${RPI3_64_KERNEL_URL:=$RPI3_64_DEF_KERNEL_URL} |
|
71 | RPI3_64_KERNEL_URL=${RPI3_64_KERNEL_URL:=$RPI3_64_DEF_KERNEL_URL} | |
72 |
|
72 | |||
73 | # Build directories |
|
73 | # Build directories | |
74 | WORKDIR=$(pwd) |
|
74 | WORKDIR=$(pwd) | |
75 | BASEDIR=${BASEDIR:=${WORKDIR}/images/${RELEASE}} |
|
75 | BASEDIR=${BASEDIR:=${WORKDIR}/images/${RELEASE}} | |
76 | BUILDDIR="${BASEDIR}/build" |
|
76 | BUILDDIR="${BASEDIR}/build" | |
77 |
|
77 | |||
78 | # Chroot directories |
|
78 | # Chroot directories | |
79 | R="${BUILDDIR}/chroot" |
|
79 | R="${BUILDDIR}/chroot" | |
80 | ETC_DIR="${R}/etc" |
|
80 | ETC_DIR="${R}/etc" | |
81 | LIB_DIR="${R}/lib" |
|
81 | LIB_DIR="${R}/lib" | |
82 | BOOT_DIR="${R}/boot/firmware" |
|
82 | BOOT_DIR="${R}/boot/firmware" | |
83 | KERNEL_DIR="${R}/usr/src/linux" |
|
83 | KERNEL_DIR="${R}/usr/src/linux" | |
84 | WLAN_FIRMWARE_DIR="${LIB_DIR}/firmware/brcm" |
|
84 | WLAN_FIRMWARE_DIR="${LIB_DIR}/firmware/brcm" | |
85 | BLUETOOTH_FIRMWARE_DIR="${ETC_DIR}/firmware/bt" |
|
85 | BLUETOOTH_FIRMWARE_DIR="${ETC_DIR}/firmware/bt" | |
86 |
|
86 | |||
87 | # Firmware directory: Blank if download from github |
|
87 | # Firmware directory: Blank if download from github | |
88 | RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""} |
|
88 | RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""} | |
89 |
|
89 | |||
90 | # General settings |
|
90 | # General settings | |
91 | SET_ARCH=${SET_ARCH:=32} |
|
91 | SET_ARCH=${SET_ARCH:=32} | |
92 | HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}} |
|
92 | HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}} | |
93 | PASSWORD=${PASSWORD:=raspberry} |
|
93 | PASSWORD=${PASSWORD:=raspberry} | |
94 | USER_PASSWORD=${USER_PASSWORD:=raspberry} |
|
94 | USER_PASSWORD=${USER_PASSWORD:=raspberry} | |
95 | DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"} |
|
95 | DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"} | |
96 | TIMEZONE=${TIMEZONE:="Europe/Berlin"} |
|
96 | TIMEZONE=${TIMEZONE:="Europe/Berlin"} | |
97 | EXPANDROOT=${EXPANDROOT:=true} |
|
97 | EXPANDROOT=${EXPANDROOT:=true} | |
98 |
|
98 | |||
99 | # Keyboard settings |
|
99 | # Keyboard settings | |
100 | XKB_MODEL=${XKB_MODEL:=""} |
|
100 | XKB_MODEL=${XKB_MODEL:=""} | |
101 | XKB_LAYOUT=${XKB_LAYOUT:=""} |
|
101 | XKB_LAYOUT=${XKB_LAYOUT:=""} | |
102 | XKB_VARIANT=${XKB_VARIANT:=""} |
|
102 | XKB_VARIANT=${XKB_VARIANT:=""} | |
103 | XKB_OPTIONS=${XKB_OPTIONS:=""} |
|
103 | XKB_OPTIONS=${XKB_OPTIONS:=""} | |
104 |
|
104 | |||
105 | # Network settings (DHCP) |
|
105 | # Network settings (DHCP) | |
106 | ENABLE_DHCP=${ENABLE_DHCP:=true} |
|
106 | ENABLE_DHCP=${ENABLE_DHCP:=true} | |
107 |
|
107 | |||
108 | # Network settings (static) |
|
108 | # Network settings (static) | |
109 | NET_ADDRESS=${NET_ADDRESS:=""} |
|
109 | NET_ADDRESS=${NET_ADDRESS:=""} | |
110 | NET_GATEWAY=${NET_GATEWAY:=""} |
|
110 | NET_GATEWAY=${NET_GATEWAY:=""} | |
111 | NET_DNS_1=${NET_DNS_1:=""} |
|
111 | NET_DNS_1=${NET_DNS_1:=""} | |
112 | NET_DNS_2=${NET_DNS_2:=""} |
|
112 | NET_DNS_2=${NET_DNS_2:=""} | |
113 | NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""} |
|
113 | NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""} | |
114 | NET_NTP_1=${NET_NTP_1:=""} |
|
114 | NET_NTP_1=${NET_NTP_1:=""} | |
115 | NET_NTP_2=${NET_NTP_2:=""} |
|
115 | NET_NTP_2=${NET_NTP_2:=""} | |
116 |
|
116 | |||
117 | # APT settings |
|
117 | # APT settings | |
118 | APT_PROXY=${APT_PROXY:=""} |
|
118 | APT_PROXY=${APT_PROXY:=""} | |
119 | APT_SERVER=${APT_SERVER:="ftp.debian.org"} |
|
119 | APT_SERVER=${APT_SERVER:="ftp.debian.org"} | |
120 |
|
120 | |||
121 | # Feature settings |
|
121 | # Feature settings | |
122 | ENABLE_PRINTK=${ENABLE_PRINTK:=false} |
|
122 | ENABLE_PRINTK=${ENABLE_PRINTK:=false} | |
123 | ENABLE_BLUETOOTH=${ENABLE_BLUETOOTH:=false} |
|
123 | ENABLE_BLUETOOTH=${ENABLE_BLUETOOTH:=false} | |
124 | ENABLE_MINIUART_OVERLAY=${ENABLE_MINIUART_OVERLAY:=false} |
|
124 | ENABLE_MINIUART_OVERLAY=${ENABLE_MINIUART_OVERLAY:=false} | |
125 | ENABLE_CONSOLE=${ENABLE_CONSOLE:=true} |
|
125 | ENABLE_CONSOLE=${ENABLE_CONSOLE:=true} | |
126 | ENABLE_I2C=${ENABLE_I2C:=false} |
|
126 | ENABLE_I2C=${ENABLE_I2C:=false} | |
127 | ENABLE_SPI=${ENABLE_SPI:=false} |
|
127 | ENABLE_SPI=${ENABLE_SPI:=false} | |
128 | ENABLE_IPV6=${ENABLE_IPV6:=true} |
|
128 | ENABLE_IPV6=${ENABLE_IPV6:=true} | |
129 | ENABLE_SSHD=${ENABLE_SSHD:=true} |
|
129 | ENABLE_SSHD=${ENABLE_SSHD:=true} | |
130 | ENABLE_NONFREE=${ENABLE_NONFREE:=false} |
|
130 | ENABLE_NONFREE=${ENABLE_NONFREE:=false} | |
131 | ENABLE_WIRELESS=${ENABLE_WIRELESS:=false} |
|
131 | ENABLE_WIRELESS=${ENABLE_WIRELESS:=false} | |
132 | ENABLE_SOUND=${ENABLE_SOUND:=true} |
|
132 | ENABLE_SOUND=${ENABLE_SOUND:=true} | |
133 | ENABLE_DBUS=${ENABLE_DBUS:=true} |
|
133 | ENABLE_DBUS=${ENABLE_DBUS:=true} | |
134 | ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true} |
|
134 | ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true} | |
135 | ENABLE_MINGPU=${ENABLE_MINGPU:=false} |
|
135 | ENABLE_MINGPU=${ENABLE_MINGPU:=false} | |
136 | ENABLE_XORG=${ENABLE_XORG:=false} |
|
136 | ENABLE_XORG=${ENABLE_XORG:=false} | |
137 | ENABLE_WM=${ENABLE_WM:=""} |
|
137 | ENABLE_WM=${ENABLE_WM:=""} | |
138 | ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true} |
|
138 | ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true} | |
139 | ENABLE_USER=${ENABLE_USER:=true} |
|
139 | ENABLE_USER=${ENABLE_USER:=true} | |
140 | USER_NAME=${USER_NAME:="pi"} |
|
140 | USER_NAME=${USER_NAME:="pi"} | |
141 | ENABLE_ROOT=${ENABLE_ROOT:=false} |
|
141 | ENABLE_ROOT=${ENABLE_ROOT:=false} | |
142 | ENABLE_QEMU=${ENABLE_QEMU:=false} |
|
142 | ENABLE_QEMU=${ENABLE_QEMU:=false} | |
143 | ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false} |
|
143 | ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false} | |
144 |
|
144 | |||
145 | # SSH settings |
|
145 | # SSH settings | |
146 | SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false} |
|
146 | SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false} | |
147 | SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false} |
|
147 | SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false} | |
148 | SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false} |
|
148 | SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false} | |
149 | SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""} |
|
149 | SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""} | |
150 | SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""} |
|
150 | SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""} | |
151 |
|
151 | |||
152 | # Advanced settings |
|
152 | # Advanced settings | |
153 | ENABLE_SYSTEMDSWAP=${ENABLE_MINBASE:=false} |
|
153 | ENABLE_SYSTEMDSWAP=${ENABLE_MINBASE:=false} | |
154 | ENABLE_MINBASE=${ENABLE_MINBASE:=false} |
|
154 | ENABLE_MINBASE=${ENABLE_MINBASE:=false} | |
155 | ENABLE_REDUCE=${ENABLE_REDUCE:=false} |
|
155 | ENABLE_REDUCE=${ENABLE_REDUCE:=false} | |
156 | ENABLE_UBOOT=${ENABLE_UBOOT:=false} |
|
156 | ENABLE_UBOOT=${ENABLE_UBOOT:=false} | |
157 | UBOOTSRC_DIR=${UBOOTSRC_DIR:=""} |
|
157 | UBOOTSRC_DIR=${UBOOTSRC_DIR:=""} | |
158 | ENABLE_UBOOTUSB=${ENABLE_UBOOTUSB=false} |
|
158 | ENABLE_UBOOTUSB=${ENABLE_UBOOTUSB=false} | |
159 | ENABLE_FBTURBO=${ENABLE_FBTURBO:=false} |
|
159 | ENABLE_FBTURBO=${ENABLE_FBTURBO:=false} | |
160 | ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=false} |
|
160 | ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=false} | |
161 | ENABLE_NEXMON=${ENABLE_NEXMON:=false} |
|
161 | ENABLE_NEXMON=${ENABLE_NEXMON:=false} | |
162 | VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""} |
|
162 | VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""} | |
163 | FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""} |
|
163 | FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""} | |
164 | NEXMONSRC_DIR=${NEXMONSRC_DIR:=""} |
|
164 | NEXMONSRC_DIR=${NEXMONSRC_DIR:=""} | |
165 | ENABLE_HARDNET=${ENABLE_HARDNET:=false} |
|
165 | ENABLE_HARDNET=${ENABLE_HARDNET:=false} | |
166 | ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} |
|
166 | ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} | |
167 | ENABLE_SPLITFS=${ENABLE_SPLITFS:=false} |
|
167 | ENABLE_SPLITFS=${ENABLE_SPLITFS:=false} | |
168 | ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false} |
|
168 | ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false} | |
169 | ENABLE_IFNAMES=${ENABLE_IFNAMES:=true} |
|
169 | ENABLE_IFNAMES=${ENABLE_IFNAMES:=true} | |
170 | DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=} |
|
170 | DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=} | |
171 |
|
171 | |||
172 | # Kernel compilation settings |
|
172 | # Kernel compilation settings | |
173 | BUILD_KERNEL=${BUILD_KERNEL:=true} |
|
173 | BUILD_KERNEL=${BUILD_KERNEL:=true} | |
174 | KERNEL_REDUCE=${KERNEL_REDUCE:=false} |
|
174 | KERNEL_REDUCE=${KERNEL_REDUCE:=false} | |
175 | KERNEL_THREADS=${KERNEL_THREADS:=1} |
|
175 | KERNEL_THREADS=${KERNEL_THREADS:=1} | |
176 | KERNEL_HEADERS=${KERNEL_HEADERS:=true} |
|
176 | KERNEL_HEADERS=${KERNEL_HEADERS:=true} | |
177 | KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false} |
|
177 | KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false} | |
178 | KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true} |
|
178 | KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true} | |
179 | KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false} |
|
179 | KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false} | |
180 | KERNEL_CCACHE=${KERNEL_CCACHE:=false} |
|
180 | KERNEL_CCACHE=${KERNEL_CCACHE:=false} | |
181 | KERNEL_ZSWAP=${KERNEL_ZSWAP:=false} |
|
181 | KERNEL_ZSWAP=${KERNEL_ZSWAP:=false} | |
182 | KERNEL_VIRT=${KERNEL_VIRT:=false} |
|
182 | KERNEL_VIRT=${KERNEL_VIRT:=false} | |
183 | KERNEL_BPF=${KERNEL_BPF:=false} |
|
183 | KERNEL_BPF=${KERNEL_BPF:=false} | |
184 | KERNEL_DEFAULT_GOV=${KERNEL_DEFAULT_GOV:=POWERSAVE} |
|
184 | KERNEL_DEFAULT_GOV=${KERNEL_DEFAULT_GOV:=POWERSAVE} | |
185 |
|
185 | |||
186 | # Kernel compilation from source directory settings |
|
186 | # Kernel compilation from source directory settings | |
187 | KERNELSRC_DIR=${KERNELSRC_DIR:=""} |
|
187 | KERNELSRC_DIR=${KERNELSRC_DIR:=""} | |
188 | KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false} |
|
188 | KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false} | |
189 | KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true} |
|
189 | KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true} | |
190 | KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false} |
|
190 | KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false} | |
191 |
|
191 | |||
192 | # Reduce disk usage settings |
|
192 | # Reduce disk usage settings | |
193 | REDUCE_APT=${REDUCE_APT:=true} |
|
193 | REDUCE_APT=${REDUCE_APT:=true} | |
194 | REDUCE_DOC=${REDUCE_DOC:=true} |
|
194 | REDUCE_DOC=${REDUCE_DOC:=true} | |
195 | REDUCE_MAN=${REDUCE_MAN:=true} |
|
195 | REDUCE_MAN=${REDUCE_MAN:=true} | |
196 | REDUCE_VIM=${REDUCE_VIM:=false} |
|
196 | REDUCE_VIM=${REDUCE_VIM:=false} | |
197 | REDUCE_BASH=${REDUCE_BASH:=false} |
|
197 | REDUCE_BASH=${REDUCE_BASH:=false} | |
198 | REDUCE_HWDB=${REDUCE_HWDB:=true} |
|
198 | REDUCE_HWDB=${REDUCE_HWDB:=true} | |
199 | REDUCE_SSHD=${REDUCE_SSHD:=true} |
|
199 | REDUCE_SSHD=${REDUCE_SSHD:=true} | |
200 | REDUCE_LOCALE=${REDUCE_LOCALE:=true} |
|
200 | REDUCE_LOCALE=${REDUCE_LOCALE:=true} | |
201 |
|
201 | |||
202 | # Encrypted filesystem settings |
|
202 | # Encrypted filesystem settings | |
203 | ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false} |
|
203 | ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false} | |
204 | CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""} |
|
204 | CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""} | |
205 | CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"} |
|
205 | CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"} | |
206 | CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"} |
|
206 | CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"} | |
207 | CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512} |
|
207 | CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512} | |
208 | #Dropbear-initramfs supports unlocking encrypted filesystem via SSH on bootup |
|
208 | #Dropbear-initramfs supports unlocking encrypted filesystem via SSH on bootup | |
209 | CRYPTFS_DROPBEAR=${CRYPTFS_DROPBEAR:=false} |
|
209 | CRYPTFS_DROPBEAR=${CRYPTFS_DROPBEAR:=false} | |
210 | #Provide your own Dropbear Public RSA-OpenSSH Key otherwise it will be generated |
|
210 | #Provide your own Dropbear Public RSA-OpenSSH Key otherwise it will be generated | |
211 | CRYPTFS_DROPBEAR_PUBKEY=${CRYPTFS_DROPBEAR_PUBKEY:=""} |
|
211 | CRYPTFS_DROPBEAR_PUBKEY=${CRYPTFS_DROPBEAR_PUBKEY:=""} | |
212 |
|
212 | |||
213 | # Chroot scripts directory |
|
213 | # Chroot scripts directory | |
214 | CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""} |
|
214 | CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""} | |
215 |
|
215 | |||
216 | # Packages required in the chroot build environment |
|
216 | # Packages required in the chroot build environment | |
217 | APT_INCLUDES=${APT_INCLUDES:=""} |
|
217 | APT_INCLUDES=${APT_INCLUDES:=""} | |
218 | APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup,libnss-systemd" |
|
218 | APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup,libnss-systemd" | |
219 |
|
219 | |||
220 | #Packages to exclude from chroot build environment |
|
220 | #Packages to exclude from chroot build environment | |
221 | APT_EXCLUDES=${APT_EXCLUDES:=""} |
|
221 | APT_EXCLUDES=${APT_EXCLUDES:=""} | |
222 |
|
222 | |||
223 | # Packages required for bootstrapping |
|
223 | # Packages required for bootstrapping | |
224 | REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo netselect-apt" |
|
224 | REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo netselect-apt" | |
225 | MISSING_PACKAGES="" |
|
225 | MISSING_PACKAGES="" | |
226 |
|
226 | |||
227 | # Packages installed for c/c++ build environment in chroot (keep empty) |
|
227 | # Packages installed for c/c++ build environment in chroot (keep empty) | |
228 | COMPILER_PACKAGES="" |
|
228 | COMPILER_PACKAGES="" | |
229 |
|
229 | |||
230 | #Check if apt-cacher-ng has port 3142 open and set APT_PROXY |
|
230 | #Check if apt-cacher-ng has port 3142 open and set APT_PROXY | |
231 | APT_CACHER_RUNNING=$(lsof -i :3142 | cut -d ' ' -f3 | uniq | sed '/^\s*$/d') |
|
231 | APT_CACHER_RUNNING=$(lsof -i :3142 | cut -d ' ' -f3 | uniq | sed '/^\s*$/d') | |
232 | if [ "${APT_CACHER_RUNNING}" = "apt-cacher-ng" ] ; then |
|
232 | if [ "${APT_CACHER_RUNNING}" = "apt-cacher-ng" ] ; then | |
233 | APT_PROXY=http://127.0.0.1:3142/ |
|
233 | APT_PROXY=http://127.0.0.1:3142/ | |
234 | fi |
|
234 | fi | |
235 |
|
235 | |||
236 | #netselect-apt does not know buster yet |
|
236 | #netselect-apt does not know buster yet | |
237 | if [ "$RELEASE" = "buster" ] ; then |
|
237 | if [ "$RELEASE" = "buster" ] ; then | |
238 | RLS=testing |
|
238 | RLS=testing | |
239 | else |
|
239 | else | |
240 | RLS="$RELEASE" |
|
240 | RLS="$RELEASE" | |
241 | fi |
|
241 | fi | |
242 |
|
242 | |||
243 | if [ -f "$(pwd)/files/apt/sources.list" ] ; then |
|
243 | if [ -f "$(pwd)/files/apt/sources.list" ] ; then | |
244 | rm "$(pwd)/files/apt/sources.list" |
|
244 | rm "$(pwd)/files/apt/sources.list" | |
245 | fi |
|
245 | fi | |
246 |
|
246 | |||
247 | if [ "$ENABLE_NONFREE" = true ] ; then |
|
247 | if [ "$ENABLE_NONFREE" = true ] ; then | |
248 | netselect-apt --arch "$RELEASE_ARCH" -t 3 --sources --nonfree --outfile "$(pwd)/files/apt/sources.list" -d "$RLS" |
|
248 | netselect-apt --arch "$RELEASE_ARCH" -t 3 --sources --nonfree --outfile "$(pwd)/files/apt/sources.list" -d "$RLS" | |
249 | else |
|
249 | else | |
250 | netselect-apt --arch "$RELEASE_ARCH" -t 3 --sources --outfile "$(pwd)/files/apt/sources.list" -d "$RLS" |
|
250 | netselect-apt --arch "$RELEASE_ARCH" -t 3 --sources --outfile "$(pwd)/files/apt/sources.list" -d "$RLS" | |
251 | fi |
|
251 | fi | |
252 |
|
252 | |||
253 | #sed and cut the result string so we can use it as APT_SERVER |
|
253 | #sed and cut the result string so we can use it as APT_SERVER | |
254 | APT_SERVER=$(grep -m 1 http files/apt/sources.list | sed "s|http://| |g" | cut -d ' ' -f 3 | sed 's|/$|''|') |
|
254 | APT_SERVER=$(grep -m 1 http files/apt/sources.list | sed "s|http://| |g" | cut -d ' ' -f 3 | sed 's|/$|''|') | |
255 |
|
255 | |||
256 | #make script easier and more stable to use with convenient setup switch. Just setup SET_ARCH and RPI_MODEL and your good to go! |
|
256 | #make script easier and more stable to use with convenient setup switch. Just setup SET_ARCH and RPI_MODEL and your good to go! | |
257 | if [ -n "$SET_ARCH" ] ; then |
|
257 | if [ -n "$SET_ARCH" ] ; then | |
258 | # 64-bit configuration |
|
258 | # 64-bit configuration | |
259 | if [ "$SET_ARCH" = 64 ] ; then |
|
259 | if [ "$SET_ARCH" = 64 ] ; then | |
260 | # General 64-bit depended settings |
|
260 | # General 64-bit depended settings | |
261 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static} |
|
261 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static} | |
262 | KERNEL_ARCH=${KERNEL_ARCH:=arm64} |
|
262 | KERNEL_ARCH=${KERNEL_ARCH:=arm64} | |
263 | KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"} |
|
263 | KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"} | |
264 |
|
264 | |||
265 | # Raspberry Pi model specific settings |
|
265 | # Raspberry Pi model specific settings | |
266 | if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then |
|
266 | if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then | |
267 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64" |
|
267 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64" | |
268 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig} |
|
268 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig} | |
269 | RELEASE_ARCH=${RELEASE_ARCH:=arm64} |
|
269 | RELEASE_ARCH=${RELEASE_ARCH:=arm64} | |
270 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img} |
|
270 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img} | |
271 | CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-} |
|
271 | CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-} | |
272 | else |
|
272 | else | |
273 | echo "error: Only Raspberry PI 3 and 3B+ support 64-bit" |
|
273 | echo "error: Only Raspberry PI 3 and 3B+ support 64-bit" | |
274 | exit 1 |
|
274 | exit 1 | |
275 | fi |
|
275 | fi | |
276 | fi |
|
276 | fi | |
277 |
|
277 | |||
278 | # 32-bit configuration |
|
278 | # 32-bit configuration | |
279 | if [ "$SET_ARCH" = 32 ] ; then |
|
279 | if [ "$SET_ARCH" = 32 ] ; then | |
280 | # General 32-bit dependend settings |
|
280 | # General 32-bit dependend settings | |
281 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static} |
|
281 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static} | |
282 | KERNEL_ARCH=${KERNEL_ARCH:=arm} |
|
282 | KERNEL_ARCH=${KERNEL_ARCH:=arm} | |
283 | KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"} |
|
283 | KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"} | |
284 |
|
284 | |||
285 | # Raspberry Pi model specific settings |
|
285 | # Raspberry Pi model specific settings | |
286 | if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then |
|
286 | if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then | |
287 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel" |
|
287 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel" | |
288 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig} |
|
288 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig} | |
289 | RELEASE_ARCH=${RELEASE_ARCH:=armel} |
|
289 | RELEASE_ARCH=${RELEASE_ARCH:=armel} | |
290 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img} |
|
290 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img} | |
291 | CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-} |
|
291 | CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-} | |
292 | fi |
|
292 | fi | |
293 |
|
293 | |||
294 | # Raspberry Pi model specific settings |
|
294 | # Raspberry Pi model specific settings | |
295 | if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then |
|
295 | if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then | |
296 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" |
|
296 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" | |
297 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} |
|
297 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} | |
298 | RELEASE_ARCH=${RELEASE_ARCH:=armhf} |
|
298 | RELEASE_ARCH=${RELEASE_ARCH:=armhf} | |
299 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img} |
|
299 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img} | |
300 | CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-} |
|
300 | CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-} | |
301 | fi |
|
301 | fi | |
302 | fi |
|
302 | fi | |
303 | #SET_ARCH not set |
|
303 | #SET_ARCH not set | |
304 | else |
|
304 | else | |
305 | echo "error: Please set '32' or '64' as value for SET_ARCH" |
|
305 | echo "error: Please set '32' or '64' as value for SET_ARCH" | |
306 | exit 1 |
|
306 | exit 1 | |
307 | fi |
|
307 | fi | |
308 | # Device specific configuration and U-Boot configuration |
|
308 | # Device specific configuration and U-Boot configuration | |
309 | case "$RPI_MODEL" in |
|
309 | case "$RPI_MODEL" in | |
310 | 0) |
|
310 | 0) | |
311 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb} |
|
311 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb} | |
312 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} |
|
312 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} | |
313 | ;; |
|
313 | ;; | |
314 | 1) |
|
314 | 1) | |
315 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb} |
|
315 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb} | |
316 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} |
|
316 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} | |
317 | ;; |
|
317 | ;; | |
318 | 1P) |
|
318 | 1P) | |
319 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb} |
|
319 | DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb} | |
320 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} |
|
320 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig} | |
321 | ;; |
|
321 | ;; | |
322 | 2) |
|
322 | 2) | |
323 | DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb} |
|
323 | DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb} | |
324 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig} |
|
324 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig} | |
325 | ;; |
|
325 | ;; | |
326 | 3) |
|
326 | 3) | |
327 | DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb} |
|
327 | DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb} | |
328 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig} |
|
328 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig} | |
329 | ;; |
|
329 | ;; | |
330 | 3P) |
|
330 | 3P) | |
331 | DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb} |
|
331 | DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb} | |
332 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig} |
|
332 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig} | |
333 | ;; |
|
333 | ;; | |
334 | *) |
|
334 | *) | |
335 | echo "error: Raspberry Pi model $RPI_MODEL is not supported!" |
|
335 | echo "error: Raspberry Pi model $RPI_MODEL is not supported!" | |
336 | exit 1 |
|
336 | exit 1 | |
337 | ;; |
|
337 | ;; | |
338 | esac |
|
338 | esac | |
339 |
|
339 | |||
340 | # Raspberry PI 0,3,3P with Bluetooth and Wifi onboard |
|
340 | # Raspberry PI 0,3,3P with Bluetooth and Wifi onboard | |
341 | if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then |
|
341 | if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then | |
342 | # Include bluetooth packages on supported boards |
|
342 | # Include bluetooth packages on supported boards | |
343 | if [ "$ENABLE_BLUETOOTH" = true ] && [ "$ENABLE_CONSOLE" = false ]; then |
|
343 | if [ "$ENABLE_BLUETOOTH" = true ] && [ "$ENABLE_CONSOLE" = false ]; then | |
344 | APT_INCLUDES="${APT_INCLUDES},bluetooth,bluez" |
|
344 | APT_INCLUDES="${APT_INCLUDES},bluetooth,bluez" | |
345 | fi |
|
345 | fi | |
346 | else # Raspberry PI 1,1P,2 without Wifi and bluetooth onboard |
|
346 | else # Raspberry PI 1,1P,2 without Wifi and bluetooth onboard | |
347 | # Check if the internal wireless interface is not supported by the RPi model |
|
347 | # Check if the internal wireless interface is not supported by the RPi model | |
348 | if [ "$ENABLE_WIRELESS" = true ] || [ "$ENABLE_BLUETOOTH" = true ]; then |
|
348 | if [ "$ENABLE_WIRELESS" = true ] || [ "$ENABLE_BLUETOOTH" = true ]; then | |
349 | echo "error: The selected Raspberry Pi model has no integrated interface for wireless or bluetooth" |
|
349 | echo "error: The selected Raspberry Pi model has no integrated interface for wireless or bluetooth" | |
350 | exit 1 |
|
350 | exit 1 | |
351 | fi |
|
351 | fi | |
352 | fi |
|
352 | fi | |
353 |
|
353 | |||
|
354 | if [ "$BUILD_KERNEL" = false ] && [ "$ENABLE_NEXMON" = true ]; then | |||
|
355 | echo "error: You have to compile kernel sources, if you want to enable nexmon" | |||
|
356 | exit 1 | |||
|
357 | fi | |||
|
358 | ||||
354 | # Prepare date string for default image file name |
|
359 | # Prepare date string for default image file name | |
355 | DATE="$(date +%Y-%m-%d)" |
|
360 | DATE="$(date +%Y-%m-%d)" | |
356 | if [ -z "$KERNEL_BRANCH" ] ; then |
|
361 | if [ -z "$KERNEL_BRANCH" ] ; then | |
357 | IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} |
|
362 | IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} | |
358 | else |
|
363 | else | |
359 | IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} |
|
364 | IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} | |
360 | fi |
|
365 | fi | |
361 |
|
366 | |||
362 | # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported |
|
367 | # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported | |
363 | if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then |
|
368 | if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then | |
364 | if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then |
|
369 | if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then | |
365 | echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported" |
|
370 | echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported" | |
366 | exit 1 |
|
371 | exit 1 | |
367 | fi |
|
372 | fi | |
368 | fi |
|
373 | fi | |
369 |
|
374 | |||
370 | set +x |
|
375 | set +x | |
371 |
|
376 | |||
372 | # Add cmake to compile videocore sources |
|
377 | # Add cmake to compile videocore sources | |
373 | if [ "$ENABLE_VIDEOCORE" = true ] ; then |
|
378 | if [ "$ENABLE_VIDEOCORE" = true ] ; then | |
374 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake" |
|
379 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake" | |
375 | fi |
|
380 | fi | |
376 |
|
381 | |||
377 | # Add deps for nexmon |
|
382 | # Add deps for nexmon | |
378 | if [ "$ENABLE_NEXMON" = true ] ; then |
|
383 | if [ "$ENABLE_NEXMON" = true ] ; then | |
379 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libgmp3-dev gawk qpdf bison flex make autoconf automake build-essential libtool" |
|
384 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libgmp3-dev gawk qpdf bison flex make autoconf automake build-essential libtool" | |
380 | fi |
|
385 | fi | |
381 |
|
386 | |||
382 | # Add libncurses5 to enable kernel menuconfig |
|
387 | # Add libncurses5 to enable kernel menuconfig | |
383 | if [ "$KERNEL_MENUCONFIG" = true ] ; then |
|
388 | if [ "$KERNEL_MENUCONFIG" = true ] ; then | |
384 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev" |
|
389 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev" | |
385 | fi |
|
390 | fi | |
386 |
|
391 | |||
387 | # Add ccache compiler cache for (faster) kernel cross (re)compilation |
|
392 | # Add ccache compiler cache for (faster) kernel cross (re)compilation | |
388 | if [ "$KERNEL_CCACHE" = true ] ; then |
|
393 | if [ "$KERNEL_CCACHE" = true ] ; then | |
389 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache" |
|
394 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache" | |
390 | fi |
|
395 | fi | |
391 |
|
396 | |||
392 | # Add cryptsetup package to enable filesystem encryption |
|
397 | # Add cryptsetup package to enable filesystem encryption | |
393 | if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then |
|
398 | if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then | |
394 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup" |
|
399 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup" | |
395 | APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup" |
|
400 | APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup" | |
396 |
|
401 | |||
397 | #If cryptfs,dropbear and initramfs are enabled include dropbear-initramfs package |
|
402 | #If cryptfs,dropbear and initramfs are enabled include dropbear-initramfs package | |
398 | if [ "$CRYPTFS_DROPBEAR" = true ] && [ "$ENABLE_INITRAMFS" = true ]; then |
|
403 | if [ "$CRYPTFS_DROPBEAR" = true ] && [ "$ENABLE_INITRAMFS" = true ]; then | |
399 | APT_INCLUDES="${APT_INCLUDES},dropbear-initramfs" |
|
404 | APT_INCLUDES="${APT_INCLUDES},dropbear-initramfs" | |
400 | fi |
|
405 | fi | |
401 |
|
406 | |||
402 | if [ -z "$CRYPTFS_PASSWORD" ] ; then |
|
407 | if [ -z "$CRYPTFS_PASSWORD" ] ; then | |
403 | echo "error: no password defined (CRYPTFS_PASSWORD)!" |
|
408 | echo "error: no password defined (CRYPTFS_PASSWORD)!" | |
404 | exit 1 |
|
409 | exit 1 | |
405 | fi |
|
410 | fi | |
406 | ENABLE_INITRAMFS=true |
|
411 | ENABLE_INITRAMFS=true | |
407 | fi |
|
412 | fi | |
408 |
|
413 | |||
409 | # Add initramfs generation tools |
|
414 | # Add initramfs generation tools | |
410 | if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then |
|
415 | if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then | |
411 | APT_INCLUDES="${APT_INCLUDES},initramfs-tools" |
|
416 | APT_INCLUDES="${APT_INCLUDES},initramfs-tools" | |
412 | fi |
|
417 | fi | |
413 |
|
418 | |||
414 | # Add device-tree-compiler required for building the U-Boot bootloader |
|
419 | # Add device-tree-compiler required for building the U-Boot bootloader | |
415 | if [ "$ENABLE_UBOOT" = true ] ; then |
|
420 | if [ "$ENABLE_UBOOT" = true ] ; then | |
416 | APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc" |
|
421 | APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc" | |
417 | else |
|
422 | else | |
418 | if [ "$ENABLE_UBOOTUSB" = true ] ; then |
|
423 | if [ "$ENABLE_UBOOTUSB" = true ] ; then | |
419 | echo "error: Enabling UBOOTUSB requires u-boot to be enabled" |
|
424 | echo "error: Enabling UBOOTUSB requires u-boot to be enabled" | |
420 | exit 1 |
|
425 | exit 1 | |
421 | fi |
|
426 | fi | |
422 | fi |
|
427 | fi | |
423 |
|
428 | |||
424 | if [ "$ENABLE_BLUETOOTH" = true ] ; then |
|
429 | if [ "$ENABLE_BLUETOOTH" = true ] ; then | |
425 | if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then |
|
430 | if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then | |
426 | if [ "$ENABLE_CONSOLE" = false ] ; then |
|
431 | if [ "$ENABLE_CONSOLE" = false ] ; then | |
427 | APT_INCLUDES="${APT_INCLUDES},bluetooth,bluez" |
|
432 | APT_INCLUDES="${APT_INCLUDES},bluetooth,bluez" | |
428 | fi |
|
433 | fi | |
429 | fi |
|
434 | fi | |
430 | fi |
|
435 | fi | |
431 |
|
436 | |||
432 | # Check if root SSH (v2) public key file exists |
|
437 | # Check if root SSH (v2) public key file exists | |
433 | if [ -n "$SSH_ROOT_PUB_KEY" ] ; then |
|
438 | if [ -n "$SSH_ROOT_PUB_KEY" ] ; then | |
434 | if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then |
|
439 | if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then | |
435 | echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!" |
|
440 | echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!" | |
436 | exit 1 |
|
441 | exit 1 | |
437 | fi |
|
442 | fi | |
438 | fi |
|
443 | fi | |
439 |
|
444 | |||
440 | # Check if $USER_NAME SSH (v2) public key file exists |
|
445 | # Check if $USER_NAME SSH (v2) public key file exists | |
441 | if [ -n "$SSH_USER_PUB_KEY" ] ; then |
|
446 | if [ -n "$SSH_USER_PUB_KEY" ] ; then | |
442 | if [ ! -f "$SSH_USER_PUB_KEY" ] ; then |
|
447 | if [ ! -f "$SSH_USER_PUB_KEY" ] ; then | |
443 | echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!" |
|
448 | echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!" | |
444 | exit 1 |
|
449 | exit 1 | |
445 | fi |
|
450 | fi | |
446 | fi |
|
451 | fi | |
447 |
|
452 | |||
448 | # Check if all required packages are installed on the build system |
|
453 | # Check if all required packages are installed on the build system | |
449 | for package in $REQUIRED_PACKAGES ; do |
|
454 | for package in $REQUIRED_PACKAGES ; do | |
450 | if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then |
|
455 | if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then | |
451 | MISSING_PACKAGES="${MISSING_PACKAGES} $package" |
|
456 | MISSING_PACKAGES="${MISSING_PACKAGES} $package" | |
452 | fi |
|
457 | fi | |
453 | done |
|
458 | done | |
454 |
|
459 | |||
455 | # If there are missing packages ask confirmation for install, or exit |
|
460 | # If there are missing packages ask confirmation for install, or exit | |
456 | if [ -n "$MISSING_PACKAGES" ] ; then |
|
461 | if [ -n "$MISSING_PACKAGES" ] ; then | |
457 | echo "the following packages needed by this script are not installed:" |
|
462 | echo "the following packages needed by this script are not installed:" | |
458 | echo "$MISSING_PACKAGES" |
|
463 | echo "$MISSING_PACKAGES" | |
459 |
|
464 | |||
460 | printf "\ndo you want to install the missing packages right now? [y/n] " |
|
465 | printf "\ndo you want to install the missing packages right now? [y/n] " | |
461 | read -r confirm |
|
466 | read -r confirm | |
462 | [ "$confirm" != "y" ] && exit 1 |
|
467 | [ "$confirm" != "y" ] && exit 1 | |
463 |
|
468 | |||
464 | # Make sure all missing required packages are installed |
|
469 | # Make sure all missing required packages are installed | |
465 | apt-get -qq -y install `echo "${MISSING_PACKAGES}" | sed "s/ //"` |
|
470 | apt-get -qq -y install `echo "${MISSING_PACKAGES}" | sed "s/ //"` | |
466 | fi |
|
471 | fi | |
467 |
|
472 | |||
468 | # Check if ./bootstrap.d directory exists |
|
473 | # Check if ./bootstrap.d directory exists | |
469 | if [ ! -d "./bootstrap.d/" ] ; then |
|
474 | if [ ! -d "./bootstrap.d/" ] ; then | |
470 | echo "error: './bootstrap.d' required directory not found!" |
|
475 | echo "error: './bootstrap.d' required directory not found!" | |
471 | exit 1 |
|
476 | exit 1 | |
472 | fi |
|
477 | fi | |
473 |
|
478 | |||
474 | # Check if ./files directory exists |
|
479 | # Check if ./files directory exists | |
475 | if [ ! -d "./files/" ] ; then |
|
480 | if [ ! -d "./files/" ] ; then | |
476 | echo "error: './files' required directory not found!" |
|
481 | echo "error: './files' required directory not found!" | |
477 | exit 1 |
|
482 | exit 1 | |
478 | fi |
|
483 | fi | |
479 |
|
484 | |||
480 | # Check if specified KERNELSRC_DIR directory exists |
|
485 | # Check if specified KERNELSRC_DIR directory exists | |
481 | if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then |
|
486 | if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then | |
482 | echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!" |
|
487 | echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!" | |
483 | exit 1 |
|
488 | exit 1 | |
484 | fi |
|
489 | fi | |
485 |
|
490 | |||
486 | # Check if specified UBOOTSRC_DIR directory exists |
|
491 | # Check if specified UBOOTSRC_DIR directory exists | |
487 | if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then |
|
492 | if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then | |
488 | echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!" |
|
493 | echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!" | |
489 | exit 1 |
|
494 | exit 1 | |
490 | fi |
|
495 | fi | |
491 |
|
496 | |||
492 | # Check if specified VIDEOCORESRC_DIR directory exists |
|
497 | # Check if specified VIDEOCORESRC_DIR directory exists | |
493 | if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then |
|
498 | if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then | |
494 | echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!" |
|
499 | echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!" | |
495 | exit 1 |
|
500 | exit 1 | |
496 | fi |
|
501 | fi | |
497 |
|
502 | |||
498 | # Check if specified FBTURBOSRC_DIR directory exists |
|
503 | # Check if specified FBTURBOSRC_DIR directory exists | |
499 | if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then |
|
504 | if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then | |
500 | echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!" |
|
505 | echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!" | |
501 | exit 1 |
|
506 | exit 1 | |
502 | fi |
|
507 | fi | |
503 |
|
508 | |||
504 | # Check if specified NEXMONSRC_DIR directory exists |
|
509 | # Check if specified NEXMONSRC_DIR directory exists | |
505 | if [ -n "$NEXMONSRC_DIR" ] && [ ! -d "$NEXMONSRC_DIR" ] ; then |
|
510 | if [ -n "$NEXMONSRC_DIR" ] && [ ! -d "$NEXMONSRC_DIR" ] ; then | |
506 | echo "error: '${NEXMONSRC_DIR}' specified directory not found (NEXMONSRC_DIR)!" |
|
511 | echo "error: '${NEXMONSRC_DIR}' specified directory not found (NEXMONSRC_DIR)!" | |
507 | exit 1 |
|
512 | exit 1 | |
508 | fi |
|
513 | fi | |
509 |
|
514 | |||
510 | # Check if specified CHROOT_SCRIPTS directory exists |
|
515 | # Check if specified CHROOT_SCRIPTS directory exists | |
511 | if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then |
|
516 | if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then | |
512 | echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!" |
|
517 | echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!" | |
513 | exit 1 |
|
518 | exit 1 | |
514 | fi |
|
519 | fi | |
515 |
|
520 | |||
516 | # Check if specified device mapping already exists (will be used by cryptsetup) |
|
521 | # Check if specified device mapping already exists (will be used by cryptsetup) | |
517 | if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then |
|
522 | if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then | |
518 | echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding" |
|
523 | echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding" | |
519 | exit 1 |
|
524 | exit 1 | |
520 | fi |
|
525 | fi | |
521 |
|
526 | |||
522 | # Don't clobber an old build |
|
527 | # Don't clobber an old build | |
523 | if [ -e "$BUILDDIR" ] ; then |
|
528 | if [ -e "$BUILDDIR" ] ; then | |
524 | echo "error: directory ${BUILDDIR} already exists, not proceeding" |
|
529 | echo "error: directory ${BUILDDIR} already exists, not proceeding" | |
525 | exit 1 |
|
530 | exit 1 | |
526 | fi |
|
531 | fi | |
527 |
|
532 | |||
528 | # Setup chroot directory |
|
533 | # Setup chroot directory | |
529 | mkdir -p "${R}" |
|
534 | mkdir -p "${R}" | |
530 |
|
535 | |||
531 | # Check if build directory has enough of free disk space >512MB |
|
536 | # Check if build directory has enough of free disk space >512MB | |
532 | if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then |
|
537 | if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then | |
533 | echo "error: ${BUILDDIR} not enough space left to generate the output image!" |
|
538 | echo "error: ${BUILDDIR} not enough space left to generate the output image!" | |
534 | exit 1 |
|
539 | exit 1 | |
535 | fi |
|
540 | fi | |
536 |
|
541 | |||
537 | set -x |
|
542 | set -x | |
538 |
|
543 | |||
539 | # Call "cleanup" function on various signals and errors |
|
544 | # Call "cleanup" function on various signals and errors | |
540 | trap cleanup 0 1 2 3 6 |
|
545 | trap cleanup 0 1 2 3 6 | |
541 |
|
546 | |||
542 | # Add required packages for the minbase installation |
|
547 | # Add required packages for the minbase installation | |
543 | if [ "$ENABLE_MINBASE" = true ] ; then |
|
548 | if [ "$ENABLE_MINBASE" = true ] ; then | |
544 | APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown" |
|
549 | APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown" | |
545 | fi |
|
550 | fi | |
546 |
|
551 | |||
547 | # Add parted package, required to get partprobe utility |
|
552 | # Add parted package, required to get partprobe utility | |
548 | if [ "$EXPANDROOT" = true ] ; then |
|
553 | if [ "$EXPANDROOT" = true ] ; then | |
549 | APT_INCLUDES="${APT_INCLUDES},parted" |
|
554 | APT_INCLUDES="${APT_INCLUDES},parted" | |
550 | fi |
|
555 | fi | |
551 |
|
556 | |||
552 | # Add dbus package, recommended if using systemd |
|
557 | # Add dbus package, recommended if using systemd | |
553 | if [ "$ENABLE_DBUS" = true ] ; then |
|
558 | if [ "$ENABLE_DBUS" = true ] ; then | |
554 | APT_INCLUDES="${APT_INCLUDES},dbus" |
|
559 | APT_INCLUDES="${APT_INCLUDES},dbus" | |
555 | fi |
|
560 | fi | |
556 |
|
561 | |||
557 | # Add iptables IPv4/IPv6 package |
|
562 | # Add iptables IPv4/IPv6 package | |
558 | if [ "$ENABLE_IPTABLES" = true ] ; then |
|
563 | if [ "$ENABLE_IPTABLES" = true ] ; then | |
559 | APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent" |
|
564 | APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent" | |
560 | fi |
|
565 | fi | |
561 |
|
566 | |||
562 | # Add openssh server package |
|
567 | # Add openssh server package | |
563 | if [ "$ENABLE_SSHD" = true ] ; then |
|
568 | if [ "$ENABLE_SSHD" = true ] ; then | |
564 | APT_INCLUDES="${APT_INCLUDES},openssh-server" |
|
569 | APT_INCLUDES="${APT_INCLUDES},openssh-server" | |
565 | fi |
|
570 | fi | |
566 |
|
571 | |||
567 | # Add alsa-utils package |
|
572 | # Add alsa-utils package | |
568 | if [ "$ENABLE_SOUND" = true ] ; then |
|
573 | if [ "$ENABLE_SOUND" = true ] ; then | |
569 | APT_INCLUDES="${APT_INCLUDES},alsa-utils" |
|
574 | APT_INCLUDES="${APT_INCLUDES},alsa-utils" | |
570 | fi |
|
575 | fi | |
571 |
|
576 | |||
572 | # Add rng-tools package |
|
577 | # Add rng-tools package | |
573 | if [ "$ENABLE_HWRANDOM" = true ] ; then |
|
578 | if [ "$ENABLE_HWRANDOM" = true ] ; then | |
574 | APT_INCLUDES="${APT_INCLUDES},rng-tools" |
|
579 | APT_INCLUDES="${APT_INCLUDES},rng-tools" | |
575 | fi |
|
580 | fi | |
576 |
|
581 | |||
577 | # Add fbturbo video driver |
|
582 | # Add fbturbo video driver | |
578 | if [ "$ENABLE_FBTURBO" = true ] ; then |
|
583 | if [ "$ENABLE_FBTURBO" = true ] ; then | |
579 | # Enable xorg package dependencies |
|
584 | # Enable xorg package dependencies | |
580 | ENABLE_XORG=true |
|
585 | ENABLE_XORG=true | |
581 | fi |
|
586 | fi | |
582 |
|
587 | |||
583 | # Add user defined window manager package |
|
588 | # Add user defined window manager package | |
584 | if [ -n "$ENABLE_WM" ] ; then |
|
589 | if [ -n "$ENABLE_WM" ] ; then | |
585 | APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}" |
|
590 | APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}" | |
586 |
|
591 | |||
587 | # Enable xorg package dependencies |
|
592 | # Enable xorg package dependencies | |
588 | ENABLE_XORG=true |
|
593 | ENABLE_XORG=true | |
589 | fi |
|
594 | fi | |
590 |
|
595 | |||
591 | # Add xorg package |
|
596 | # Add xorg package | |
592 | if [ "$ENABLE_XORG" = true ] ; then |
|
597 | if [ "$ENABLE_XORG" = true ] ; then | |
593 | APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11" |
|
598 | APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11" | |
594 | fi |
|
599 | fi | |
595 |
|
600 | |||
596 | # Replace selected packages with smaller clones |
|
601 | # Replace selected packages with smaller clones | |
597 | if [ "$ENABLE_REDUCE" = true ] ; then |
|
602 | if [ "$ENABLE_REDUCE" = true ] ; then | |
598 | # Add levee package instead of vim-tiny |
|
603 | # Add levee package instead of vim-tiny | |
599 | if [ "$REDUCE_VIM" = true ] ; then |
|
604 | if [ "$REDUCE_VIM" = true ] ; then | |
600 | APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")" |
|
605 | APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")" | |
601 | fi |
|
606 | fi | |
602 |
|
607 | |||
603 | # Add dropbear package instead of openssh-server |
|
608 | # Add dropbear package instead of openssh-server | |
604 | if [ "$REDUCE_SSHD" = true ] ; then |
|
609 | if [ "$REDUCE_SSHD" = true ] ; then | |
605 | APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")" |
|
610 | APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")" | |
606 | fi |
|
611 | fi | |
607 | fi |
|
612 | fi | |
608 |
|
613 | |||
609 | # Configure systemd-sysv exclude to make halt/reboot/shutdown scripts available |
|
614 | # Configure systemd-sysv exclude to make halt/reboot/shutdown scripts available | |
610 | if [ "$ENABLE_SYSVINIT" = false ] ; then |
|
615 | if [ "$ENABLE_SYSVINIT" = false ] ; then | |
611 | APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv" |
|
616 | APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv" | |
612 | fi |
|
617 | fi | |
613 |
|
618 | |||
614 | # Configure kernel sources if no KERNELSRC_DIR |
|
619 | # Configure kernel sources if no KERNELSRC_DIR | |
615 | if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then |
|
620 | if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then | |
616 | KERNELSRC_CONFIG=true |
|
621 | KERNELSRC_CONFIG=true | |
617 | fi |
|
622 | fi | |
618 |
|
623 | |||
619 | # Configure reduced kernel |
|
624 | # Configure reduced kernel | |
620 | if [ "$KERNEL_REDUCE" = true ] ; then |
|
625 | if [ "$KERNEL_REDUCE" = true ] ; then | |
621 | KERNELSRC_CONFIG=false |
|
626 | KERNELSRC_CONFIG=false | |
622 | fi |
|
627 | fi | |
623 |
|
628 | |||
624 | # Configure qemu compatible kernel |
|
629 | # Configure qemu compatible kernel | |
625 | if [ "$ENABLE_QEMU" = true ] ; then |
|
630 | if [ "$ENABLE_QEMU" = true ] ; then | |
626 | DTB_FILE=vexpress-v2p-ca15_a7.dtb |
|
631 | DTB_FILE=vexpress-v2p-ca15_a7.dtb | |
627 | UBOOT_CONFIG=vexpress_ca15_tc2_defconfig |
|
632 | UBOOT_CONFIG=vexpress_ca15_tc2_defconfig | |
628 | KERNEL_DEFCONFIG="vexpress_defconfig" |
|
633 | KERNEL_DEFCONFIG="vexpress_defconfig" | |
629 | if [ "$KERNEL_MENUCONFIG" = false ] ; then |
|
634 | if [ "$KERNEL_MENUCONFIG" = false ] ; then | |
630 | KERNEL_OLDDEFCONFIG=true |
|
635 | KERNEL_OLDDEFCONFIG=true | |
631 | fi |
|
636 | fi | |
632 | fi |
|
637 | fi | |
633 |
|
638 | |||
634 | # Execute bootstrap scripts |
|
639 | # Execute bootstrap scripts | |
635 | for SCRIPT in bootstrap.d/*.sh; do |
|
640 | for SCRIPT in bootstrap.d/*.sh; do | |
636 | head -n 3 "$SCRIPT" |
|
641 | head -n 3 "$SCRIPT" | |
637 | . "$SCRIPT" |
|
642 | . "$SCRIPT" | |
638 | done |
|
643 | done | |
639 |
|
644 | |||
640 | ## Execute custom bootstrap scripts |
|
645 | ## Execute custom bootstrap scripts | |
641 | if [ -d "custom.d" ] ; then |
|
646 | if [ -d "custom.d" ] ; then | |
642 | for SCRIPT in custom.d/*.sh; do |
|
647 | for SCRIPT in custom.d/*.sh; do | |
643 | . "$SCRIPT" |
|
648 | . "$SCRIPT" | |
644 | done |
|
649 | done | |
645 | fi |
|
650 | fi | |
646 |
|
651 | |||
647 | # Execute custom scripts inside the chroot |
|
652 | # Execute custom scripts inside the chroot | |
648 | if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then |
|
653 | if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then | |
649 | cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts" |
|
654 | cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts" | |
650 | chroot_exec /bin/bash -x <<'EOF' |
|
655 | chroot_exec /bin/bash -x <<'EOF' | |
651 | for SCRIPT in /chroot_scripts/* ; do |
|
656 | for SCRIPT in /chroot_scripts/* ; do | |
652 | if [ -f $SCRIPT -a -x $SCRIPT ] ; then |
|
657 | if [ -f $SCRIPT -a -x $SCRIPT ] ; then | |
653 | $SCRIPT |
|
658 | $SCRIPT | |
654 | fi |
|
659 | fi | |
655 | done |
|
660 | done | |
656 | EOF |
|
661 | EOF | |
657 | rm -rf "${R}/chroot_scripts" |
|
662 | rm -rf "${R}/chroot_scripts" | |
658 | fi |
|
663 | fi | |
659 |
|
664 | |||
660 | # Remove c/c++ build environment from the chroot |
|
665 | # Remove c/c++ build environment from the chroot | |
661 | chroot_remove_cc |
|
666 | chroot_remove_cc | |
662 |
|
667 | |||
663 | # Generate required machine-id |
|
668 | # Generate required machine-id | |
664 | MACHINE_ID=$(dbus-uuidgen) |
|
669 | MACHINE_ID=$(dbus-uuidgen) | |
665 | echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id" |
|
670 | echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id" | |
666 | echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id" |
|
671 | echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id" | |
667 |
|
672 | |||
668 | # APT Cleanup |
|
673 | # APT Cleanup | |
669 | chroot_exec apt-get -y clean |
|
674 | chroot_exec apt-get -y clean | |
670 | chroot_exec apt-get -y autoclean |
|
675 | chroot_exec apt-get -y autoclean | |
671 | chroot_exec apt-get -y autoremove |
|
676 | chroot_exec apt-get -y autoremove | |
672 |
|
677 | |||
673 | # Unmount mounted filesystems |
|
678 | # Unmount mounted filesystems | |
674 | umount -l "${R}/proc" |
|
679 | umount -l "${R}/proc" | |
675 | umount -l "${R}/sys" |
|
680 | umount -l "${R}/sys" | |
676 |
|
681 | |||
677 | # Clean up directories |
|
682 | # Clean up directories | |
678 | rm -rf "${R}/run/*" |
|
683 | rm -rf "${R}/run/*" | |
679 | rm -rf "${R}/tmp/*" |
|
684 | rm -rf "${R}/tmp/*" | |
680 |
|
685 | |||
681 | # Clean up files |
|
686 | # Clean up files | |
682 | rm -f "${ETC_DIR}/ssh/ssh_host_*" |
|
687 | rm -f "${ETC_DIR}/ssh/ssh_host_*" | |
683 | rm -f "${ETC_DIR}/dropbear/dropbear_*" |
|
688 | rm -f "${ETC_DIR}/dropbear/dropbear_*" | |
684 | rm -f "${ETC_DIR}/apt/sources.list.save" |
|
689 | rm -f "${ETC_DIR}/apt/sources.list.save" | |
685 | rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original" |
|
690 | rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original" | |
686 | rm -f "${ETC_DIR}/*-" |
|
691 | rm -f "${ETC_DIR}/*-" | |
687 | rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy" |
|
692 | rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy" | |
688 | rm -f "${ETC_DIR}/resolv.conf" |
|
693 | rm -f "${ETC_DIR}/resolv.conf" | |
689 | rm -f "${R}/root/.bash_history" |
|
694 | rm -f "${R}/root/.bash_history" | |
690 | rm -f "${R}/var/lib/urandom/random-seed" |
|
695 | rm -f "${R}/var/lib/urandom/random-seed" | |
691 | rm -f "${R}/initrd.img" |
|
696 | rm -f "${R}/initrd.img" | |
692 | rm -f "${R}/vmlinuz" |
|
697 | rm -f "${R}/vmlinuz" | |
693 | rm -f "${R}${QEMU_BINARY}" |
|
698 | rm -f "${R}${QEMU_BINARY}" | |
694 |
|
699 | |||
695 | if [ "$ENABLE_QEMU" = true ] ; then |
|
700 | if [ "$ENABLE_QEMU" = true ] ; then | |
696 | # Setup QEMU directory |
|
701 | # Setup QEMU directory | |
697 | mkdir "${BASEDIR}/qemu" |
|
702 | mkdir "${BASEDIR}/qemu" | |
698 |
|
703 | |||
699 | # Copy kernel image to QEMU directory |
|
704 | # Copy kernel image to QEMU directory | |
700 | install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}" |
|
705 | install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}" | |
701 |
|
706 | |||
702 | # Copy kernel config to QEMU directory |
|
707 | # Copy kernel config to QEMU directory | |
703 | install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}" |
|
708 | install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}" | |
704 |
|
709 | |||
705 | # Copy kernel dtbs to QEMU directory |
|
710 | # Copy kernel dtbs to QEMU directory | |
706 | for dtb in "${BOOT_DIR}/"*.dtb ; do |
|
711 | for dtb in "${BOOT_DIR}/"*.dtb ; do | |
707 | if [ -f "${dtb}" ] ; then |
|
712 | if [ -f "${dtb}" ] ; then | |
708 | install_readonly "${dtb}" "${BASEDIR}/qemu/" |
|
713 | install_readonly "${dtb}" "${BASEDIR}/qemu/" | |
709 | fi |
|
714 | fi | |
710 | done |
|
715 | done | |
711 |
|
716 | |||
712 | # Copy kernel overlays to QEMU directory |
|
717 | # Copy kernel overlays to QEMU directory | |
713 | if [ -d "${BOOT_DIR}/overlays" ] ; then |
|
718 | if [ -d "${BOOT_DIR}/overlays" ] ; then | |
714 | # Setup overlays dtbs directory |
|
719 | # Setup overlays dtbs directory | |
715 | mkdir "${BASEDIR}/qemu/overlays" |
|
720 | mkdir "${BASEDIR}/qemu/overlays" | |
716 |
|
721 | |||
717 | for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do |
|
722 | for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do | |
718 | if [ -f "${dtb}" ] ; then |
|
723 | if [ -f "${dtb}" ] ; then | |
719 | install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/" |
|
724 | install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/" | |
720 | fi |
|
725 | fi | |
721 | done |
|
726 | done | |
722 | fi |
|
727 | fi | |
723 |
|
728 | |||
724 | # Copy u-boot files to QEMU directory |
|
729 | # Copy u-boot files to QEMU directory | |
725 | if [ "$ENABLE_UBOOT" = true ] ; then |
|
730 | if [ "$ENABLE_UBOOT" = true ] ; then | |
726 | if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then |
|
731 | if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then | |
727 | install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin" |
|
732 | install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin" | |
728 | fi |
|
733 | fi | |
729 | if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then |
|
734 | if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then | |
730 | install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage" |
|
735 | install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage" | |
731 | fi |
|
736 | fi | |
732 | if [ -f "${BOOT_DIR}/boot.scr" ] ; then |
|
737 | if [ -f "${BOOT_DIR}/boot.scr" ] ; then | |
733 | install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr" |
|
738 | install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr" | |
734 | fi |
|
739 | fi | |
735 | fi |
|
740 | fi | |
736 |
|
741 | |||
737 | # Copy initramfs to QEMU directory |
|
742 | # Copy initramfs to QEMU directory | |
738 | if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then |
|
743 | if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then | |
739 | install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}" |
|
744 | install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}" | |
740 | fi |
|
745 | fi | |
741 | fi |
|
746 | fi | |
742 |
|
747 | |||
743 | # Calculate size of the chroot directory in KB |
|
748 | # Calculate size of the chroot directory in KB | |
744 | CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')") |
|
749 | CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')") | |
745 |
|
750 | |||
746 | # Calculate the amount of needed 512 Byte sectors |
|
751 | # Calculate the amount of needed 512 Byte sectors | |
747 | TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512) |
|
752 | TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512) | |
748 | FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512) |
|
753 | FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512) | |
749 | ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}") |
|
754 | ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}") | |
750 |
|
755 | |||
751 | # The root partition is EXT4 |
|
756 | # The root partition is EXT4 | |
752 | # This means more space than the actual used space of the chroot is used. |
|
757 | # This means more space than the actual used space of the chroot is used. | |
753 | # As overhead for journaling and reserved blocks 35% are added. |
|
758 | # As overhead for journaling and reserved blocks 35% are added. | |
754 | ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512) |
|
759 | ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512) | |
755 |
|
760 | |||
756 | # Calculate required image size in 512 Byte sectors |
|
761 | # Calculate required image size in 512 Byte sectors | |
757 | IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}") |
|
762 | IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}") | |
758 |
|
763 | |||
759 | # Prepare image file |
|
764 | # Prepare image file | |
760 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
765 | if [ "$ENABLE_SPLITFS" = true ] ; then | |
761 | dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}" |
|
766 | dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}" | |
762 | dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}" |
|
767 | dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}" | |
763 | dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}" |
|
768 | dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}" | |
764 | dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}" |
|
769 | dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}" | |
765 |
|
770 | |||
766 | # Write firmware/boot partition tables |
|
771 | # Write firmware/boot partition tables | |
767 | sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM |
|
772 | sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM | |
768 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* |
|
773 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* | |
769 | EOM |
|
774 | EOM | |
770 |
|
775 | |||
771 | # Write root partition table |
|
776 | # Write root partition table | |
772 | sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM |
|
777 | sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM | |
773 | ${TABLE_SECTORS},${ROOT_SECTORS},83 |
|
778 | ${TABLE_SECTORS},${ROOT_SECTORS},83 | |
774 | EOM |
|
779 | EOM | |
775 |
|
780 | |||
776 | # Setup temporary loop devices |
|
781 | # Setup temporary loop devices | |
777 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)" |
|
782 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)" | |
778 | ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)" |
|
783 | ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)" | |
779 | else # ENABLE_SPLITFS=false |
|
784 | else # ENABLE_SPLITFS=false | |
780 | dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}" |
|
785 | dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}" | |
781 | dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}" |
|
786 | dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}" | |
782 |
|
787 | |||
783 | # Write partition table |
|
788 | # Write partition table | |
784 | sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM |
|
789 | sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM | |
785 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* |
|
790 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* | |
786 | ${ROOT_OFFSET},${ROOT_SECTORS},83 |
|
791 | ${ROOT_OFFSET},${ROOT_SECTORS},83 | |
787 | EOM |
|
792 | EOM | |
788 |
|
793 | |||
789 | # Setup temporary loop devices |
|
794 | # Setup temporary loop devices | |
790 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)" |
|
795 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)" | |
791 | ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)" |
|
796 | ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)" | |
792 | fi |
|
797 | fi | |
793 |
|
798 | |||
794 | if [ "$ENABLE_CRYPTFS" = true ] ; then |
|
799 | if [ "$ENABLE_CRYPTFS" = true ] ; then | |
795 | # Create dummy ext4 fs |
|
800 | # Create dummy ext4 fs | |
796 | mkfs.ext4 "$ROOT_LOOP" |
|
801 | mkfs.ext4 "$ROOT_LOOP" | |
797 |
|
802 | |||
798 | # Setup password keyfile |
|
803 | # Setup password keyfile | |
799 | touch .password |
|
804 | touch .password | |
800 | chmod 600 .password |
|
805 | chmod 600 .password | |
801 | echo -n ${CRYPTFS_PASSWORD} > .password |
|
806 | echo -n ${CRYPTFS_PASSWORD} > .password | |
802 |
|
807 | |||
803 | # Initialize encrypted partition |
|
808 | # Initialize encrypted partition | |
804 | echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password |
|
809 | echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password | |
805 |
|
810 | |||
806 | # Open encrypted partition and setup mapping |
|
811 | # Open encrypted partition and setup mapping | |
807 | cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}" |
|
812 | cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}" | |
808 |
|
813 | |||
809 | # Secure delete password keyfile |
|
814 | # Secure delete password keyfile | |
810 | shred -zu .password |
|
815 | shred -zu .password | |
811 |
|
816 | |||
812 | # Update temporary loop device |
|
817 | # Update temporary loop device | |
813 | ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}" |
|
818 | ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}" | |
814 |
|
819 | |||
815 | # Wipe encrypted partition (encryption cipher is used for randomness) |
|
820 | # Wipe encrypted partition (encryption cipher is used for randomness) | |
816 | dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")" |
|
821 | dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")" | |
817 | fi |
|
822 | fi | |
818 |
|
823 | |||
819 | # Build filesystems |
|
824 | # Build filesystems | |
820 | mkfs.vfat "$FRMW_LOOP" |
|
825 | mkfs.vfat "$FRMW_LOOP" | |
821 | mkfs.ext4 "$ROOT_LOOP" |
|
826 | mkfs.ext4 "$ROOT_LOOP" | |
822 |
|
827 | |||
823 | # Mount the temporary loop devices |
|
828 | # Mount the temporary loop devices | |
824 | mkdir -p "$BUILDDIR/mount" |
|
829 | mkdir -p "$BUILDDIR/mount" | |
825 | mount "$ROOT_LOOP" "$BUILDDIR/mount" |
|
830 | mount "$ROOT_LOOP" "$BUILDDIR/mount" | |
826 |
|
831 | |||
827 | mkdir -p "$BUILDDIR/mount/boot/firmware" |
|
832 | mkdir -p "$BUILDDIR/mount/boot/firmware" | |
828 | mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware" |
|
833 | mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware" | |
829 |
|
834 | |||
830 | # Copy all files from the chroot to the loop device mount point directory |
|
835 | # Copy all files from the chroot to the loop device mount point directory | |
831 | rsync -a "${R}/" "$BUILDDIR/mount/" |
|
836 | rsync -a "${R}/" "$BUILDDIR/mount/" | |
832 |
|
837 | |||
833 | # Unmount all temporary loop devices and mount points |
|
838 | # Unmount all temporary loop devices and mount points | |
834 | cleanup |
|
839 | cleanup | |
835 |
|
840 | |||
836 | # Create block map file(s) of image(s) |
|
841 | # Create block map file(s) of image(s) | |
837 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
842 | if [ "$ENABLE_SPLITFS" = true ] ; then | |
838 | # Create block map files for "bmaptool" |
|
843 | # Create block map files for "bmaptool" | |
839 | bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img" |
|
844 | bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img" | |
840 | bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img" |
|
845 | bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img" | |
841 |
|
846 | |||
842 | # Image was successfully created |
|
847 | # Image was successfully created | |
843 | echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
848 | echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" | |
844 | echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
849 | echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" | |
845 | else |
|
850 | else | |
846 | # Create block map file for "bmaptool" |
|
851 | # Create block map file for "bmaptool" | |
847 | bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img" |
|
852 | bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img" | |
848 |
|
853 | |||
849 | # Image was successfully created |
|
854 | # Image was successfully created | |
850 | echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
855 | echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" | |
851 |
|
856 | |||
852 | # Create qemu qcow2 image |
|
857 | # Create qemu qcow2 image | |
853 | if [ "$ENABLE_QEMU" = true ] ; then |
|
858 | if [ "$ENABLE_QEMU" = true ] ; then | |
854 | QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} |
|
859 | QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}} | |
855 | QEMU_SIZE=16G |
|
860 | QEMU_SIZE=16G | |
856 |
|
861 | |||
857 | qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2 |
|
862 | qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2 | |
858 | qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE |
|
863 | qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE | |
859 |
|
864 | |||
860 | echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created" |
|
865 | echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created" | |
861 | fi |
|
866 | fi | |
862 | fi |
|
867 | fi |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant