-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
181 lines (157 loc) · 5.2 KB
/
Makefile
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
DOCKER_IMAGE="zondax/builder-yocto"
INTERACTIVE:=$(shell [ -t 0 ] && echo 1)
ifdef INTERACTIVE
INTERACTIVE_SETTING:="-i"
TTY_SETTING:="-t"
else
INTERACTIVE_SETTING:=
TTY_SETTING:=
endif
SCRIPTS_DIR=/home/zondax/shared/scripts
QEMU_SERIAL1 := 54320
QEMU_SERIAL2 := 54321
GDB_SERVER := 1234
SSH_HOST_FWD := 5555
gnome-terminal := $(shell command -v gnome-terminal 2>/dev/null)
xterm := $(shell command -v xterm 2>/dev/null)
ifdef gnome-terminal
define launch-terminal
$(gnome-terminal) -x telnet localhost $(1) &
endef
else
ifdef xterm
define launch-terminal
$(xterm) -title $(2) -e $(BASH) -c "telnet localhost $(1)"
endef
endif
endif
define run_docker_fetch
$(eval FORCE := $(word 1, $(2)))
docker run $(TTY_SETTING) $(INTERACTIVE_SETTING) --rm \
-u $(shell id -u) \
-v $(shell pwd)/shared:/home/zondax/shared \
-e FORCE_FETCH=$(FORCE) \
$(DOCKER_IMAGE) \
"$(1)"
endef
# $(2) is MACHINE
define run_docker_build
docker run $(TTY_SETTING) $(INTERACTIVE_SETTING) --rm \
-u $(shell id -u) \
-v $(shell pwd)/shared:/home/zondax/shared \
-e ZONDAX_CONF=$(2) \
$(DOCKER_IMAGE) \
"$(1)"
endef
define run_docker_qemu
docker run $(TTY_SETTING) $(INTERACTIVE_SETTING) --rm \
-u $(shell id -u) \
-v $(shell pwd)/shared:/home/zondax/shared \
-p $(QEMU_SERIAL1):$(QEMU_SERIAL1) \
-p $(QEMU_SERIAL2):$(QEMU_SERIAL2) \
-p $(GDB_SERVER):$(GDB_SERVER) \
-p $(SSH_HOST_FWD):$(SSH_HOST_FWD) \
-e ZONDAX_CONF=$(2) \
$(DOCKER_IMAGE) \
"$(1)"
endef
define run_docker_qemu_xterm
$(call launch-terminal,$(QEMU_SERIAL1),"Normal World")
$(call launch-terminal,$(QEMU_SERIAL2),"Secure World")
$(call run_docker_qemu,$(1),$(2))
endef
# $(2) is MACHINE
define run_docker_toaster
docker run $(TTY_SETTING) $(INTERACTIVE_SETTING) --rm \
-u $(shell id -u) \
-v $(shell pwd)/shared:/home/zondax/shared \
-p 8000:8000 \
-e DISPLAY=$(shell echo ${DISPLAY}) \
-v /tmp/.X11-unix:/tmp/.X11-unix:ro \
-e ZONDAX_CONF=$(2) \
$(DOCKER_IMAGE) \
"$(1)"
endef
define run_docker_recipe
$(eval MACHINE := $(word 1, $(2)))
$(eval RECIPE := $(word 2, $(2)))
docker run $(TTY_SETTING) $(INTERACTIVE_SETTING) --rm \
-u $(shell id -u) \
-v $(shell pwd)/shared:/home/zondax/shared \
-e ZONDAX_CONF=$(MACHINE) \
-e ZONDAX_RECIPE=$(RECIPE) \
$(DOCKER_IMAGE) \
"$(1)"
endef
define run_dev_environment
$(eval MACHINE := $(word 1, $(1)))
$(eval MACHINE := $(if $(MACHINE),$(MACHINE), "qemu"))
# TODO: We need to handle previous sessions? Kill or attach? `tmux kill-server`
# TODO: We need to handle preexisting stale containers?
# TODO: make scripts and remove all these sleeps
tmux new-session -s "zondax-dev" -d "make run $(MACHINE); bash"
tmux set -g mouse on
tmux split-window -p 66 "echo 'Normal world'; sleep 15; telnet localhost 54320"
tmux split-window -d "echo 'Waiting for QEMU ($(MACHINE))'; sleep 15; make shell $(MACHINE)"
tmux split-window -h "echo 'Secure world'; sleep 15; telnet localhost 54321"
tmux attach-session -d
endef
.PHONY: help
help:
@echo "Usage:"
@echo " make workspace <target> <recipe> Create a workspace for <target> <recipe>"
@echo " make dev Launch a tmux ready environment for QEMU"
@echo ""
@echo "Others:"
@echo " make docker Fetch Zondax docker image"
@echo " make manifest Fetch Zondax repo manifest"
@echo " make manifest force Force fetch/update Zondax repo manifest"
@echo " make login Simply login into docker container"
@echo " make toaster <target> Run Toaster web interface"
@echo " make build <target> Build image for <target>"
@echo " make shell <target> Get shell for <target>"
@echo " make workspace <target> <recipe> Create a workspace for <recipe>"
@echo " make run <qemu|qemu8> Run QEMU ARMv7/QEMU ARMv8 emulation"
@echo " make run-term <qemu|qemu8> Run QEMU emulation + fork xterm terminals for NW/SW consoles"
@echo ""
@echo "Typical <targets> = qemu qemu8 dk2"
@echo ""
.PHONY: docker
docker:
docker pull $(DOCKER_IMAGE)
.PHONY: manifest
manifest: docker
$(call run_docker_fetch,$(SCRIPTS_DIR)/zxfetch.sh,$(filter-out $@,$(MAKECMDGOALS)))
.PHONY: login
login: manifest
$(call run_docker_build,zsh)
.PHONY: toaster
toaster: manifest
$(call run_docker_toaster,$(SCRIPTS_DIR)/zxtoaster.sh,$(filter-out $@,$(MAKECMDGOALS)))
.PHONY: shell
shell: manifest
$(call run_docker_build,$(SCRIPTS_DIR)/zxshell.sh,$(filter-out $@,$(MAKECMDGOALS)))
# Building images
.PHONY: build
build: manifest
$(call run_docker_build,$(SCRIPTS_DIR)/zxbuild.sh,$(filter-out $@,$(MAKECMDGOALS)))
.PHONY: run
run:
$(call run_docker_qemu,$(SCRIPTS_DIR)/zxrun.sh,$(filter-out $@,$(MAKECMDGOALS)))
.PHONY: run-term
run-term: manifest
$(call run_docker_qemu_xterm,$(SCRIPTS_DIR)/zxrun.sh,$(filter-out $@,$(MAKECMDGOALS)))
# Creating workspace so you can work locally on recipe source code
# Example:
# $ make workspace target <recipe-name>
.PHONY: workspace
workspace: manifest
# TODO: We need to improve this
$(call run_docker_recipe,$(SCRIPTS_DIR)/zxworkspace.sh,$(filter-out $@,$(MAKECMDGOALS)))
ln -s shared/zondbox-distro/build/workspace/sources sources
.PHONY: dev
dev:
$(call run_dev_environment, $(filter-out $@,$(MAKECMDGOALS)))
# Drop other targets
%:
@: