Add support for Intel Sandybridge CPU
[coreboot.git] / src / cpu / intel / microcode / update-microcodes.sh
1 #!/bin/bash
2 #
3 # This file is part of the coreboot project.
4 #
5 # Copyright (C) 2007-2010 coresystems GmbH
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19 #
20
21 MICROCODE_VERSION=20111110
22 MICROCODE_ARCHIVE=microcode-$MICROCODE_VERSION.tgz
23 MICROCODE_FILE=microcode.dat
24 INTEL_MICROCODE=http://downloadmirror.intel.com/20728/eng/$MICROCODE_ARCHIVE
25
26 #
27 # Getting Intel(R) Microcode
28 #
29
30 get_microcode() {
31     printf "Getting microcode...\n"
32     wget -nv $INTEL_MICROCODE
33     tar xzf $MICROCODE_ARCHIVE
34 }
35
36 #
37 # Creating separate files per microcode
38 #
39
40 separate_microcode() {
41     printf "Separating microcode...\n"
42     csplit -s -n4 -k $MICROCODE_FILE '/^\/\*.*\.inc.*\*\//' '{500}' 2> /dev/null
43     mv xx0000 header.inc
44     perl -pi -e 's,\ \ \ \ \ \ \ ,\     ,' header.inc
45     perl -pi -e 's,^,/,g' header.inc
46     perl -pi -e 's,^//\*,/\*,' header.inc
47     for i in xx????; do
48         name="`head -1 $i`"
49         name=${name%??}
50         name=${name:2}
51         name=$( echo $name )
52         name=microcode-${name%.inc}.h
53         cat header.inc $i > $name
54     done
55     rm -f xx???? header.inc
56 }
57
58 #
59 # Dump CPUIDs from all separated files
60 #
61
62 dump_cpuids() {
63     ls -1 microcode-*.h | while read F; do
64         CPUID="$( echo $( head -36 $F |tail -1|cut -d, -f4|sed s,0x,, ) | sed 's/0*//')"
65         echo "$CPUID:$F"
66     done
67 }
68
69 #
70 # Move microcode to target positions
71 #
72
73 move_microcode() {
74     printf "Moving microcode...\n"
75     dump_cpuids | sort | while read N; do
76         ID=$( echo $N | cut -d: -f1 )
77         F=$( echo $N | cut -d: -f2 )
78
79         if [ -d ../model_$ID ]; then
80             echo "Model: $ID  Microcode: $F"
81             mv $F ../model_$ID/$F
82         else
83             ID2=${ID%?}x
84             if [ -d ../model_$ID2 ]; then
85                 echo "Model: $ID($ID2)  Microcode: $F (copied)"
86                 mv $F ../model_$ID2/$F
87             else
88                 ID1=${ID%??}xx
89                 if [ -d ../model_$ID1 ]; then
90                     echo "Model: $ID($ID1)  Microcode: $F (copied)"
91                     mv $F ../model_$ID1/$F
92                 else
93                     echo "Model: $ID  Microcode: $F (erased)"
94                     rm -f $F
95                 fi
96             fi
97         fi
98     done
99 }
100
101 get_microcode
102 separate_microcode
103 move_microcode
104
105 rm -f $MICROCODE_ARCHIVE
106 rm -f $MICROCODE_FILE
107