rpi-eeprom-config/update: Exit cleanly when not run on rpi4

Some users might forcibly install this on a board that isn't an rpi4.
Exit early, and explain why the program can't be run.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
This commit is contained in:
Nicolas Saenz Julienne
2021-02-04 16:23:41 +01:00
parent 3d6165304c
commit 6fe6f22bad
2 changed files with 13 additions and 1 deletions

View File

@@ -32,6 +32,15 @@ FILE_HDR_LEN = 20
FILENAME_LEN = 12
TEMP_DIR = None
def rpi4():
compatible_path = "/sys/firmware/devicetree/base/compatible"
if os.path.exists(compatible_path):
with open(compatible_path, "rb") as f:
compatible = f.read().decode('utf-8')
if "bcm2711" in compatible:
return True
return False
def exit_handler():
"""
Delete any temporary files.
@@ -327,10 +336,12 @@ images.
parser.add_argument('eeprom', nargs='?', help='Name of EEPROM file to use as input')
args = parser.parse_args()
if (args.edit or args.apply is not None) and os.getuid() != 0:
exit_error("--edit/--apply must be run as root")
if (args.edit or args.apply is not None) and not rpi4():
exit_error("--edit/--apply must run on a Raspberry Pi 4")
if args.edit:
edit_config(args.eeprom)
elif args.apply is not None: