diff options
author | Michael Auchter <michael.auchter@ni.com> | 2021-04-02 14:40:22 -0500 |
---|---|---|
committer | Martin Braun <martin@gnuradio.org> | 2021-05-31 05:28:47 -0700 |
commit | 3b2814aa25fe5d396ebed004f686e8aca2c6ad6b (patch) | |
tree | ade1f7254de8f9eb9a4cb2cd88192124b71eff43 | |
parent | 73462501f04fe423bc3b4ec232dba710ee551e2b (diff) | |
download | uhd-3b2814aa25fe5d396ebed004f686e8aca2c6ad6b.tar.gz uhd-3b2814aa25fe5d396ebed004f686e8aca2c6ad6b.tar.bz2 uhd-3b2814aa25fe5d396ebed004f686e8aca2c6ad6b.zip |
tlv_eeprom: add eeprom-set-autoboot helper script
This adds a simple script to control the autoboot flag (i.e., whether
the device will automatically boot when power is connected or not).
Signed-off-by: Michael Auchter <michael.auchter@ni.com>
-rw-r--r-- | mpm/tools/tlv_eeprom/CMakeLists.txt | 1 | ||||
-rw-r--r-- | mpm/tools/tlv_eeprom/eeprom-set-autoboot | 59 |
2 files changed, 60 insertions, 0 deletions
diff --git a/mpm/tools/tlv_eeprom/CMakeLists.txt b/mpm/tools/tlv_eeprom/CMakeLists.txt index 75cf3c9cc..11879cfb7 100644 --- a/mpm/tools/tlv_eeprom/CMakeLists.txt +++ b/mpm/tools/tlv_eeprom/CMakeLists.txt @@ -36,5 +36,6 @@ endforeach(eeprom_tool_source ${eeprom_tool_sources}) install(PROGRAMS eeprom-path eeprom-wrapper + eeprom-set-autoboot DESTINATION ${RUNTIME_DIR} ) diff --git a/mpm/tools/tlv_eeprom/eeprom-set-autoboot b/mpm/tools/tlv_eeprom/eeprom-set-autoboot new file mode 100644 index 000000000..e2cb1facc --- /dev/null +++ b/mpm/tools/tlv_eeprom/eeprom-set-autoboot @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# +# Copyright 2021 Ettus Research, a National Instruments Brand +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import subprocess +import sys + +# Default flags if none in present in eeprom +# See board/titanium/usrp_eeprom.h in chromium-ec for details +MCU_FLAGS_DEFAULT = [0x00, 0x06, 0x00, 0x00, 0x00, 0x00] + + +def get_mcu_flags(): + """ + Return the current mcu flags stored in eeprom + """ + p = subprocess.run(['eeprom-dump', 'mb'], check=True, capture_output=True, encoding='ascii') + lines = p.stdout.split('\n') + for line in lines: + if line.startswith('usrp_eeprom_mcu_flags'): + flags = line.strip().split(' ')[-6:] + return [int(x, 0) for x in flags] + return None + + +def set_mcu_flags(flags): + """ + Set mcu flags in eeprom + """ + subprocess.run(['eeprom-update', 'mb', '--mcu_flags'] + [hex(x) for x in flags], check=True) + + +def set_autoboot(enabled): + """ + Control whether autoboot is enabled in the eeprom + """ + flags = get_mcu_flags() + if flags is None: + flags = MCU_FLAGS_DEFAULT + + flags[0] = flags[0] & ~0x1 + if enabled: + flags[0] |= 1 + + if get_mcu_flags() != flags: + set_mcu_flags(flags) + readback = get_mcu_flags() + assert readback == flags + + +if __name__ == '__main__': + if len(sys.argv) != 2 or sys.argv[1] not in ['on', 'off']: + print("usage: %s <on/off>" % sys.argv[0]) + sys.exit(1) + + set_autoboot(sys.argv[1] == 'on') |