extract-ikconfig 1.6 KB

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