summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/fru/default-fru/checkFru.sh
blob: 0ba6e132f8722323af3348d5f382bad0d87c9fc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash

# this script checks the gpio id and loads the correct baseboard fru
FRUPATH="/etc/fru"
PRODIDPATH="/var/cache/private"
fruFile="$FRUPATH/baseboard.fru.bin"
prodIDFile="$PRODIDPATH/prodID"
eepromFru=false

read_id() {
    local idx=0
    local result=0
    local value=0
    for ((idx=0; idx<6; idx++))
    do
        typeset -i value=$(gpioget $(gpiofind "FM_BMC_BOARD_SKU_ID${idx}_N"))
        value=$((value << idx))
        result=$((result | value))
    done
    echo $result
}

# Check 'Chassis Info Area' exists or not by checking its offset value in the
# FRU Common Header. If exists, return 0 (success).
chassis_area_found(){
    local eepromBus="3"
    local eepromAddr="0x56"
    local eepromReadOffset="0x02"
    local chassisAreaOffset="0"

    chassisAreaOffset=$(eeprog /dev/i2c-$eepromBus $eepromAddr -f -q -r $eepromReadOffset -x | awk '{print $2}')
    if [ $chassisAreaOffset != "00" ]; then
        return 0
    fi
    return 1
}

if [ -f $fruFile -a -f $prodIDFile ] &&
    grep -q 'CPU part\s*: 0xc07' /proc/cpuinfo; then
    exit 0
fi

BOARD_ID=$(read_id)
if grep -q 'CPU part\s*: 0xb76' /proc/cpuinfo; then
    # AST2500
    if [ -f $fruFile -a -f $prodIDFile -a $BOARD_ID -ne 0 ]; then
        exit 0
    fi

    case $BOARD_ID in
        12) NAME="D50TNP1SB"
            PRODID="0x99";;
        40) NAME="CooperCity"
            PRODID="0x9d";;
        42) NAME="WilsonCity"
            PRODID="0x91";;
        44) NAME="WilsonCityM"
            PRODID="0x91";;
        45) NAME="WilsonCity"
            PRODID="0x91";;
        60) NAME="M50CYP2SB2U"
            PRODID="0x98";;
        62) NAME="WilsonPoint"
            PRODID="0x9a";;
         0) PRODID="0x00"
            eepromFru=true
            rm -f $fruFile
            if ! chassis_area_found || [ -f /etc/bc_fru_write_fails ]; then
                nohup rewriteFru.sh &
            fi
            ;;
        *)  NAME="S2600WFT"
            PRODID="0x7b";;
    esac

elif grep -q 'CPU part\s*: 0xc07' /proc/cpuinfo; then
    # AST2600
    case $BOARD_ID in
        62) NAME="ArcherCity"
            PRODID="0x9c";;
        *)  NAME="AST2600EVB"
            PRODID="0x00";;
    esac

fi

if [ -z "$NAME" ]; then
    NAME="Unknown"
fi

if [ ! -e $prodIDFile ]
then
    echo $PRODID >$prodIDFile
fi

if $eepromFru;
then
    # Wait for rewriteFru.sh child process to finish.
    wait
    exit 0
fi

if [ ! -f $fruFile ]
then
    cd /tmp
    mkdir -p $FRUPATH
    mkfru $NAME
    mv $NAME.fru.bin $fruFile
fi