]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - lfs/flash-images
haproxy: Link against libatomic on ARM
[people/pmueller/ipfire-2.x.git] / lfs / flash-images
1 ###############################################################################
2 # #
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007-2017 IPFire Team <info@ipfire.org> #
5 # #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
18 # #
19 ###############################################################################
20
21 ###############################################################################
22 # Definitions
23 ###############################################################################
24
25 include Config
26
27 VER = ipfire
28
29 THISAPP = flash-image
30 TARGET = $(DIR_INFO)/$(THISAPP)
31
32 DEVICE = $(shell losetup -f)
33 PART_BOOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p1
34 PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p3
35
36 ifeq "$(SCON)" "1"
37 IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).1gb-ext4-scon.$(BUILD_ARCH)-full-core$(CORE).img.gz
38 else
39 IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).1gb-ext4.$(BUILD_ARCH)-full-core$(CORE).img.gz
40 endif
41
42 FSTAB_FMT = UUID=%s %-8s %-4s %-10s %d %d\n
43
44 ###############################################################################
45 # Top-level Rules
46 ###############################################################################
47
48 install : $(TARGET)
49
50 check :
51
52 download :
53
54 md5 :
55
56 ###############################################################################
57 # Installation Details
58 ###############################################################################
59 MNThdd := /install/harddisk
60 IMG := /install/images/image.img
61
62 # All sizes in blocks
63 ifeq "$(BUILD_PLATFORM)" "arm"
64 BOOTLOADER =
65 S_OFFSET = 8192
66
67 # FAT32
68 PART_TYPE = c
69 else
70 BOOTLOADER = grub
71 S_OFFSET = 8192
72
73 # Logical
74 PART_TYPE = L
75 endif
76
77 # /boot: 64MB - OFFSET
78 # / : 850MB
79 S_BOOT := $(shell echo $$(( 131072 - $(S_OFFSET) )))
80 S_ROOT := 1740800
81
82 PADDING = 100 # MB
83
84 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
85 # Stop if $(MNThdd) is still mounted
86 mountpoint $(MNThdd) && exit 1 || exit 0
87
88 rm -rf $(IMG) $(MNThdd) && mkdir -p $(MNThdd)
89
90 # Allocate image on disk
91 dd if=/dev/zero of=$(IMG) bs=512 count=$$(( $(S_OFFSET) + $(S_BOOT) + $(S_ROOT) ))
92 losetup $(DEVICE) $(IMG)
93
94 # Write Partition table
95 echo -e "$(S_OFFSET),$(S_BOOT),$(PART_TYPE),*\n,0,0\n$$(( $(S_BOOT) + $(S_OFFSET) )),$(S_ROOT),L\n" \
96 | sfdisk -uS $(DEVICE)
97 -echo -e "d\n2\nw\n\q\n" | fdisk $(DEVICE)
98
99 kpartx -v -a $(DEVICE)
100
101 # Format them
102 ifeq "$(PART_TYPE)" "c"
103 mkfs.vfat $(PART_BOOT)
104 else
105 mkfs.ext2 -F $(PART_BOOT)
106 endif
107 mkfs.ext4 -O ^has_journal,extent -F $(PART_ROOT)
108
109 # Most systems that use Flashimages has no RTC at boot
110 # so the interval check should disables
111 tune2fs -i0 $(PART_ROOT)
112
113 # Mount root partition
114 mount $(PART_ROOT) $(MNThdd)
115
116 # Mount boot partition
117 mkdir -pv $(MNThdd)/boot
118 mount $(PART_BOOT) $(MNThdd)/boot
119
120 # Install Pandaboard MLO and uboot first
121 ifeq "$(BUILD_PLATFORM)" "arm"
122 cp -v /boot/MLO $(MNThdd)/boot/
123 cp -v /boot/u-boot.img $(MNThdd)/boot/
124 cp -v /boot/zImage-ipfire-multi $(MNThdd)/boot/
125 cp -v /boot/uInit-ipfire-multi $(MNThdd)/boot/
126 cp -v /boot/uImage-ipfire-kirkwood $(MNThdd)/boot/
127 cp -v /boot/uInit-ipfire-kirkwood $(MNThdd)/boot/
128 cp -v /boot/uEnv.txt $(MNThdd)/boot/
129 # work around a u-boot bug not find the folders sometimes
130 mkdir -pv $(MNThdd)/boot/dtb-$(KVER)-ipfire-multi
131 mkdir -pv $(MNThdd)/boot/dtb-$(KVER)-ipfire-kirkwood
132
133 sync
134 umount $(MNThdd)/boot
135 mount $(PART_BOOT) $(MNThdd)/boot
136 endif
137
138 # Install IPFire
139 ifneq "$(BUILD_PLATFORM)" "arm"
140 tar -x --xz -C $(MNThdd)/ -f /install/cdrom/distro.img
141 else
142 tar -x -C $(MNThdd)/ -f /install/cdrom/distro.img
143 endif
144 echo "LANGUAGE=en" >> $(MNThdd)/var/ipfire/main/settings
145 echo "HOSTNAME=$(SNAME)" >> $(MNThdd)/var/ipfire/main/settings
146 echo "THEME=ipfire" >> $(MNThdd)/var/ipfire/main/settings
147
148 ifeq "$(SCON)" "1"
149 # Enable serial console
150 sed -i -e "s|1:2345:respawn:|#1:2345:respawn:|g" $(MNThdd)/etc/inittab
151 sed -i -e "s|2:2345:respawn:|#2:2345:respawn:|g" $(MNThdd)/etc/inittab
152 sed -i -e "s|3:2345:respawn:|#3:2345:respawn:|g" $(MNThdd)/etc/inittab
153 sed -i -e "s|4:2345:respawn:|#4:2345:respawn:|g" $(MNThdd)/etc/inittab
154 sed -i -e "s|5:2345:respawn:|#5:2345:respawn:|g" $(MNThdd)/etc/inittab
155 sed -i -e "s|6:2345:respawn:|#6:2345:respawn:|g" $(MNThdd)/etc/inittab
156 sed -i -e "s|#7:2345:respawn:|7:2345:respawn:|g" $(MNThdd)/etc/inittab
157
158 ifeq "$(BUILD_PLATFORM)" "arm"
159 sed -i -e "s| console=tty1 | console=ttyAMA0,115200n8 |g" $(MNThdd)/boot/cmdline.txt
160 sed -i -e "s| console=tty1 | console=ttyO2,115200n8 |g" $(MNThdd)/boot/uEnv.txt
161 endif
162 endif
163
164 -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep
165 mkdir $(MNThdd)/proc
166 mount --bind /proc $(MNThdd)/proc
167 mount --bind /dev $(MNThdd)/dev
168 mount --bind /sys $(MNThdd)/sys
169
170 chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
171
172 # Create /etc/fstab
173 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_BOOT))" "/boot" \
174 "auto" "defaults" 1 2 > $(MNThdd)/etc/fstab
175 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \
176 "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab
177
178 ifeq "$(BOOTLOADER)" "grub"
179 ifeq "$(SCON)" "1"
180 # Enable serial console on GRUB
181 echo "GRUB_TERMINAL=\"serial\"" >> $(MNThdd)/etc/default/grub
182 echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> $(MNThdd)/etc/default/grub
183
184 sed -i -e "s|panic=10|& console=ttyS0,115200n8|g" $(MNThdd)/etc/default/grub
185 endif
186
187 # Create configuration
188 mkdir -pv $(MNThdd)/boot/grub
189 chroot $(MNThdd) grub-mkconfig -o /boot/grub/grub.cfg
190
191 # Insert the UUID because grub-mkconfig often fails to
192 # detect that correctly
193 sed -i $(MNThdd)/boot/grub/grub.cfg \
194 -e "s/root=[A-Za-z0-9\/=-]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g"
195
196 # Install GRUB
197 grub-install --force --recheck --no-floppy --target=i386-pc \
198 --root-directory=$(MNThdd) $(DEVICE)
199 endif
200
201 # Set ramdisk mode to automatic
202 echo RAMDISK_MODE=2 > $(MNThdd)/etc/sysconfig/ramdisk
203
204 # Automatically resize the root partition to its maximum size at first boot
205 touch $(MNThdd)/.partresize
206
207 # Unmount
208 umount $(MNThdd)/proc
209 umount $(MNThdd)/sys
210 umount $(MNThdd)/dev
211 umount $(MNThdd)/boot
212 umount $(MNThdd)
213
214 # zerofree the ext2 images to get better compression
215 ifneq "$(PART_TYPE)" "c"
216 zerofree $(PART_BOOT)
217 -fsck.ext2 -f -y $(PART_BOOT)
218 fsck.ext2 -f -y $(PART_BOOT)
219 endif
220 zerofree $(PART_ROOT)
221 -fsck.ext4 -f -y $(PART_ROOT)
222 fsck.ext4 -f -y $(PART_ROOT)
223
224 sleep 10 #Ubuntu compiling: allow time to automount/dismount
225 kpartx -d -v $(DEVICE)
226 losetup -d $(DEVICE)
227
228 # Add padding at the end of the image (to fix alignment issues if the image is
229 # not copied to a block device)
230 dd if=/dev/zero bs=1M count=$(PADDING) >> $(IMG)
231
232 ifeq "$(BUILD_PLATFORM)" "arm"
233 # Install u-boot for LeMaker Banana Pi into image 8KB
234 dd if=/usr/share/u-boot/banana_pi/u-boot-sunxi-with-spl.bin of=$(IMG) bs=1K seek=8 conv=notrunc
235 endif
236
237 # Compress Image
238 pigz -f9 < $(IMG) > $(IMAGE_FILE)
239 rm -rf $(IMG) $(MNThdd)