CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/ardupilotwaf/esp32.py
Views: 1798
1
# encoding: utf-8
2
3
"""
4
Waf tool for ESP32 build
5
"""
6
7
from waflib import Build, ConfigSet, Configure, Context, Task, Utils
8
from waflib import Errors, Logs
9
from waflib.TaskGen import before, after_method, before_method, feature
10
from waflib.Configure import conf
11
from collections import OrderedDict
12
13
import os
14
import shutil
15
import sys
16
import re
17
import pickle
18
import subprocess
19
20
def configure(cfg):
21
mcu_esp32s3 = True if (cfg.variant[0:7] == "esp32s3") else False
22
target = "esp32s3" if mcu_esp32s3 else "esp32"
23
bldnode = cfg.bldnode.make_node(cfg.variant)
24
def srcpath(path):
25
return cfg.srcnode.make_node(path).abspath()
26
def bldpath(path):
27
return bldnode.make_node(path).abspath()
28
29
#Load cmake builder and make
30
cfg.load('cmake')
31
32
#define env and location for the cmake esp32 file
33
env = cfg.env
34
env.AP_HAL_ESP32 = srcpath('libraries/AP_HAL_ESP32/targets/'+target+'/esp-idf')
35
env.AP_PROGRAM_FEATURES += ['esp32_ap_program']
36
37
env.ESP_IDF_PREFIX_REL = 'esp-idf'
38
39
prefix_node = bldnode.make_node(env.ESP_IDF_PREFIX_REL)
40
env.ESP32_TARGET = target
41
env.BUILDROOT = bldpath('')
42
env.SRCROOT = srcpath('')
43
env.APJ_TOOL = srcpath('Tools/scripts/apj_tool.py')
44
45
#Check if esp-idf env are loaded, or load it
46
try:
47
env.IDF = os.environ['IDF_PATH']
48
except:
49
env.IDF = cfg.srcnode.abspath()+"/modules/esp_idf"
50
print("USING EXPRESSIF IDF:"+str(env.IDF))
51
52
#env.append_value('GIT_SUBMODULES', 'esp_idf')
53
54
# delete the output sdkconfig file when the input defaults changes. we take the
55
# stamp as the output so we can compute the path to the sdkconfig, yet it
56
# doesn't have to exist when we're done.
57
class clean_sdkconfig(Task.Task):
58
def keyword(self):
59
return "delete sdkconfig generated from"
60
61
def run(self):
62
prefix = ".clean-stamp-"
63
for out in self.outputs:
64
if not out.name.startswith(prefix):
65
raise ValueError("not a stamp file: "+out)
66
dest = out.parent.abspath()+"/"+out.name[len(prefix):]
67
if os.path.exists(dest):
68
os.unlink(dest)
69
70
# waf needs the output to exist after the task, so touch it
71
open(out.abspath(), "w").close()
72
73
def pre_build(self):
74
"""Configure esp-idf as lib target"""
75
lib_vars = OrderedDict()
76
lib_vars['ARDUPILOT_CMD'] = self.cmd
77
lib_vars['WAF_BUILD_TARGET'] = self.targets
78
lib_vars['ARDUPILOT_LIB'] = self.bldnode.find_or_declare('lib/').abspath()
79
lib_vars['ARDUPILOT_BIN'] = self.bldnode.find_or_declare('lib/bin').abspath()
80
target = self.env.ESP32_TARGET
81
esp_idf = self.cmake(
82
name='esp-idf',
83
cmake_vars=lib_vars,
84
cmake_src='libraries/AP_HAL_ESP32/targets/'+target+'/esp-idf',
85
cmake_bld='esp-idf_build',
86
)
87
88
esp_idf_showinc = esp_idf.build('showinc', target='esp-idf_build/includes.list')
89
90
# task to delete the sdkconfig (thereby causing it to be regenerated) when
91
# the .defaults changes. it uses a stamp to find the sdkconfig. changing
92
# the sdkconfig WILL NOT cause it to be deleted as it's not an input. this
93
# is by design so the user can tweak it for testing purposes.
94
clean_sdkconfig_task = esp_idf_showinc.create_task("clean_sdkconfig",
95
src=self.srcnode.find_or_declare(self.env.AP_HAL_ESP32+"/sdkconfig.defaults"),
96
tgt=self.bldnode.find_or_declare("esp-idf_build/.clean-stamp-sdkconfig"))
97
98
esp_idf_showinc.post()
99
100
# ensure the sdkconfig will be deleted before the cmake configure occurs
101
# that regenerates it
102
esp_idf_showinc.cmake_config_task.set_run_after(clean_sdkconfig_task)
103
104
from waflib import Task
105
class load_generated_includes(Task.Task):
106
"""After includes.list generated include it in env"""
107
always_run = True
108
def run(tsk):
109
bld = tsk.generator.bld
110
includes = bld.bldnode.find_or_declare('esp-idf_build/includes.list').read().split()
111
#print(includes)
112
bld.env.prepend_value('INCLUDES', includes)
113
114
tsk = load_generated_includes(env=self.env)
115
tsk.set_inputs(self.path.find_resource('esp-idf_build/includes.list'))
116
self.add_to_group(tsk)
117
118
119
@feature('esp32_ap_program')
120
@after_method('process_source')
121
def esp32_firmware(self):
122
self.link_task.always_run = True
123
esp_idf = self.bld.cmake('esp-idf')
124
125
build = esp_idf.build('all', target='esp-idf_build/ardupilot.bin')
126
build.post()
127
128
build.cmake_build_task.set_run_after(self.link_task)
129
130
# optional upload is last
131
if self.bld.options.upload:
132
flasher = esp_idf.build('flash')
133
flasher.post()
134
135