diff options
author | Emilio López <emilio.lopez@collabora.co.uk> | 2015-09-03 19:40:39 (GMT) |
---|---|---|
committer | Emilio López <emilio.lopez@collabora.co.uk> | 2015-09-25 12:13:00 (GMT) |
commit | 43c10b5dd4409e9feaeefb91a4628d247b496fd6 (patch) | |
tree | df15e940d28eac1a6680bc05c8ad60afb6e97b6b | |
parent | 6b3534651f4594894ee9ed2cbd64f995903686fa (diff) | |
download | test-definitions-43c10b5dd4409e9feaeefb91a4628d247b496fd6.tar.gz test-definitions-43c10b5dd4409e9feaeefb91a4628d247b496fd6.tar.xz |
cros_ec: add new test for vboot context interface
Differential Revision: https://phabricator.collabora.co.uk/D160
-rwxr-xr-x | kernel/cros_ec/scripts/cros-ec-test.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/kernel/cros_ec/scripts/cros-ec-test.py b/kernel/cros_ec/scripts/cros-ec-test.py index d86134d..a7f55d7 100755 --- a/kernel/cros_ec/scripts/cros-ec-test.py +++ b/kernel/cros_ec/scripts/cros-ec-test.py @@ -17,6 +17,10 @@ EC_DEV_IOCRDMEM = 0xc108ec01 # _IOWR(EC_DEV_IOC, 1, struct cros_ec_readmem) EC_CMD_MAX = 0xfc EC_MEMMAP_SIZE = 0xff EC_CMD_HELLO = 0x01 +EC_CMD_VBNV_CONTEXT = 0x17 +EC_VER_VBNV_CONTEXT = 1 +EC_VBNV_CONTEXT_OP_READ = 0 +EC_VBNV_BLOCK_SIZE = 16 EC_RES_SUCCESS = 0 EC_IN_DATA = 0xa0b0c0d0 # magic number that the EC expects on HELLO EC_OUT_DATA = 0xa1b2c3d4 # magic number that the EC answers on HELLO @@ -41,6 +45,17 @@ class cros_ec_readmem(Structure): ('buffer', c_ubyte * EC_MEMMAP_SIZE) ] +class ec_vbnvcontext_params(Structure): + _fields_ = [ + ('op', c_uint), + ('block', c_ubyte * EC_VBNV_BLOCK_SIZE) + ] + +class ec_vbnvcontext_response(Structure): + _fields_ = [ + ('block', c_ubyte * EC_VBNV_BLOCK_SIZE) + ] + class ec_params_hello(Structure): _fields_ = [ ('in_data', c_uint) @@ -115,6 +130,56 @@ if exit_status == os.EX_OK: else: print "ec-rdmem-ioctl: unknown" +print "Testing vboot context read" + +if exit_status == os.EX_OK: + param = ec_vbnvcontext_params() + param.op = EC_VBNV_CONTEXT_OP_READ + + response = ec_vbnvcontext_response() + + cmd = cros_ec_command() + cmd.version = EC_VER_VBNV_CONTEXT + cmd.command = EC_CMD_VBNV_CONTEXT + cmd.insize = sizeof(response) + cmd.outsize = sizeof(c_uint) + + memmove(addressof(cmd.data), addressof(param), cmd.outsize) + + try: + fcntl.ioctl(fd, EC_DEV_IOCXCMD, cmd) + + memmove(addressof(response), addressof(cmd.data), cmd.insize) + + sfs = open(EC_SYSFS_PATH + "/vbc/vboot_context", 'r') + ctx = sfs.read() + sfs.close() + status = True + for (k, i) in enumerate(ctx): + if k >= EC_VBNV_BLOCK_SIZE: + break + byte1 = int(response.block[k]) + byte2 = int(ord(i)) + if byte1 != byte2: + status = False + print "Position {}: expected {}, found {}".format( + k, hex(byte1), hex(byte2)) + else: + print "Position {}: OK with {}".format(k, hex(byte1)) + + if cmd.result == EC_RES_SUCCESS and status: + print "ec-vboot-ctx-read: pass" + else: + print "ec-vboot-ctx-read: fail" + exit_status = os.EX_IOERR + + except IOError as e: + print "I/O error({0}): {1}".format(e.errno, e.strerror) + print "ec-vboot-ctx-read: fail" + exit_status = os.EX_IOERR +else: + print "ec-vboot-ctx-read: unknown" + if fd != None: fd.close() |