5353 help = "Number of bytes to read" )
5454parser .add_option ("-w" , "--write" , type = "string" , dest = "write" , default = None ,
5555 help = "Hex-coded Values to read" )
56+
57+ parser .add_option ("--read-info" , dest = "read_info" , default = False ,
58+ action = "store_true" ,
59+ help = "Read and decode the info area of the selected memory space." )
60+
5661options , args = parser .parse_args ()
5762if options .space : options .space = int (options .space )
5863
@@ -110,6 +115,61 @@ def optimal_size(space:int, info:bool, address:int, nbytes:int):
110115 return b
111116 raise ValueError ("Access size incompatible with address or length (address=%d nbytes=%d memsizes=%d)" % (address , nbytes , memsizes ))
112117
118+ def get_uint16 (data :bytes , offset :int ):
119+ return (data [offset + 1 ] << 8 ) | data [offset ]
120+
121+ def print_info (data :bytes ):
122+ print (f"info area for memory space { options .space } :" )
123+
124+ cookie = get_uint16 (data , 0 )
125+ print (f" cookie: 0x{ cookie :04x} " )
126+
127+ memsize = get_uint16 (data , 2 )
128+ memsize_writable = memsize & 0x8000
129+ memsize_type = (memsize & 0x7f00 ) >> 8
130+ memsize_access = memsize & 0x000f
131+ print (f" memsize: 0x{ memsize :04x} " )
132+
133+ print (" Writable" if memsize_writable else " Read-Only" )
134+
135+ if (memsize_type == 0x01 ):
136+ print (" type=01 (Register)" )
137+ elif (memsize_type == 0x02 ):
138+ print (" type=02 (Memory)" )
139+ elif (memsize_type == 0x0e ):
140+ print (" type=0e (EEPROM)" )
141+ elif (memsize_type == 0x0f ):
142+ print (" type=0f (Flash)" )
143+ else :
144+ print (f" type={ memsize_type :02x} (unknown)" )
145+
146+ print (f" access=0x{ memsize_access :01x} " , end = '' )
147+ if memsize_access & 0x1 :
148+ print (" 8-bit" , end = '' )
149+ if memsize_access & 0x2 :
150+ print (" 16-bit" , end = '' )
151+ if memsize_access & 0x4 :
152+ print (" 32-bit" , end = '' )
153+ if memsize_access & 0x8 :
154+ print (" 64-bit" , end = '' )
155+ print ()
156+
157+ memranges = get_uint16 (data , 4 )
158+ e = (memranges & 0xf800 ) >> 11
159+ p = (memranges & 0x07c0 ) >> 6
160+ s = memranges & 0x003f
161+ print (f" memranges: 0x{ memranges :04x} " )
162+ print (f" erase block size: { e } ({ 2 ** e } bytes)" )
163+ print (f" page size: { p } ({ 2 ** p } bytes)" )
164+ print (f" Ps address range: { s } ({ 2 ** s } bytes)" )
165+
166+ addr_ptr = get_uint16 (data , 6 )
167+ print (f" addr ptr: 0x{ addr_ptr :04x} " )
168+
169+ name = str (data [8 :], encoding = 'utf-7' )
170+ print (f" name: { name } " )
171+
172+
113173if options .read :
114174 if options .address is None : raise SystemExit ("--read must specify --address" )
115175 if options .size == 0 :
@@ -127,6 +187,14 @@ def optimal_size(space:int, info:bool, address:int, nbytes:int):
127187 print (">" , command .hex ())
128188 transact (command , response = False )
129189
190+ elif options .read_info :
191+ if options .size == 0 :
192+ options .size = optimal_size (options .space , True , 0x0000 , 16 )
193+ command = make_read_request (options .space , True , options .size , options .increment , 0x00 , 0x10 )
194+ print (">" , command .hex ())
195+ data = transact (command )
196+ print_info (data )
197+
130198elif args :
131199 for a in args :
132200 transact (a )
0 commit comments