summaryrefslogtreecommitdiffstats
path: root/src/usr/sbeio/runtime/test/sbemsg-utils.sh
blob: 85e323c166a30f1e3042aa0d74a98bef59dad0e9 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/bin/bash
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/usr/sbeio/runtime/test/sbemsg-utils.sh $
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2017
# [+] 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

#-----------------------------------------------------------------------
# print-getscom
#   Filter value returned by getscom
#
#   print-getscom <addr>
#----------------------------------------------------------------------
print-getscom(){
    getscom pu $1 | grep -e '0x[0-9A-Fa-f]\{16\}' | sed -e 's/.*0x/0x/'
}

#-----------------------------------------------------------------------
# print-getscom-32
#   Filter value returned by getscom and return lsw
#
#   print-getscom-32 <addr>
#----------------------------------------------------------------------
print-getscom-32(){
    let temp=$(dw-getscom $1)
    let temp=$(($temp >>32))
    let temp=$(($temp&0x00000000FFFFFFFF))
    printf "0x%08x\n" $temp
}

#-----------------------------------------------------------------------
# append-u8()
#   Append a u8 hex value to a binary file.
#
#   append-u8 <hex value> <file>
#
#------------------------------------------------------------------------
append-u8(){
    if [ -z "$1" ] || [ -z "$2" ]
    then
        echo "Usage: append-u8 <value> <file>"
        echo "       param value: A uint8_t value to append to <file>"
        echo "       param file: The file to which the binary uint8_t"
        echo "                   value is to be appended."
    fi

    x=$1

    if [[ "${x:0:2}" != "0x" ]]
    then
        x="0x$x"
    fi

    let x=$(($x&0x00FF))
    printf "0000000: %02x" $x | xxd -r -g0 >> $2
}

#--------------------------------------------------------------------------
# append-u16()
#   Append a u16 hex value to a binary file. The xxd utility will store the
#   value in Big Endian format.
#
#   append-u16 <hex value> <file>
#---------------------------------------------------------------------------
append-u16(){
    if [ -z "$1" ] || [ -z "$2" ]
    then
        echo "Usage: append-u16 <value> <file>"
        echo "       param value: A uint16_t value to append to <file>"
        echo "       param file: The file to which the binary uint16_t"
        echo "                   value is to be appended."
    fi

    x=$1

    if [[ "${x:0:2}" != "0x" ]]
    then
        x="0x$x"
    fi

    let x=$(($x& 0x0000FFFF))
    printf "0000000: %04x" $x | xxd -r -g0 >> $2
}

#---------------------------------------------------------------------------
# append-u32()
#   Append a u32 hex value to a binary file. The xxd utility will store the
#   value in Big Endian format.
#
#   append-u32 <hex value> <file>
#---------------------------------------------------------------------------
append-u32(){
    if [ -z "$1" ] || [ -z "$2" ]
    then
        echo "Usage: append-u32 <value> <file>"
        echo "       param value: A uint32_t value to append to <file>"
        echo "       param file: The file to which the binary uint32_t"
        echo "                   value is to be appended."
    fi

    x=$1

    if [[ "${x:0:2}" != "0x" ]]
    then
        x="0x$x"
    fi

    let x=$(($x& 0x00000000FFFFFFFF))
    printf "0000000: %08x" $x | xxd -r -g0 >> $2
}

#---------------------------------------------------------------------------
# append-u64()
#   Append a u64 hex value to a binary file. The xxd utility will store the
#   value in Big Endian format.
#
#   append-u64 <hex value> <file>
#---------------------------------------------------------------------------
append-u64(){
    if [ -z "$1" ] || [ -z "$2" ]
    then
        echo "Usage: append-u64 <value> <file>"
        echo "       param value: A uint64_t value to append to <file>"
        echo "       param file: The file to which the binary uint64_t"
        echo "                   value is to be appended."
    fi

    x=$1

    if [[ "${x:0:2}" != "0x" ]]
    then
        x="0x$x"
    fi

    let x=$(($x))
    printf "0000000: %016x" $x | xxd -r -g0 >> $2
}

