more options

This commit is contained in:
iceman1001 2020-10-10 09:24:47 +02:00
parent ba8a4fdf5f
commit e14c1aaf21

View file

@ -11,7 +11,7 @@ example = [[
1. script run tearoff -n 2 -s 200 -e 400 -a 5 1. script run tearoff -n 2 -s 200 -e 400 -a 5
]] ]]
usage = [[ usage = [[
script run tearoff [-h] [-n <steps us>] [-a <addr>] [-p <pwd>] [-s <start us>] [-e <end us>] script run tearoff [-h] [-n <steps us>] [-a <addr>] [-p <pwd>] [-s <start us>] [-e <end us>] [-r <read>] [-w <write>]
]] ]]
arguments = [[ arguments = [[
-h This help -h This help
@ -20,6 +20,8 @@ arguments = [[
-p <pwd> (optional) use a password -p <pwd> (optional) use a password
-s <delay us> inital start delay -s <delay us> inital start delay
-e <delay us> end delay, must be larger than start delay -e <delay us> end delay, must be larger than start delay
-r <read value> 4 hex bytes value to be read
-w <write value> 4 hex bytes value to be written
end end
]] ]]
@ -59,18 +61,21 @@ local function main(args)
core.em4x05_read(addr, password) core.em4x05_read(addr, password)
--]] --]]
local n, addr, password, sd, ed local n, addr, password, sd, ed, wr_value, rd_value
for o, a in getopt.getopt(args, 'he:s:a:p:n:') do for o, a in getopt.getopt(args, 'he:s:a:p:n:r:w:') do
if o == 'h' then return help() end if o == 'h' then return help() end
if o == 'n' then n = a end if o == 'n' then n = a end
if o == 'a' then addr = a end if o == 'a' then addr = a end
if o == 'p' then password = a end if o == 'p' then password = a end
if o == 'e' then ed = tonumber(a) end if o == 'e' then ed = tonumber(a) end
if o == 's' then sd = tonumber(a) end if o == 's' then sd = tonumber(a) end
if o == 'w' then wr_value = a end
if o == 'r' then rd_value = a end
end end
rd_value = rd_value or 'FFFFFFFF'
wr_value = wr_value or 'FFFFFFFF'
addr = addr or 5 addr = addr or 5
password = password or '' password = password or ''
n = n or 2 n = n or 2
@ -81,6 +86,14 @@ local function main(args)
password = '' password = ''
end end
if #wr_value ~= 8 then
wr_value = 'FFFFFFFF'
end
if #rd_value ~= 8 then
rd_value = 'FFFFFFFF'
end
if sd > ed then if sd > ed then
return oops('start delay cant be larger than end delay', sd, ed) return oops('start delay cant be larger than end delay', sd, ed)
end end
@ -91,8 +104,9 @@ local function main(args)
print('target pwd', password) print('target pwd', password)
end end
print('target stepping', n) print('target stepping', n)
print('target delay') print('target delay', sd ,ed)
print('', sd, ed) print('read value', rd_value)
print('write value', wr_value)
local res_tear = 0 local res_tear = 0
local res_nowrite = 0 local res_nowrite = 0
@ -100,6 +114,8 @@ local function main(args)
local set_tearoff_delay = 'hw tearoff --delay %d' local set_tearoff_delay = 'hw tearoff --delay %d'
local enable_tearoff = 'hw tearoff --on' local enable_tearoff = 'hw tearoff --on'
local wr_template = 'lf em 4x05_write %s %s %s'
for step = sd, ed, n do for step = sd, ed, n do
io.flush() io.flush()
@ -109,23 +125,25 @@ local function main(args)
end end
core.clearCommandBuffer() core.clearCommandBuffer()
c = wr_template:format(addr, wr_value, password)
core.console(c)
local c = set_tearoff_delay:format(step) local c = set_tearoff_delay:format(step)
core.console(c); core.console(c);
core.console(enable_tearoff) core.console(enable_tearoff)
if #password == 8 then
c = ('lf em 4x05_write %s ffffffff %s'):format(addr, password) c = wr_template:format(addr, wr_value, password)
else
c = ('lf em 4x05_write %s ffffffff'):format(addr)
end
core.console(c) core.console(c)
local word, err = core.em4x05_read(addr, password) local word, err = core.em4x05_read(addr, password)
if err then if err then
return oops(err) return oops(err)
end end
if word ~= 0xFFFFFFFF then local wordstr = ('%08X'):format(word)
if word ~= 0 then
if wordstr ~= wr_value then
if wordstr ~= rd_value then
print((ansicolors.red..'TEAR OFF occured:'..ansicolors.reset..' %08X'):format(word)) print((ansicolors.red..'TEAR OFF occured:'..ansicolors.reset..' %08X'):format(word))
res_tear = res_tear + 1 res_tear = res_tear + 1
else else
@ -136,12 +154,6 @@ local function main(args)
print((ansicolors.green..'Good write occured:'..ansicolors.reset..' %08X'):format(word)) print((ansicolors.green..'Good write occured:'..ansicolors.reset..' %08X'):format(word))
end end
if password then
c = ('lf em 4x05_write %s 00000000 %s'):format(addr, password)
else
c = ('lf em 4x05_write %s 00000000'):format(addr)
end
core.console(c)
if res_tear == 5 then if res_tear == 5 then
print(('No of no writes %d'):format(res_nowrite)) print(('No of no writes %d'):format(res_nowrite))