summaryrefslogtreecommitdiffstats
path: root/src/build/sbeOpDistribute.py
blob: cb735b7321740f5729990031e7d3d201b1a96770 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/build/sbeOpDistribute.py $
#
# OpenPOWER sbe Project
#
# Contributors Listed Below - COPYRIGHT 2017,2019
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG
from __future__ import print_function
import os
import sys
import getopt

def usage():
    print("usage:sbeOpDistribute.py [--sbe_binary_dir] <sbe binary path> [--img_dir] <images path>")

def run_system_cmd(cmd):
    print('Cmd:<'+cmd+'>')
    if(os.system(cmd)):
        print("ERROR running cmd:<"+cmd+">")
        exit(1)

def main(argv):
    try:
        opts, args = getopt.getopt(sys.argv[1:], "", ['sbe_binary_dir=', 'img_dir=', 'buildSbePart=', 'hw_ref_image=', 'sbe_binary_filename=', 'scratch_dir=', 'install', 'help'])
    except getopt.GetoptError as err:
        print(str(err))
        usage()
        exit(1)

    # Default values
    mode = "MAKE"
    sbe_binary_dir = ''
    img_dir = ''
    buildSbePart = ''
    hw_ref_image = ''
    sbe_binary_filename = ''
    scratch_dir = ''

    sbe_out_name = ''

    if len(opts)<2:
        usage()
        exit(1)

    # Parse the command line arguments
    for opt, arg in opts:
        if opt == '--help':
            usage()
            exit(1)
        elif opt == '--install':
            mode = "INSTALL"
        elif opt == '--sbe_binary_dir':
            sbe_binary_dir = str(arg)
        elif opt == '--img_dir':
            img_dir = str(arg)
            assert os.path.exists(arg), "Did not find the file at,"+str(arg)
        elif opt == '--buildSbePart':
            buildSbePart = str(arg)
            assert os.path.exists(arg), "Did not find the file at,"+str(arg)
        elif opt == '--hw_ref_image':
            hw_ref_image = str(arg)
            assert os.path.exists(arg), "Did not find the file at,"+str(arg)
        elif opt == '--sbe_binary_filename':
            sbe_binary_filename = str(arg)
            sbe_out_name = sbe_binary_filename.split(".ecc")[0]
        elif opt == '--scratch_dir':
            scratch_dir = str(arg)
            assert os.path.exists(arg), "Did not find the file at,"+str(arg)

    SEEPROM_IMAGE           = 'sbe_seeprom.bin'
    SEEPROM_HDR_BIN         = 'sbe_seeprom.hdr.bin'

    #Default chipId for Nimbus chips as this script can be called without the
    #input SBE binary name.
    CHIPID = 'p9n'
    eclist = {'21':'DD2', '22':'DD2', '23':'DD2'}

    #Update if the script is called for Axone chips
    if (sbe_binary_filename == "axone_sbe.img.ecc"):
      CHIPID = 'p9a'
      eclist = {'10':'AXONE'}

    if (mode == "MAKE"):
        # Create binaries folder
        run_system_cmd('mkdir -p '+sbe_binary_dir)
        for ecLevel, ddLevel in eclist.items():
            # Copy sbe raw binary to binaries folder
            run_system_cmd('cp '+img_dir+'/'+'sbe_seeprom_'+ddLevel+'.bin'+' '+sbe_binary_dir+'/'+CHIPID+'_'+ecLevel+'.'+SEEPROM_IMAGE)
    elif (mode == "INSTALL"):
        ec_build_sbe_cmd = ''
        for ecLevel, ddLevel in eclist.items():
            basename = CHIPID+'_'+ecLevel+'.sbe_seeprom'
            ec_build_sbe_cmd += ' --ecImg_'+ecLevel+' '+scratch_dir+'/'+basename+'.hdr.bin'
            # Copy sbe raw binary to scratch folder
            run_system_cmd('cp '+sbe_binary_dir+'/'+basename+'.bin'+' '+scratch_dir+'/'+basename+'.bin')
            # Add HW ref image
            run_system_cmd('p9_ipl_build '+scratch_dir+'/'+basename+'.bin '+hw_ref_image+' 0x'+ecLevel)
            #add pnor header
            run_system_cmd("env echo -en VERSION\\\\0 > "+scratch_dir+"/"+basename+".sha.bin")
            run_system_cmd("sha512sum "+scratch_dir+"/"+basename+".bin | awk '{print $1}' | xxd -pr -r >> "+scratch_dir+"/"+basename+".sha.bin")
            run_system_cmd("dd if="+scratch_dir+"/"+basename+".sha.bin of="+scratch_dir+"/"+basename+".hdr.bin ibs=4k conv=sync")
            run_system_cmd("cat "+scratch_dir+"/"+basename+".bin >> "+scratch_dir+"/"+basename+".hdr.bin")

        # buildSbePart.pl
        run_system_cmd(buildSbePart+" --sbeOutBin "+scratch_dir+"/"+sbe_out_name+ec_build_sbe_cmd)
        run_system_cmd("ecc --inject "+scratch_dir+"/"+sbe_out_name+" --output "+scratch_dir+"/"+sbe_out_name+".ecc --p8")
if __name__ == "__main__":
    main(sys.argv)
OpenPOWER on IntegriCloud