gen_image_generic.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env bash
  2. # Copyright (C) 2006-2012 OpenWrt.org
  3. set -x
  4. [ $# -eq 5 -o $# -eq 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 / 512))"
  22. ROOTFSOFFSET="$(($3 / 512))"
  23. ROOTFSSIZE="$(($4 / 512))"
  24. BLOCKS="$((($KERNELSIZE / 2) - 1))"
  25. [ -n "$PADDING" ] && dd if=/dev/zero of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc count="$ROOTFSSIZE"
  26. dd if="$ROOTFSIMAGE" of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc
  27. [ -n "$NOGRUB" ] && exit 0
  28. genext2fs -d "$KERNELDIR" -b "$BLOCKS" "$OUTPUT.kernel"
  29. dd if="$OUTPUT.kernel" of="$OUTPUT" bs=512 seek="$KERNELOFFSET" conv=notrunc
  30. rm -f "$OUTPUT.kernel"