]> git.ipfire.org Git - ipfire-2.x.git/blame_incremental - lfs/flash-images
crda: update 3.13.
[ipfire-2.x.git] / lfs / flash-images
... / ...
CommitLineData
1###############################################################################
2# #
3# IPFire.org - A linux based firewall #
4# Copyright (C) 2007-2014 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
25include Config
26
27VER = ipfire
28
29THISAPP = flash-image
30TARGET = $(DIR_INFO)/$(THISAPP)
31
32DEVICE = $(shell losetup -f)
33PART_BOOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p1
34PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p3
35
36ifeq "$(SCON)" "1"
37 IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).1gb-ext4-scon.$(MACHINE)-full-core$(CORE).img.gz
38else
39 IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).1gb-ext4.$(MACHINE)-full-core$(CORE).img.gz
40endif
41
42FSTAB_FMT = UUID=%s %-8s %-4s %-10s %d %d\n
43
44###############################################################################
45# Top-level Rules
46###############################################################################
47
48install : $(TARGET)
49
50check :
51
52download :
53
54md5 :
55
56###############################################################################
57# Installation Details
58###############################################################################
59MNThdd := /install/harddisk
60IMG := /install/images/image.img
61
62# All sizes in blocks
63ifeq "$(MACHINE_TYPE)" "arm"
64 BOOTLOADER =
65 S_OFFSET = 8192
66
67 # FAT32
68 PART_TYPE = c
69else
70 BOOTLOADER = grub
71 S_OFFSET = 8192
72
73 # Logical
74 PART_TYPE = L
75endif
76
77# /boot: 64MB - OFFSET
78# / : 700MB
79S_BOOT := $(shell echo $$(( 131072 - $(S_OFFSET) )))
80S_ROOT := 1433600
81
82PADDING = 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 -D -uS -H 64 -S 32 $(DEVICE)
97
98 kpartx -v -a $(DEVICE)
99
100 # Format them
101ifeq "$(PART_TYPE)" "c"
102 mkfs.vfat $(PART_BOOT)
103else
104 mkfs.ext2 -F $(PART_BOOT)
105endif
106 mkfs.ext4 -O ^has_journal,extent -F $(PART_ROOT)
107
108 # Most systems that use Flashimages has no RTC at boot
109 # so the interval check should disables
110 tune2fs -i0 $(PART_ROOT)
111
112 # Mount root partition
113 mount $(PART_ROOT) $(MNThdd)
114
115 # Mount boot partition
116 mkdir -pv $(MNThdd)/boot
117 mount $(PART_BOOT) $(MNThdd)/boot
118
119 # Install Pandaboard MLO and uboot first
120ifeq "$(MACHINE_TYPE)" "arm"
121 cp -v /boot/MLO $(MNThdd)/boot/
122 cp -v /boot/u-boot.img $(MNThdd)/boot/
123 cp -v /boot/zImage-ipfire-multi $(MNThdd)/boot/
124 # work around a u-boot bug not find the folders sometimes
125 mkdir -pv $(MNThdd)/boot/dtb-$(KVER)-ipfire-multi
126 mkdir -pv $(MNThdd)/boot/dtb-$(KVER)-ipfire-kirkwood
127 sync
128 umount $(MNThdd)/boot
129 mount $(PART_BOOT) $(MNThdd)/boot
130endif
131
132 # Install IPFire
133ifneq "$(MACHINE_TYPE)" "arm"
134 tar -x --lzma -C $(MNThdd)/ -f /install/cdrom/distro.img
135else
136 tar -x -C $(MNThdd)/ -f /install/cdrom/distro.img
137endif
138 echo "LANGUAGE=en" >> $(MNThdd)/var/ipfire/main/settings
139 echo "HOSTNAME=$(SNAME)" >> $(MNThdd)/var/ipfire/main/settings
140 echo "THEME=ipfire" >> $(MNThdd)/var/ipfire/main/settings
141
142ifeq "$(SCON)" "1"
143 # Enable serial console
144 sed -i -e "s|1:2345:respawn:|#1:2345:respawn:|g" $(MNThdd)/etc/inittab
145 sed -i -e "s|2:2345:respawn:|#2:2345:respawn:|g" $(MNThdd)/etc/inittab
146 sed -i -e "s|3:2345:respawn:|#3:2345:respawn:|g" $(MNThdd)/etc/inittab
147 sed -i -e "s|4:2345:respawn:|#4:2345:respawn:|g" $(MNThdd)/etc/inittab
148 sed -i -e "s|5:2345:respawn:|#5:2345:respawn:|g" $(MNThdd)/etc/inittab
149 sed -i -e "s|6:2345:respawn:|#6:2345:respawn:|g" $(MNThdd)/etc/inittab
150 sed -i -e "s|#7:2345:respawn:|7:2345:respawn:|g" $(MNThdd)/etc/inittab
151
152ifeq "$(MACHINE_TYPE)" "arm"
153 sed -i -e "s| console=tty1 | console=ttyAMA0,115200n8 |g" $(MNThdd)/boot/cmdline.txt
154 sed -i -e "s| console=tty1 | console=ttyO2,115200n8 |g" $(MNThdd)/boot/uEnv.txt
155endif
156endif
157
158 -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep
159 mkdir $(MNThdd)/proc
160 mount --bind /proc $(MNThdd)/proc
161 mount --bind /dev $(MNThdd)/dev
162 mount --bind /sys $(MNThdd)/sys
163
164 chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
165
166 # Create /etc/fstab
167 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_BOOT))" "/boot" \
168 "auto" "defaults" 1 2 > $(MNThdd)/etc/fstab
169 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \
170 "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab
171
172ifeq "$(BOOTLOADER)" "grub"
173ifeq "$(SCON)" "1"
174 # Enable serial console on GRUB
175 echo "GRUB_TERMINAL=\"serial\"" >> $(MNThdd)/etc/default/grub
176 echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> $(MNThdd)/etc/default/grub
177
178 sed -i -e "s|panic=10|& console=ttyS0,115200n8|g" $(MNThdd)/etc/default/grub
179endif
180
181 # Create configuration
182 mkdir -pv $(MNThdd)/boot/grub
183 chroot $(MNThdd) grub-mkconfig -o /boot/grub/grub.cfg
184
185 # Insert the UUID because grub-mkconfig fails to detect that correctly
186 sed -i $(MNThdd)/boot/grub/grub.cfg \
187 -e "s/root=[a-z0-9\/]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g"
188
189 # Install GRUB
190 grub-install --force --recheck --no-floppy \
191 --root-directory=$(MNThdd) $(DEVICE)
192endif
193
194 # Automatically resize the root partition to its maximum size at first boot
195 touch $(MNThdd)/.partresize
196
197 # Unmount
198 umount $(MNThdd)/proc
199 umount $(MNThdd)/sys
200 umount $(MNThdd)/dev
201 umount $(MNThdd)/boot
202 umount $(MNThdd)
203
204 # zerofree the ext2 images to get better compression
205ifneq "$(PART_TYPE)" "c"
206 zerofree $(PART_BOOT)
207 -fsck.ext2 -f -y $(PART_BOOT)
208 fsck.ext2 -f -y $(PART_BOOT)
209endif
210 zerofree $(PART_ROOT)
211 -fsck.ext4 -f -y $(PART_ROOT)
212 fsck.ext4 -f -y $(PART_ROOT)
213
214 kpartx -d -v $(DEVICE)
215 losetup -d $(DEVICE)
216
217 # Add padding at the end of the image (to fix alignment issues if the image is
218 # not copied to a block device)
219 dd if=/dev/zero bs=1M count=$(PADDING) >> $(IMG)
220
221ifeq "$(MACHINE_TYPE)" "arm"
222 # Install u-boot for LeMaker Banana Pi into image 8KB
223 dd if=/usr/share/u-boot/banana_pi/u-boot-sunxi-with-spl.bin of=$(IMG) bs=1K seek=8 conv=notrunc
224endif
225
226 # Compress Image
227 pigz -f9 < $(IMG) > $(IMAGE_FILE)
228 rm -rf $(IMG) $(MNThdd)