diff options
author | Liam Beguin <liambeguin@gmail.com> | 2018-03-14 19:15:15 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2018-03-22 13:25:20 -0400 |
commit | c3342cd58f251f78fe02955c47b51f7bb94e87ba (patch) | |
tree | 14395d7ceeaddaa6a3b7f787dd013026c328d497 /test | |
parent | 64a2cebb6e664ad32757c9507140aa69ad7228d3 (diff) | |
download | u-boot-c3342cd58f251f78fe02955c47b51f7bb94e87ba.tar.gz u-boot-c3342cd58f251f78fe02955c47b51f7bb94e87ba.tar.bz2 u-boot-c3342cd58f251f78fe02955c47b51f7bb94e87ba.zip |
test/py: add generic CRC32 function
Add a generic function which can be used to compute the CRC32 value of
a region of RAM.
Signed-off-by: Liam Beguin <liambeguin@gmail.com>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/py/u_boot_utils.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py index 64584494e4..de9ee2643f 100644 --- a/test/py/u_boot_utils.py +++ b/test/py/u_boot_utils.py @@ -11,6 +11,7 @@ import os.path import pytest import sys import time +import re def md5sum_data(data): """Calculate the MD5 hash of some data. @@ -310,3 +311,25 @@ def persistent_file_helper(u_boot_log, filename): """ return PersistentFileHelperCtxMgr(u_boot_log, filename) + +def crc32(u_boot_console, address, count): + """Helper function used to compute the CRC32 value of a section of RAM. + + Args: + u_boot_console: A U-Boot console connection. + address: Address where data starts. + count: Amount of data to use for calculation. + + Returns: + CRC32 value + """ + + bcfg = u_boot_console.config.buildconfig + has_cmd_crc32 = bcfg.get('config_cmd_crc32', 'n') == 'y' + assert has_cmd_crc32, 'Cannot compute crc32 without CONFIG_CMD_CRC32.' + output = u_boot_console.run_command('crc32 %08x %x' % (address, count)) + + m = re.search('==> ([0-9a-fA-F]{8})$', output) + assert m, 'CRC32 operation failed.' + + return m.group(1) |