9
0
Fork 0
sumorobot-firmware/boot.py

35 lines
955 B
Python
Raw Permalink Normal View History

import os
2021-06-24 19:06:48 +00:00
import utime
import machine
2021-06-24 19:06:48 +00:00
2020-08-12 19:35:28 +00:00
# Give time to cancel this boot script
print("Press Ctrl-C to stop new boot script...")
2021-06-24 19:06:48 +00:00
utime.sleep_ms(1000)
root_files = os.listdir()
update_files = ['boot.py.new', 'main.py.new', 'hal.py.new']
files_to_update = []
# Check for FW updates and verify new FW files
for file in update_files:
if file in root_files:
2021-06-24 19:06:48 +00:00
print("boot.py: starting to update:", file)
# Try to load the user code
try:
with open(file, 'r') as code:
compile(code.read(), "snippet", 'exec')
files_to_update.append(file)
2021-06-24 19:06:48 +00:00
except Exception as error:
print("boot.py:", file, "compilation failed:", error)
files_to_update.clear()
break
# If valid updates replace with new FW
for file in files_to_update:
os.rename(file, file.replace('.new', ''))
# If updates, reboot to load new FW
if len(files_to_update) != 0:
machine.reset()