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