1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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')
|