Skip to content

Commit

Permalink
Improve Pycom firmware installation
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jul 18, 2019
1 parent 0b10222 commit 3243a48
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 72 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Expand Up @@ -47,6 +47,7 @@ Development
- Improve Watchdog subsystem by adjusting to edge cases
- Reorder sections when uploading using FTP
- Add Self-documenting-Makefile helper
- Improve Pycom firmware installation


2019-06-22 0.5.1
Expand Down
7 changes: 3 additions & 4 deletions Makefile
Expand Up @@ -55,10 +55,12 @@
# Load modules
include tools/help.mk
include tools/core.mk
include tools/micropython.mk
include tools/setup.mk
include tools/release.mk

include tools/micropython.mk
include tools/pycom.mk


# -----
# Setup
Expand Down Expand Up @@ -113,9 +115,6 @@ install-ng:
$(MAKE) install; \
fi

install-pycom-firmware:
$(pycom_fwtool_cli) --verbose --port $(MCU_PORT) flash --tar dist-firmwares/fipy/FiPy-1.20.0.rc11.tar.gz

install-requirements: check-mcu-port
$(rshell) $(rshell_options) mkdir /flash/dist-packages
$(rshell) $(rshell_options) rsync dist-packages /flash/dist-packages
Expand Down
8 changes: 8 additions & 0 deletions doc/pycom-firmware-upgrade.rst
Expand Up @@ -2,6 +2,14 @@
Pycom firmware upgrade
######################

::

# Install FiPy-1.20.0.rc11.tar.gz (default)
make install-pycom-firmware

# Install recent firmware for WiPy
make install-pycom-firmware pycom_firmware_file=WiPy-1.20.0.rc11.tar.gz


************
Introduction
Expand Down
60 changes: 3 additions & 57 deletions tools/micropython.mk
Expand Up @@ -24,44 +24,22 @@ check-mcu-port:
fi


# ======================
# Pycom firmware updater
# ======================
$(eval pycom_fwtool_cli_macos := /Applications/Pycom\ Firmware\ Update.app/Contents/Resources/pycom-fwtool-cli)
$(eval pycom_fwtool_cli_windows := c:\\Program\ Files\ (x86)\\Pycom\\Pycom\ Firmware\ Update\\pycom-fwtool-cli.exe)

PYCOM_MACOS := $(or $(and $(wildcard $(pycom_fwtool_cli_macos)),1),0)
PYCOM_WINDOWS := $(or $(and $(wildcard $(pycom_fwtool_cli_windows)),1),0)

ifeq ($(PYCOM_MACOS),1)
pycom_fwtool_cli := $(pycom_fwtool_cli_macos)
endif
ifeq ($(PYCOM_WINDOWS),1)
pycom_fwtool_cli := $(pycom_fwtool_cli_windows)
endif

check-pycom-fwtool:
@if test "${pycom_fwtool_cli}" = ""; then \
echo "ERROR: Pycom Firmware Updater not found"; \
exit 1; \
else \
echo "INFO: Found Pycom Firmware Updater at $(pycom_fwtool_cli)"; \
fi


# ================
# Action utilities
# ================

list-serials:
@$(rshell) --list

## Run interactive rshell on the device
rshell: check-mcu-port
$(rshell) $(rshell_options)

## Run interactive REPL on the device
repl: check-mcu-port
$(rshell) $(rshell_options) repl

## Open console over serial or telnet
console: check-mcu-port

ifeq ($(mcu_port_type),usb)
Expand All @@ -87,35 +65,3 @@ reset-device-attached: check-mcu-port

reset-ampy:
$(ampy) --port $(serial_port) --delay 1 reset

format-flash: check-mcu-port

@# Old version
@# $(rshell) $(rshell_options) --file tools/clean.rshell

$(eval retval := $(shell bash -c 'read -s -p "Format /flash on the device with LittleFS? THIS WILL DESTROY DATA ON YOUR DEVICE. [y/n]? " outcome; echo $$outcome'))
@if test "$(retval)" = "y"; then \
echo; \
\
echo Creating LittleFS filesystem; \
$(rshell) $(rshell_options) --quiet repl pyboard 'import pycom ~ pycom.bootmgr(fs_type=pycom.LittleFS, reset=True) ~'; \
\
echo Formatting filesystem; \
$(rshell) $(rshell_options) --quiet repl pyboard 'import os ~ os.fsformat(\"/flash\") ~'; \
\
echo Resetting device; \
$(rshell) $(rshell_options) --quiet repl pyboard 'import machine ~ machine.reset() ~'; \
else \
echo; \
fi

