forked from Ameba-AIoT/ameba-MicroPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
48 lines (38 loc) · 1.86 KB
/
Copy pathMakefile
File metadata and controls
48 lines (38 loc) · 1.86 KB
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
SHELL := /bin/bash
ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
PORT_DIR := $(ROOT)ports/ameba-rtos-m
ENV_SH := $(ROOT)ameba-rtos/env.sh
AMEBA := $(ROOT)ameba-rtos/ameba.py
# Target SoC, read from soc_info.json; switching chips needs no edit here.
DEVICE := $(shell python3 -c "import json;print(json.load(open('$(PORT_DIR)/soc_info.json'))['soc']['name'])")
# Retry on transient flash errors (b'\xe2' / DEV_TIMEOUT).
RETRY ?= 3
# deploy requires an explicit serial port, e.g. make deploy PORT=/dev/ttyUSB0
ifneq ($(filter deploy,$(MAKECMDGOALS)),)
ifeq ($(PORT),)
$(error PORT is required, e.g. make deploy PORT=/dev/ttyUSB0)
endif
endif
.PHONY: all build pristine clean deploy submodules
all: build
build: submodules
cd $(PORT_DIR) && source $(ENV_SH) && python $(AMEBA) build
pristine: submodules
cd $(PORT_DIR) && source $(ENV_SH) && python $(AMEBA) build -p
clean:
cd $(PORT_DIR) && source $(ENV_SH) && python $(AMEBA) clean
# Flash only -- skips build so repeated deploys are fast.
# To build and flash in one go: make build deploy PORT=/dev/ttyUSB0
# Serial port is required: make deploy PORT=/dev/ttyUSB0 [BAUD=115200]
deploy:
@cd $(PORT_DIR) && source $(ENV_SH) && for i in $$(seq 1 $(RETRY)); do \
echo ">> flash $$i/$(RETRY) ($(PORT) $(DEVICE))"; \
python $(AMEBA) flash -p $(PORT) $(if $(BAUD),-b $(BAUD)) -dev $(DEVICE) && exit 0; \
done; echo ">> flash failed"; exit 1
# Sync submodules to the commits recorded by the parent repo. Idempotent:
# a no-op offline when already in sync, so running it on every build is cheap.
# Unlike a one-time stamp, it also picks up submodule pointer bumps after a
# `git pull`, avoiding a silent build against a stale SDK.
submodules:
git -C $(ROOT) submodule update --init --depth 1 micropython ameba-rtos
git -C $(ROOT)micropython submodule update --init --depth 1 lib/berkeley-db-1.xx lib/micropython-lib