source: trunk/debian/rootfs/debian.mk @ 770

Last change on this file since 770 was 770, checked in by amain, 3 years ago

Install target dependent files during boot (sysV or systemd). This is needed because DebWrt rootfs image now are target independent. The target dependent files are installed via the debwrt-modules-*.gz file, which contains the target depending moduels and two files: /lib/modules/debwrt.target and /lib/modules/debwrt.subtarget. In case systemd does not work, sysvinit is installed as well (jessie+).

File size: 9.1 KB
Line 
1# DebWrt - Debian on Embedded devices
2#
3# Copyright (C) 2010,2015 Johan van Zoomeren <amain@debwrt.net>
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18QEMU_BIN=/usr/bin/qemu-$(ROOTFS_DEBIAN_ARCH)
19QEMU_BIN_STATIC=$(QEMU_BIN)-static
20QEMU_INTERPRETER=$(shell cat /proc/sys/fs/binfmt_misc/qemu-$(ROOTFS_DEBIAN_ARCH) 2>/dev/null | grep interpreter | awk '{print $$2}')
21
22ROOTFS_DEBIAN_INCLUDE_PACKAGES:=$(call qstrip,$(CONFIG_ROOTFS_DEBIAN_INCLUDE_PACKAGES))
23ROOTFS_DEBIAN_QEMU_2ND_STAGE:=$(call qstrip, $(CONFIG_ROOTFS_DEBIAN_QEMU_2ND_STAGE))
24DEBWRT_EXTRA_ROOTFS_FILES_DIR:=$(TOPDIR)/debian/rootfs/files
25MODULES_VERSION=$(shell echo `basename $(DEBWRT_MODULES_ARCHIVE) 2>/dev/null` | awk -F '-' '{print $$6}')
26ROOTFS_DEBIAN_INCLUDE_PACKAGES_DEBIAN_VERSION:=$(wildcard debian/rootfs/include_packages.list.$(ROOTFS_DEBIAN_RELEASE))
27
28define qemu-prepare
29        @if [ ! -x $(QEMU_BIN_STATIC) ]; then echo "E: can't find qemu ($(QEMU_BIN_STATIC))"; fi
30        @if [ ! -e /proc/sys/fs/binfmt_misc/qemu-$(ROOTFS_DEBIAN_ARCH) ]; then echo "E: can't find binfmt_misc qemu-$(ROOTFS_DEBIAN_ARCH) ( /proc/sys/fs/binfmt_misc/qemu-$(ROOTFS_DEBIAN_ARCH)).\nE: install qemu-user-static, or\nE: disable second stage with qemu with menuconfig (ROOTFS_DEBIAN_QEMU_2ND_STAGE)."; fi
31        @if [ ! -x $(QEMU_BIN_STATIC) -o ! -e /proc/sys/fs/binfmt_misc/qemu-$(ROOTFS_DEBIAN_ARCH) ]; then echo "E: abort - qemu not available in chroot"; exit 1; fi
32        @if [ ! -e $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER) ]; then sudo cp $(QEMU_BIN_STATIC) $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER); fi
33        @if ! sudo chroot $(ROOTFS_BUILD_DIR) /bin/ls >/dev/null; then echo "E: qemu can't execute binaries for $(ROOTFS_DEBIAN_ARCH)"; echo "E: abort"; exit 1; fi
34        @if ! (mount | grep -q $(ROOTFS_BUILD_DIR)/proc); then sudo chroot $(ROOTFS_BUILD_DIR) mount -t proc none /proc; fi
35        @if ! (mount | grep -q $(ROOTFS_BUILD_DIR)/sys ); then sudo chroot $(ROOTFS_BUILD_DIR) mount -t sysfs none /sys; fi
36        @mount
37endef
38
39define qemu-cleanup
40        @if (mount | grep -q $(ROOTFS_BUILD_DIR)/proc); then sudo umount $(ROOTFS_BUILD_DIR)/proc; fi
41        @if (mount | grep -q $(ROOTFS_BUILD_DIR)/sys ); then sudo umount $(ROOTFS_BUILD_DIR)/sys ; fi
42        @sudo rm -f $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER)
43endef
44
45define rootfs-package-list
46$(shell echo "$(DEBWRT_ROOTFS_PKGLST_DEPS)" \
47         | tr ' ' '\n' \
48         >$(TMP_DIR)/include_packages_list.debwrt-package-deps; \
49        grep -hv -e '^#' -v -e '^$$'  \
50                 $(ROOTFS_DEBIAN_INCLUDE_PACKAGES) \
51                 $(ROOTFS_DEBIAN_INCLUDE_PACKAGES_DEBIAN_VERSION) \
52                 $(TMP_DIR)/include_packages_list.debwrt-package-deps \
53          | sort -u | tr '\n' ',' | sed 's/,$$//')
54endef
55
56chr:
57        $(call qemu-prepare)
58        @sudo bash -c "echo "debwrt-$(ROOTFS_DEBIAN_ARCH)" > $(ROOTFS_BUILD_DIR)/etc/debian_chroot"
59        @sudo cp $(ROOTFS_BUILD_DIR)/etc/resolv.conf $(ROOTFS_BUILD_DIR)/etc/resolv.conf_debwrt
60        @sudo bash -c "cat /etc/resolv.conf | grep nameserver >$(ROOTFS_BUILD_DIR)/etc/resolv.conf"
61        @sudo chroot $(ROOTFS_BUILD_DIR)
62        @sudo rm -f $(ROOTFS_BUILD_DIR)/etc/debian_chroot
63        @sudo cp $(ROOTFS_BUILD_DIR)/etc/resolv.conf_debwrt $(ROOTFS_BUILD_DIR)/etc/resolv.conf
64        $(call qemu-cleanup)
65
66debian/rootfs: debian/rootfs/bootstrap            \
67               debian/rootfs/unpack               \
68               debian/rootfs/files-install        \
69               debian/rootfs/post-setup           \
70               debian/rootfs/second-stage         \
71               debian/rootfs/verify               \
72               debian/rootfs/save
73        @echo "I: Root filesystem $(ROOTFS_DEBIAN_RELEASE) $(ROOTFS_DEBIAN_ARCH) prepared in $(ROOTFS_BUILD_DIR) and archived in $(ROOTFS_INSTALL_DIR)/$(ROOTFS_TAR_BZ2)."
74        @echo "I:"
75        @echo "I: Install the image to USB-Disk/USB-Stick/SD-Card (make sure it is already mounted at /media/DEBWRT_ROOTFS)"
76        @echo "I: - make debian/rootfs/install"
77        @echo "I:"
78        @echo "I: Enter the change root(with qemu) and perform additional post install steps:"
79        @echo "I: - make chr"
80        @echo "I: - apt-get update # example statement ;-) - networking works!"
81        touch $@
82
83debian/rootfs/install: debian/rootfs
84        if [ -d /media/DEBWRT_ROOT ]; then \
85                sudo rm -rf /media/DEBWRT_ROOT/*; \
86                sudo bash -c "tar cf - -C $(ROOTFS_BUILD_DIR) . | tar xf - -C /media/DEBWRT_ROOT"; \
87        fi
88        #touch $@
89
90debian/rootfs/verify:
91        @if [ -f $(ROOTFS_BUILD_DIR)/debootstrap/debootstrap.log ]; then \
92                echo "E: Second stage install was not completed successfully" ;\
93                echo "E: Please check debootstrap.log to inspect the situation:" ;\
94                echo "E:    make chr" ;\
95                echo "E:    vi /debootstrap/debootstrap.log" ;\
96                exit 1 ;\
97        fi
98        touch $@
99
100debian/rootfs/save:
101        mkdir -p $(ROOTFS_INSTALL_DIR)
102        sudo bash -c "tar cjf $(ROOTFS_INSTALL_DIR)/$(ROOTFS_TAR_BZ2) -C $(ROOTFS_BUILD_DIR) ."
103        sudo chown $(USER) $(ROOTFS_INSTALL_DIR)/$(ROOTFS_TAR_BZ2)
104        sudo chmod 644 $(ROOTFS_INSTALL_DIR)/$(ROOTFS_TAR_BZ2)
105#ifeq ($(ROOTFS_DEBIAN_QEMU_2ND_STAGE),y)
106#else
107#       if [ -d /media/DEBWRT_ROOT ]; then \
108#               sudo bash -c "tar cjf $(ROOTFS_TAR_BZ2) -C /media/DEBWRT_ROOT ."; \
109#       fi
110#endif
111
112debian/rootfs/files-install: debian/rootfs/bootstrap
113        if [ ! -f $(ROOTFS_BUILD_DIR)/etc/init.d/rcS.debian -a -e $(ROOTFS_BUILD_DIR)/etc/init.d/rcS ]; then \
114                sudo mv -v $(ROOTFS_BUILD_DIR)/etc/init.d/rcS $(ROOTFS_BUILD_DIR)/etc/init.d/rcS.debian; \
115        fi
116        if [ ! -p $(ROOTFS_BUILD_DIR)/dev/initctl ]; then  \
117                sudo mkdir -p $(ROOTFS_BUILD_DIR)/dev;         \
118                sudo mkfifo   $(ROOTFS_BUILD_DIR)/dev/initctl; \
119        fi
120        chmod 600 $(DEBWRT_EXTRA_ROOTFS_FILES_DIR)/etc/ssh/ssh_host_rsa_key
121        chmod 600 $(DEBWRT_EXTRA_ROOTFS_FILES_DIR)/etc/ssh/ssh_host_dsa_key
122        @echo "Installing generic files (all):"
123        sudo bash -c "tar cf - --exclude=".svn" -C $(DEBWRT_EXTRA_ROOTFS_FILES_DIR)/all . | tar -xovf - -C $(ROOTFS_BUILD_DIR)"
124        @echo "Installing all targets files:"
125        sudo mkdir -p $(ROOTFS_BUILD_DIR)/target
126        sudo bash -c "tar cf - --exclude=".svn" --exclude ./all -C $(DEBWRT_EXTRA_ROOTFS_FILES_DIR) . | tar -xovf - -C $(ROOTFS_BUILD_DIR)/target"
127        sudo cat $(ROOTFS_BUILD_DIR)/etc/securetty \
128                $(TOPDIR)/debian/rootfs/securetty.tail \
129                >> $(TOPDIR)/securetty.temp
130        sudo mv $(TOPDIR)/securetty.temp $(ROOTFS_BUILD_DIR)/etc/securetty
131        touch $@
132
133# Fow now: Include debwrt-packages dependencies staticly. This
134#          list(DEBWRT_ROOTFS_PKGLST_DEPS) is managed in debian/package/debian.mk.
135debian/rootfs/bootstrap: debian/rootfs/clean-rootfs-dir
136        mkdir -p $(ROOTFS_BUILD_DIR)
137        sudo debootstrap --arch=$(ROOTFS_DEBIAN_ARCH)\
138                     --foreign \
139                     --include=$(call rootfs-package-list) \
140                     $(ROOTFS_DEBIAN_RELEASE) \
141                     $(ROOTFS_BUILD_DIR) \
142                     $(CONFIG_DEBIAN_BUILDENV_REPOSITORY)
143        # complete ROOTFS/dev/ with additional device files
144        sudo bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; /sbin/MAKEDEV -v consoleonly"
145        sudo bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; /sbin/MAKEDEV -v sda"
146        sudo bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; mknod -m 555 /dev/ttyS0 c 4 64; chown :tty ttyS0"
147        touch $@
148
149debian/rootfs/unpack: debian/rootfs/bootstrap
150        find $(ROOTFS_BUILD_DIR) -name "*.deb" | while read deb; do \
151                n=`basename $$deb`; \
152                echo -n "I: Extracting $${n}..."; \
153                sudo bash -c "dpkg --extract "$$deb" $(ROOTFS_BUILD_DIR)" ; \
154                echo "done"; \
155        done
156        touch $@
157
158# install all available cross-compiled debwrt debian packages, except for the kernel-headers package and the cross packages
159
160debian/rootfs/clean-rootfs-dir:
161        mkdir -p $(BUILD_DIR_BASE)
162        sudo rm -rf $(ROOTFS_BUILD_DIR)
163        touch $@
164
165debian/rootfs/post-setup: debian/rootfs/bootstrap
166        sudo mkdir -p $(ROOTFS_BUILD_DIR)/etc/apt
167        # note: unfortunately /etc/apt/sources.list is cleaned after running second stage install
168        sudo bash -c "echo \"deb http://ftp.debian.org/debian $(ROOTFS_DEBIAN_RELEASE) main\" > $(ROOTFS_BUILD_DIR)/etc/apt/sources.list"
169        sudo bash -c "echo \"$(DEBWRTVERSION)\" >$(ROOTFS_BUILD_DIR)/etc/debwrt_version"
170        sudo bash -c "echo \"$(ROOTFS_DEBIAN_RELEASE)\" >$(ROOTFS_BUILD_DIR)/etc/debian_release"
171        touch $@
172
173ifeq ($(ROOTFS_DEBIAN_QEMU_2ND_STAGE),y)
174#debian/rootfs/second-stage: debian/rootfs/bootstrap debian/buildenv/qemu
175debian/rootfs/second-stage: debian/rootfs/bootstrap
176        $(call qemu-prepare)
177        sudo chroot $(ROOTFS_BUILD_DIR) /usr/sbin/PostInstall && sudo rm -f $(ROOTFS_BUILD_DIR)/usr/sbin/PostInstall
178        $(call qemu-cleanup)
179else
180debian/rootfs/second-stage: debian/rootfs/bootstrap
181        @echo "I: Qemu 2nd stage install disabled. Second stage needs now to be performend on the target device itself."
182        @echo "I: Qemu 2nd stage install can be enabled using menuconfig (ROOTFS_DEBIAN_QEMU_2ND_STAGE)."
183endif
184        touch $@
185
186debian/rootfs/clean:
187        sudo rm -rf $(ROOTFS_BUILD_DIR)
188        rm -f debian/rootfs/bootstrap
189        rm -f debian/rootfs/install
190        rm -f debian/rootfs/files-install
191
Note: See TracBrowser for help on using the repository browser.