erase-fs: check-mcu-port
$(eval retval := $(shell bash -c 'read -s -p "Erase the filesystem on the device? THIS WILL DESTROY DATA ON YOUR DEVICE. [y/n]? " outcome; echo $$outcome'))
@if test "$(retval)" = "y"; then \
echo; \
\
echo Erasing filesystem; \
$(pycom_fwtool_cli) --port ${MCU_PORT} erase_fs; \
else \
echo; \
fi
90 changes: 90 additions & 0 deletions tools/pycom.mk
@@ -0,0 +1,90 @@
# ======================
# Pycom firmware updater
# ======================
$(eval pycom_fwtool_cli_macos := /Applications/Pycom\ Firmware\ Update.app/Contents/Resources/pycom-fwtool-cli)
$(eval pycom_fwtool_cli_windows := c:\\Program\ Files\ (x86)\\Pycom\\Pycom\ Firmware\ Update\\pycom-fwtool-cli.exe)

PYCOM_MACOS := $(or $(and $(wildcard $(pycom_fwtool_cli_macos)),1),0)
PYCOM_WINDOWS := $(or $(and $(wildcard $(pycom_fwtool_cli_windows)),1),0)

ifeq ($(PYCOM_MACOS),1)
pycom_fwtool_cli := $(pycom_fwtool_cli_macos)
endif
ifeq ($(PYCOM_WINDOWS),1)
pycom_fwtool_cli := $(pycom_fwtool_cli_windows)
endif

check-pycom-fwtool:
@if test "${pycom_fwtool_cli}" = ""; then \
echo "ERROR: Pycom Firmware Updater not found"; \
exit 1; \
else \
echo "INFO: Found Pycom Firmware Updater at $(pycom_fwtool_cli)"; \
fi


# ===============
# Pycom utilities
# ===============

pycom_firmware_file := FiPy-1.20.0.rc11.tar.gz

## Download Pycom firmware to your workstation
download-pycom-firmware:

@# Define path to the "dist-packages" installation directory.
$(eval target_dir := ./dist-firmwares)
@#$(eval fetch := wget --no-clobber --unlink --directory-prefix)
$(eval fetch := wget --no-clobber --unlink)

@mkdir -p $(target_dir)
@#$(fetch) $(target_dir) https://github.com/pycom/pycom-micropython-sigfox/releases/download/v1.20.0.rc12/FiPy-1.20.0.rc12-application.elf

$(fetch) --output-document=$(target_dir)/$(pycom_firmware_file) https://software.pycom.io/downloads/$(pycom_firmware_file) || true

## Install Pycom firmware on device
install-pycom-firmware: download-pycom-firmware
$(eval retval := $(shell bash -c 'read -s -p "Install Pycom firmware \"$(pycom_firmware_file)\" on the device connected to \"$(MCU_PORT)\" [y/n]? " outcome; echo $$outcome'))
@if test "$(retval)" = "y"; then \
echo; \
\
echo Installing firmware $(pycom_firmware_file); \
$(pycom_fwtool_cli) --verbose --port $(MCU_PORT) flash --tar dist-firmwares/$(pycom_firmware_file); \
else \
echo; \
fi


## Format flash filesystem with LittleFS
format-flash: check-mcu-port

@# Old version
@# $(rshell) $(rshell_options) --file tools/clean.rshell

$(eval retval := $(shell bash -c 'read -s -p "Format /flash on the device with LittleFS? THIS WILL DESTROY DATA ON YOUR DEVICE. [y/n]? " outcome; echo $$outcome'))
@if test "$(retval)" = "y"; then \
echo; \
\
echo Creating LittleFS filesystem; \
$(rshell) $(rshell_options) --quiet repl pyboard 'import pycom ~ pycom.bootmgr(fs_type=pycom.LittleFS, reset=True) ~'; \
\
echo Formatting filesystem; \
$(rshell) $(rshell_options) --quiet repl pyboard 'import os ~ os.fsformat(\"/flash\") ~'; \
\
echo Resetting device; \
$(rshell) $(rshell_options) --quiet repl pyboard 'import machine ~ machine.reset() ~'; \
else \
echo; \
fi

## Erase flash filesystem
erase-fs: check-mcu-port
$(eval retval := $(shell bash -c 'read -s -p "Erase the filesystem on the device? THIS WILL DESTROY DATA ON YOUR DEVICE. [y/n]? " outcome; echo $$outcome'))
@if test "$(retval)" = "y"; then \
echo; \
\
echo Erasing filesystem; \
$(pycom_fwtool_cli) --port ${MCU_PORT} erase_fs; \
else \
echo; \
fi
11 changes: 0 additions & 11 deletions tools/setup.mk
@@ -1,14 +1,3 @@
download-pycom-firmware:

# Define path to the "dist-packages" installation directory.
$(eval target_dir := ./dist-firmwares)
$(eval fetch := wget --quiet --no-clobber --directory-prefix)

mkdir -p $(target_dir)/fipy
#$(fetch) $(target_dir)/fipy https://github.com/pycom/pycom-micropython-sigfox/releases/download/v1.20.0.rc12/FiPy-1.20.0.rc12-application.elf

$(fetch) $(target_dir)/fipy https://software.pycom.io/downloads/FiPy-1.20.0.rc11.tar.gz

download-requirements:

# Define path to the "dist-packages" installation directory.
Expand Down

0 comments on commit 3243a48

Please sign in to comment.