extract-ikconfig 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/sh
  2. # extracts .config info from a [b]zImage file
  3. # uses: binoffset (new), dd, zcat, strings, grep
  4. # $arg1 is [b]zImage filename
  5. binoffset="./scripts/binoffset"
  6. test -e $binoffset || cc -o $binoffset ./scripts/binoffset.c || exit 1
  7. IKCFG_ST="0x49 0x4b 0x43 0x46 0x47 0x5f 0x53 0x54"
  8. IKCFG_ED="0x49 0x4b 0x43 0x46 0x47 0x5f 0x45 0x44"
  9. function dump_config {
  10. typeset file="$1"
  11. start=`$binoffset $file $IKCFG_ST 2>/dev/null`
  12. [ "$?" != "0" ] && start="-1"
  13. if [ "$start" -eq "-1" ]; then
  14. return
  15. fi
  16. end=`$binoffset $file $IKCFG_ED 2>/dev/null`
  17. let start="$start + 8"
  18. let size="$end - $start"
  19. dd if="$file" ibs=1 skip="$start" count="$size" 2>/dev/null | zcat
  20. clean_up
  21. exit 0
  22. }
  23. usage()
  24. {
  25. echo " usage: extract-ikconfig [b]zImage_filename"
  26. }
  27. clean_up()
  28. {
  29. if [ "$TMPFILE" != "" ]; then
  30. rm -f $TMPFILE
  31. fi
  32. }
  33. if [ $# -lt 1 ]
  34. then
  35. usage
  36. exit 1
  37. fi
  38. TMPFILE=`mktemp -t ikconfig-XXXXXX` || exit 1
  39. image="$1"
  40. # vmlinux: Attempt to dump the configuration from the file directly
  41. dump_config "$image"
  42. GZHDR1="0x1f 0x8b 0x08 0x00"
  43. GZHDR2="0x1f 0x8b 0x08 0x08"
  44. # vmlinux.gz: Check for a compressed images
  45. off=`$binoffset "$image" $GZHDR1 2>/dev/null`
  46. [ "$?" != "0" ] && off="-1"
  47. if [ "$off" -eq "-1" ]; then
  48. off=`$binoffset "$image" $GZHDR2 2>/dev/null`
  49. [ "$?" != "0" ] && off="-1"
  50. fi
  51. if [ "$off" -eq "0" ]; then
  52. zcat <"$image" >"$TMPFILE"
  53. dump_config "$TMPFILE"
  54. elif [ "$off" -ne "-1" ]; then
  55. (dd ibs="$off" skip=1 count=0 && dd bs=512k) <"$image" 2>/dev/null | \
  56. zcat >"$TMPFILE"
  57. dump_config "$TMPFILE"
  58. fi
  59. echo "ERROR: Unable to extract kernel configuration information."
  60. echo " This kernel image may not have the config info."
  61. clean_up
  62. exit 1