~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/extract-ikconfig

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/extract-ikconfig (Version linux-6.11.5) and /scripts/extract-ikconfig (Version linux-2.6.32.71)


  1 #!/bin/sh                                           1 #!/bin/sh
  2 # -------------------------------------------- !!   2 # extracts .config info from a [b]zImage file
  3 # extract-ikconfig - Extract the .config file  !!   3 # uses: binoffset (new), dd, zcat, strings, grep
  4 #                                              !!   4 # $arg1 is [b]zImage filename
  5 # This will only work when the kernel was comp !!   5 
  6 #                                              !!   6 binoffset="./scripts/binoffset"
  7 # The obscure use of the "tr" filter is to wor !!   7 test -e $binoffset || cc -o $binoffset ./scripts/binoffset.c || exit 1
  8 # "grep" that report the byte offset of the li !!   8 
  9 #                                              !!   9 IKCFG_ST="0x49 0x4b 0x43 0x46 0x47 0x5f 0x53 0x54"
 10 # (c) 2009,2010 Dick Streefland <dick@streeflan !!  10 IKCFG_ED="0x49 0x4b 0x43 0x46 0x47 0x5f 0x45 0x44"
 11 # Licensed under the terms of the GNU General  !!  11 dump_config() {
 12 # -------------------------------------------- !!  12     file="$1"
                                                   >>  13 
                                                   >>  14     start=`$binoffset $file $IKCFG_ST 2>/dev/null`
                                                   >>  15     [ "$?" != "0" ] && start="-1"
                                                   >>  16     if [ "$start" -eq "-1" ]; then
                                                   >>  17         return
                                                   >>  18     fi
                                                   >>  19     end=`$binoffset $file $IKCFG_ED 2>/dev/null`
                                                   >>  20     [ "$?" != "0" ] && end="-1"
                                                   >>  21     if [ "$end" -eq "-1" ]; then
                                                   >>  22         return
                                                   >>  23     fi
 13                                                    24 
 14 cf1='IKCFG_ST\037\213\010'                     !!  25     start=`expr $start + 8`
 15 cf2='0123456789'                               !!  26     size=`expr $end - $start`
 16                                                    27 
 17 dump_config()                                  !!  28     dd if="$file" ibs=1 skip="$start" count="$size" 2>/dev/null | zcat
                                                   >>  29 
                                                   >>  30     clean_up
                                                   >>  31     exit 0
                                                   >>  32 }
                                                   >>  33 
                                                   >>  34 
                                                   >>  35 usage()
 18 {                                                  36 {
 19         if      pos=`tr "$cf1\n$cf2" "\n$cf2=" !!  37         echo "  usage: extract-ikconfig [b]zImage_filename"
 20         then                                   << 
 21                 pos=${pos%%:*}                 << 
 22                 tail -c+$(($pos+8)) "$1" | zca << 
 23                 if      [ $? != 1 ]            << 
 24                 then    # exit status must be  << 
 25                         cat $tmp1              << 
 26                         exit 0                 << 
 27                 fi                             << 
 28         fi                                     << 
 29 }                                                  38 }
 30                                                    39 
 31 try_decompress()                               !!  40 clean_up()
 32 {                                                  41 {
 33         for     pos in `tr "$1\n$2" "\n$2=" <  !!  42         if [ "$TMPFILE" != "" ]; then
 34         do                                     !!  43                 rm -f $TMPFILE
 35                 pos=${pos%%:*}                 !!  44         fi
 36                 tail -c+$pos "$img" | $3 > $tm << 
 37                 dump_config $tmp2              << 
 38         done                                   << 
 39 }                                                  45 }
 40                                                    46 
 41 # Check invocation:                            !!  47 if [ $# -lt 1 ]
 42 me=${0##*/}                                    << 
 43 img=$1                                         << 
 44 if      [ $# -ne 1 -o ! -s "$img" ]            << 
 45 then                                               48 then
 46         echo "Usage: $me <kernel-image>" >&2   !!  49         usage
 47         exit 2                                 !!  50         exit 1
                                                   >>  51 fi
                                                   >>  52 
                                                   >>  53 TMPFILE=`mktemp -t ikconfig-XXXXXX` || exit 1
                                                   >>  54 image="$1"
                                                   >>  55 
                                                   >>  56 # vmlinux: Attempt to dump the configuration from the file directly
                                                   >>  57 dump_config "$image"
                                                   >>  58 
                                                   >>  59 GZHDR1="0x1f 0x8b 0x08 0x00"
                                                   >>  60 GZHDR2="0x1f 0x8b 0x08 0x08"
                                                   >>  61 
                                                   >>  62 ELFHDR="0x7f 0x45 0x4c 0x46"
                                                   >>  63 
                                                   >>  64 # vmlinux.gz: Check for a compressed images
                                                   >>  65 off=`$binoffset "$image" $GZHDR1 2>/dev/null`
                                                   >>  66 [ "$?" != "0" ] && off="-1"
                                                   >>  67 if [ "$off" -eq "-1" ]; then
                                                   >>  68         off=`$binoffset "$image" $GZHDR2 2>/dev/null`
                                                   >>  69         [ "$?" != "0" ] && off="-1"
                                                   >>  70 fi
                                                   >>  71 if [ "$off" -eq "0" ]; then
                                                   >>  72         zcat <"$image" >"$TMPFILE"
                                                   >>  73         dump_config "$TMPFILE"
                                                   >>  74 elif [ "$off" -ne "-1" ]; then
                                                   >>  75         (dd ibs="$off" skip=1 count=0 && dd bs=512k) <"$image" 2>/dev/null | \
                                                   >>  76                 zcat >"$TMPFILE"
                                                   >>  77         dump_config "$TMPFILE"
                                                   >>  78 
                                                   >>  79 # check if this is simply an ELF file
                                                   >>  80 else
                                                   >>  81         off=`$binoffset "$image" $ELFHDR 2>/dev/null`
                                                   >>  82         [ "$?" != "0" ] && off="-1"
                                                   >>  83         if [ "$off" -eq "0" ]; then
                                                   >>  84                 dump_config "$image"
                                                   >>  85         fi
 48 fi                                                 86 fi
 49                                                    87 
 50 # Prepare temp files:                          !!  88 echo "ERROR: Unable to extract kernel configuration information."
 51 tmp1=/tmp/ikconfig$$.1                         !!  89 echo "       This kernel image may not have the config info."
 52 tmp2=/tmp/ikconfig$$.2                         << 
 53 trap "rm -f $tmp1 $tmp2" 0                     << 
 54                                                << 
 55 # Initial attempt for uncompressed images or o << 
 56 dump_config "$img"                             << 
 57                                                << 
 58 # That didn't work, so retry after decompressi << 
 59 try_decompress '\037\213\010' xy    gunzip     << 
 60 try_decompress '\3757zXZ\000' abcde unxz       << 
 61 try_decompress 'BZh'          xy    bunzip2    << 
 62 try_decompress '\135\0\0\0'   xxx   unlzma     << 
 63 try_decompress '\211\114\132' xy    'lzop -d'  << 
 64 try_decompress '\002\041\114\030' xyy 'lz4 -d  << 
 65 try_decompress '\050\265\057\375' xxx unzstd   << 
 66                                                    90 
 67 # Bail out:                                    !!  91 clean_up
 68 echo "$me: Cannot find kernel config." >&2     << 
 69 exit 1                                             92 exit 1
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php