xref: /aosp_15_r20/external/sg3_utils/inhex/README (revision 44704f698541f6367e81f991ef8bb54ccbf3fc18)
1*44704f69SBart Van Assche        Hex data for various sg3_utils utilities
2*44704f69SBart Van Assche        ========================================
3*44704f69SBart Van Assche
4*44704f69SBart Van AsscheThe files in this folder contain hexadecimal data (in ASCII) and associated
5*44704f69SBart Van Asschecomments (prefixed with the hash mark symbol: '#' ). Files containing
6*44704f69SBart Van Asschehexadecimal data have the extension ".hex". There is at least one file
7*44704f69SBart Van Asschecontaining binary data and it has the extension ".raw".
8*44704f69SBart Van Assche
9*44704f69SBart Van AsscheThe utility that each hex file is associated with can be determined in most
10*44704f69SBart Van Asschecase by prepending "sg_" to these filenames. Then go to the 'src' folder (a
11*44704f69SBart Van Asschesibling folder to this one) and look for a match or partial match on
12*44704f69SBart Van Asschethe name.
13*44704f69SBart Van Assche
14*44704f69SBart Van AsscheFor example:
15*44704f69SBart Van Assche    vpd_dev_id.hex
16*44704f69SBart Van Asscheafter prepending 'sg_' becomes:
17*44704f69SBart Van Assche    sg_vpd_dev_id.hex
18*44704f69SBart Van Asschewhich is a partial match on the sg_vpd utility.
19*44704f69SBart Van AsscheThe remaining 'dev_id.hex' is meant to suggest the 'device identifier'
20*44704f69SBart Van AsscheVPD page which is a mandatory VPD page for SCSI devices..
21*44704f69SBart Van Assche
22*44704f69SBart Van AsscheAssuming sg3_utils is installed, it can be tested like this:
23*44704f69SBart Van Assche    sg_vpd --inhex=<folder_holding_sg3_utils>/inhex/vpd_dev_id.hex
24*44704f69SBart Van Assche
25*44704f69SBart Van AsscheAnd should output this:
26*44704f69SBart Van Assche
27*44704f69SBart Van AsscheDevice Identification VPD page:
28*44704f69SBart Van Assche  Addressed logical unit:
29*44704f69SBart Van Assche    designator type: NAA,  code set: Binary
30*44704f69SBart Van Assche      0x5000c5003011cb2b
31*44704f69SBart Van Assche  Target port:
32*44704f69SBart Van Assche    designator type: NAA,  code set: Binary
33*44704f69SBart Van Assche     transport: Serial Attached SCSI Protocol (SPL-4)
34*44704f69SBart Van Assche      0x5000c5003011cb29
35*44704f69SBart Van Assche    designator type: Relative target port,  code set: Binary
36*44704f69SBart Van Assche     transport: Serial Attached SCSI Protocol (SPL-4)
37*44704f69SBart Van Assche      Relative target port: 0x1
38*44704f69SBart Van Assche  Target device that contains addressed lu:
39*44704f69SBart Van Assche    designator type: NAA,  code set: Binary
40*44704f69SBart Van Assche     transport: Serial Attached SCSI Protocol (SPL-4)
41*44704f69SBart Van Assche      0x5000c5003011cb28
42*44704f69SBart Van Assche    designator type: SCSI name string,  code set: UTF-8
43*44704f69SBart Van Assche      SCSI name string:
44*44704f69SBart Van Assche      naa.5000C5003011CB28
45*44704f69SBart Van Assche
46*44704f69SBart Van AsscheNot all the hex files follow the "prepend sg_" pattern. Those hex files
47*44704f69SBart Van Asschestarting with 'nvme_' are examples of invoking NVMe commands with the
48*44704f69SBart Van Asschesg_raw utility.
49*44704f69SBart Van Assche
50*44704f69SBart Van AsscheBinary <--> Hexadecimal
51*44704f69SBart Van Assche-----------------------
52*44704f69SBart Van AsscheThe vpd_zbdc.raw file is binary and was created by:
53*44704f69SBart Van Assche    sg_decode_sense --inhex=vpd_zbdc.hex --nodecode --write=vpd_zbdc.raw
54*44704f69SBart Van Asscheas an example of converting a file in ASCII hexadecimal byte oriented
55*44704f69SBart Van Asscheformat to binary.
56*44704f69SBart Van Assche
57*44704f69SBart Van AsscheTurning binary output into hexadecimal can be done several ways. For
58*44704f69SBart Van Asscheviewing in byte oriented ASCII hex these Unix commands can be used:
59*44704f69SBart Van Assche    od -t x1 vpd_zbdc.raw
60*44704f69SBart Van Assche    hexdump -C vpd_zbdc.raw
61*44704f69SBart Van Assche
62*44704f69SBart Van AsscheEach line starting with a "input offset" which is a running count of
63*44704f69SBart Van Asschebytes, starting at zero. The hexdump examples shows an ASCII rendering
64*44704f69SBart Van Asscheof those 16 bytes to the right of each line. The sg_decode_sense utility
65*44704f69SBart Van Asschemay also be used:
66*44704f69SBart Van Assche    sg_decode_sense --binary=vpd_zbdc.raw -H
67*44704f69SBart Van Assche    sg_decode_sense --binary=vpd_zbdc.raw -HH
68*44704f69SBart Van Assche
69*44704f69SBart Van AsscheThe second form of sg_decode_sense appends an ASCII rendering of the 16
70*44704f69SBart Van Asschebytes to the right of each line.
71*44704f69SBart Van Assche
72*44704f69SBart Van AsscheWhen ASCII hexadecimal is being used as input to a utility in this
73*44704f69SBart Van Asschepackage, the "input offset" at the start of each line (and the optional
74*44704f69SBart Van AsscheASCII rendering to the right of each line) must not be given.
75*44704f69SBart Van AsscheThat can be done with hexdump:
76*44704f69SBart Van Assche   hexdump -An -C -v vpd_zbdc.raw
77*44704f69SBart Van Assche           ^^^
78*44704f69SBart Van AsscheThat is a syntax error, there is no 'A' option <<<<<<<< check
79*44704f69SBart Van Assche
80*44704f69SBart Van AsscheAnd the sg_decode_sense utility can do it with (with the --nodecode option):
81*44704f69SBart Van Assche   sg_decode_sense -N --binary=vpd_zbdc.raw -HHH
82*44704f69SBart Van AsscheThat will print suitable lines of hexadecimal (16 bytes per line) to the
83*44704f69SBart Van Asscheconsole (stdout) To go the other way (i.e. hexadecimal to binary):
84*44704f69SBart Van Assche   sg_decode_sense -N --inhex=vpd_zbdc.hex --write=vpd_zbdc.bin
85*44704f69SBart Van Assche
86*44704f69SBart Van Assche
87*44704f69SBart Van AsscheConclusion
88*44704f69SBart Van Assche----------
89*44704f69SBart Van AsscheUsers are encouraged to send the author any ASCII hex files for utilities
90*44704f69SBart Van Asschethat support --inhex and don't have hex data already. Special cases are
91*44704f69SBart Van Asschealso welcome. They help the author test this code.
92*44704f69SBart Van Assche
93*44704f69SBart Van AsscheDouglas Gilbert
94*44704f69SBart Van Assche18th July 2022
95