combined-image.sh 988 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/sh
  2. BLKSZ=65536
  3. [ -f "$1" -a -f "$2" ] || {
  4. echo "Usage: $0 <kernel image> <rootfs image> [output file]"
  5. exit 1
  6. }
  7. # Make sure provided images are 64k aligned.
  8. kern=$(mktemp)
  9. root=$(mktemp)
  10. dd if="$1" of="$kern" bs=$BLKSZ conv=sync 2>/dev/null
  11. dd if="$2" of="$root" bs=$BLKSZ conv=sync 2>/dev/null
  12. # Calculate md5sum over combined kernel and rootfs image.
  13. md5=$(cat "$kern" "$root" | md5sum -)
  14. # Write image header followed by kernel and rootfs image.
  15. # The header is padded to 64k, format is:
  16. # CI magic word ("Combined Image")
  17. # <kernel length> length of kernel encoded as zero padded 8 digit hex
  18. # <rootfs length> length of rootfs encoded as zero padded 8 digit hex
  19. # <md5sum> checksum of the combined kernel and rootfs image
  20. ( printf "CI%08x%08x%32s" \
  21. $(stat -c "%s" "$kern") $(stat -c "%s" "$root") "${md5%% *}" | \
  22. dd bs=$BLKSZ conv=sync;
  23. cat "$kern" "$root"
  24. ) > ${3:-openwrt-combined.img} 2>/dev/null
  25. # Clean up.
  26. rm -f "$kern" "$root"