aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/combined-image.sh
blob: 4e00cb89a286dae0ba97c9872965ccf5c9e8a875 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/sh

BLKSZ=65536

[ -f "$1" -a -f "$2" ] || {
	echo "Usage: $0 <kernel image> <rootfs image> [output file]"
	exit 1
}

IMAGE=${3:-openwrt-combined.img}

# Make sure provided images are 64k aligned.
kern="${IMAGE}.kernel"
root="${IMAGE}.rootfs"
dd if="$1" of="$kern" bs=$BLKSZ conv=sync 2>/dev/null
dd if="$2" of="$root" bs=$BLKSZ conv=sync 2>/dev/null

# Calculate md5sum over combined kernel and rootfs image.
md5=$(cat "$kern" "$root" | mkhash md5)

# Write image header followed by kernel and rootfs image.
# The header is padded to 64k, format is:
#  CI               magic word ("Combined Image")
#  <kernel length>  length of kernel encoded as zero padded 8 digit hex
#  <rootfs length>  length of rootfs encoded as zero padded 8 digit hex
#  <md5sum>         checksum of the combined kernel and rootfs image
( printf "CI%08x%08x%32s" \
	$(stat -c "%s" "$kern") $(stat -c "%s" "$root") "${md5%% *}" | \
	dd bs=$BLKSZ conv=sync;
  cat "$kern" "$root"
) > ${IMAGE} 2>/dev/null

# Clean up.
rm -f "$kern" "$root"
"nf">prereq: $(PREREQ_PACKAGES) download: $(DOWNLOAD_PACKAGES) compile: $(COMPILE_PACKAGES) install-targets: $(INSTALL_PACKAGES) install: rm -rf $(BUILD_DIR)/root $(MAKE) install-targets $(MAKE) preconfig @if [ -d $(TOPDIR)/files ]; then \ $(CP) $(TOPDIR)/files/. $(BUILD_DIR)/root; \ fi @( \ cd $(BUILD_DIR)/root; \ for script in ./etc/init.d/*; do \ grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \ IPKG_INSTROOT=$(BUILD_DIR)/root $(which bash) ./etc/rc.common $$script enable; \ done || true \ ) @-find $(BUILD_DIR)/root -name CVS | $(XARGS) rm -rf @-find $(BUILD_DIR)/root -name .svn | $(XARGS) rm -rf @-find $(BUILD_DIR)/root -name '.#*' | $(XARGS) rm -f index: $(PACKAGE_DIR)/Packages $(PACKAGE_DIR)/Packages: $(PACKAGE_DIR)/*.ipk (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages) symlinks: ../scripts/feeds.sh $(CONFIG_SOURCE_FEEDS) ifeq ($(MAKECMDGOALS),compile) MAKEFLAGS:=$(MAKEFLAGS) -j$(CONFIG_JLEVEL) else .NOTPARALLEL: endif