gen_image_generic.sh 1015 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bash
  2. # Copyright (C) 2006-2012 OpenWrt.org
  3. set -e -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. make_ext4fs -J -l "$KERNELSIZE" "$OUTPUT.kernel" "$KERNELDIR"
  27. dd if="$OUTPUT.kernel" of="$OUTPUT" bs=512 seek="$KERNELOFFSET" conv=notrunc
  28. rm -f "$OUTPUT.kernel"