gen_image_olpc.sh 972 B

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