#----------------------------------------------------------------------------
# write-attr-request-hdr
#   Writes an SbeMessage Header to file.
#   write-attr-request-hdr $1 <out file> $2 <payload size> $3 [sequence number]
#
# HEADER SCHEMA
#   SBE HEADER VERSION(u32) - 0x00010000
#   SBE HEADER MSG SIZE(u32) - The size of the entire message HEADER + PAYLOAD
#   SBE HEADER SEQ NUMBER(u32) - The Sequence Number for the Message.
#   CMD HEADER VERSION(u32) - 0x00010000
#   CMD HEADER STATUS(u32)  - The response status.
#   CMD HEADER DATA OFFSET(u32) - 0x14.
#   CMD HEADER DATA SIZE(u32) - The payload size.
#   CMD HEADER COMMAND(u32) - 0x00E10002 (Attribute Override Command)
#----------------------------------------------------------------------------
write-attr-request-hdr(){
    if [ -z "$1" ] || [ -z "$2" ]
    then
        echo "Usage write-attr-request-hdr <outfile> <payload size> [sequence]"
        return
    fi

    if [ -z "$3" ]
    then
        sbe_hdr_seq_id=0x00000001
    else
        sbe_hdr_seq_id=$3
    fi

    sbe_hdr_version=0x00010000
    let sbe_hdr_msg_size=$(($2 + 0x20 ))
    sbe_hdr_msg_size=$(printf "0x%08x" $sbe_hdr_msg_size)
    cmd_hdr_version=0x00010000
    cmd_hdr_status=0x00000000
    cmd_hdr_data_offset=0x00000014
    cmd_hdr_data_size=$2
    cmd_hdr_command=0x00E10002

    append-u32 $sbe_hdr_version $1
    append-u32 $sbe_hdr_msg_size $1
    append-u32 $sbe_hdr_seq_id $1
    append-u32 $cmd_hdr_version $1
    append-u32 $cmd_hdr_status $1
    append-u32 $cmd_hdr_data_offset $1
    append-u32 $cmd_hdr_data_size $1
    append-u32 $cmd_hdr_command $1
}

#------------------------------------------------------------------------
# write-attr-request
#
#   Produce a binary file that can be copied to the
#   SBE COMMS AREA for use as an SBE Pass-through
#   request. The caller should pass the path of a binary file
#   that contains attribute override information. The contents of
#   the attribute override file will be concatenated to a file
#   containing a request header. This file should be copied to
#   the SBE COMMS AREA prior to invoking sbeMsg.
#
#   write-attr-request $1 <attribute override data file>
#                      $2 <outfile>
#                      $3 [Sequence Number of the request]
#
#   Parameters:
#       attr data file: A file produced by the attributeOverride tool.
#                       This file contains attribute overrides in binary
#                       form.
#       outfile: The request file. This file is the concatenation of an
#                SBE Pass-through request header and the attribute
#                override data from the first parameter.
#       sequence : A sequence number to identify the request/response.
#-------------------------------------------------------------------------
write-attr-request(){
    if [ -z "$1" ] || [ -z "$2" ]
    then
        echo "usage write-attr-request <attr data file> <outfile> [sequence]"
        return
    fi

    #Get payload size
    attrsize=$(wc -c $1 | awk '{print $1; exit}')
    let attrsize=$(($attrsize))
    attrsize=$(printf "0x%08x" $attrsize)

    #Set sequence number
    if [ -z $3 ]
    then
        sb_hdr_seq_id=0x00000001
    else
        sb_hdr_seq_id=$3
    fi

    #write request header to temp file
    tmpfile=/tmp/attr_override_request_$$
    write-attr-request-hdr $tmpfile $attrsize $sb_hdr_seq_id

    #Create request file and remove temporary
    cat $tmpfile $1 > $2
    rm -f $tmpfile
}

#----------------------------------------------------------
# parse-attr-resp
#   Parses a binary file, the contents of which represent
#   a response to an SBE Pass-Through command. The xxd
#   utility will convert the values returned from Big Endian
#   to host byte order.
#
#   parse-attr-resp $1 <input binary file>
#----------------------------------------------------------
parse-attr-resp(){
    if [ -z "$1" ]
    then
        echo "usage parse-attr-resp <bin file>"
        return
    fi

    let sbe_hdr_version=0x$(xxd -p -l4 -s0 $1)
    let sbe_hdr_msg_size=0x$(xxd -p -l4 -s4 $1)
    let sbe_hdr_seq_id=0x$(xxd -p -l4 -s8 $1)
    let cmd_hdr_version=0x$(xxd -p -l4 -s12 $1)
    let cmd_hdr_status=0x$(xxd -p -l4 -s16 $1)
    let cmd_hdr_data_offset=0x$(xxd -p -l4 -s20 $1)
    let cmd_hdr_data_size=0x$(xxd -p -l4 -s24 $1)
    let cmd_hdr_command=0x$(xxd -p -l4 -s28 $1)

    echo ""
    echo "Attribute Override Response:"
    printf "\tSBE HDR Version: 0x%08X\n" $sbe_hdr_version
    printf "\tSBE HDR MSG Size: 0x%08X (%d)\n" $sbe_hdr_msg_size \
                                               $sbe_hdr_msg_size
    printf "\tSBE HDR SEQ ID: 0x%08X (%d)\n" $sbe_hdr_seq_id \
                                             $sbe_hdr_seq_id
    printf "\tCMD HDR VERSION: 0x%08X\n" $cmd_hdr_version
    printf "\tCMD HDR STATUS: 0x%08X\n" $cmd_hdr_status
    printf "\tCMD HDR DATA OFFSET: 0x%08X (%d)\n" $cmd_hdr_data_offset \
                                                  $cmd_hdr_data_offset
    printf "\tCMD HDR DATA SIZE: 0x%08X (%d)\n" $cmd_hdr_data_size \
                                                $cmd_hdr_data_size
    printf "\tCMD HDR CMD: 0x%08X\n" $cmd_hdr_command
    echo ""
}
OpenPOWER on IntegriCloud