combined-image.sh 1.0 KB

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