gen_image_generic.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env bash
  2. # Copyright (C) 2006-2012 OpenWrt.org
  3. set -x
  4. [ $# == 5 -o $# == 6 ] || {
  5. echo "SYNTAX: $0 <file> <kernel size> <kernel directory> <rootfs size> <rootfs image> [<align>]"
  6. exit 1
  7. }
  8. OUTPUT="$1"
  9. KERNELSIZE="$2"
  10. KERNELDIR="$3"
  11. ROOTFSSIZE="$4"
  12. ROOTFSIMAGE="$5"
  13. ALIGN="$6"
  14. rm -f "$OUTPUT"
  15. head=16
  16. sect=63
  17. cyl=$(( ($KERNELSIZE + $ROOTFSSIZE) * 1024 * 1024 / ($head * $sect * 512)))
  18. # create partition table
  19. set `ptgen -o "$OUTPUT" -h $head -s $sect -p ${KERNELSIZE}m -p ${ROOTFSSIZE}m ${ALIGN:+-l $ALIGN} ${SIGNATURE:+-S 0x$SIGNATURE}`
  20. KERNELOFFSET="$(($1 / 512))"
  21. KERNELSIZE="$2"
  22. ROOTFSOFFSET="$(($3 / 512))"
  23. ROOTFSSIZE="$(($4 / 512))"
  24. [ -n "$PADDING" ] && dd if=/dev/zero of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc count="$ROOTFSSIZE"
  25. dd if="$ROOTFSIMAGE" of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc
  26. [ -n "$NOGRUB" ] && exit 0
  27. make_ext4fs -J -l "$KERNELSIZE" "$OUTPUT.kernel" "$KERNELDIR"
  28. dd if="$OUTPUT.kernel" of="$OUTPUT" bs=512 seek="$KERNELOFFSET" conv=notrunc
  29. rm -f "$OUTPUT.kernel"