Add tlmConfirm to tlm_dl ota packet-structure (#2991)
[ExpressLRS.git] / src / python / build_env_setup.py
blobe33a1863b3228cfd45cb68b02722dd76b5c65fef
1 Import("env", "projenv")
2 import os
3 import shutil
4 import upload_via_esp8266_backpack
5 import esp_compress
6 import elrs_helpers
7 import BFinitPassthrough
8 import ETXinitPassthrough
9 import UnifiedConfiguration
11 def add_target_uploadoption(name: str, desc: str) -> None:
12 # Add an upload target 'uploadforce' that forces update if target mismatch
13 # This must be called after UPLOADCMD is set
14 env.AddCustomTarget(
15 name=name,
16 dependencies="${BUILD_DIR}/${PROGNAME}.bin",
17 title=name,
18 description=desc,
19 actions=env['UPLOADCMD']
22 def get_version(env):
23 return '%s (%s) %s' % (env.get('GIT_VERSION'), env.get('GIT_SHA'), env.get('REG_DOMAIN'))
25 platform = env.get('PIOPLATFORM', '')
26 stm = platform in ['ststm32']
28 target_name = env['PIOENV'].upper()
29 print("PLATFORM : '%s'" % platform)
30 print("BUILD ENV: '%s'" % target_name)
31 print("build version: %s\n\n" % get_version(env))
33 if platform in ['espressif8266']:
34 if "_WIFI" in target_name:
35 env.Replace(UPLOAD_PROTOCOL="custom")
36 env.Replace(UPLOADCMD=upload_via_esp8266_backpack.on_upload)
37 elif "_UART" in target_name:
38 env.Replace(
39 UPLOADER="$PROJECT_DIR/python/external/esptool/esptool.py",
40 UPLOAD_SPEED=460800,
41 UPLOADERFLAGS=[
42 "-b", "$UPLOAD_SPEED", "-p", "$UPLOAD_PORT",
43 "-c", "esp8266", "--before", "default_reset", "--after", "soft_reset", "write_flash"
46 elif "_BETAFLIGHTPASSTHROUGH" in target_name:
47 env.Replace(
48 UPLOADER="$PROJECT_DIR/python/external/esptool/esptool.py",
49 UPLOAD_SPEED=420000,
50 UPLOADERFLAGS=[
51 "--passthrough", "-b", "$UPLOAD_SPEED", "-p", "$UPLOAD_PORT",
52 "-c", "esp8266", "--before", "no_reset", "--after", "soft_reset", "write_flash"
55 env.AddPreAction("upload", BFinitPassthrough.init_passthrough)
57 elif platform in ['espressif32']:
58 if "_WIFI" in target_name:
59 env.Replace(UPLOAD_PROTOCOL="custom")
60 env.Replace(UPLOADCMD=upload_via_esp8266_backpack.on_upload)
61 elif "_UART" in target_name:
62 env.Replace(
63 UPLOADER="$PROJECT_DIR/python/external/esptool/esptool.py",
64 UPLOAD_SPEED=460800
66 if "_ETX" in target_name:
67 env.Replace(UPLOADER="$PROJECT_DIR/python/external/esptool/esptool.py")
68 env.AddPreAction("upload", ETXinitPassthrough.init_passthrough)
69 elif "_BETAFLIGHTPASSTHROUGH" in target_name:
70 if "ESP32S3" in target_name:
71 chip = "esp32-s3"
72 elif "ESP32C3" in target_name:
73 chip = "esp32-c3"
74 else:
75 chip = "esp32"
76 env.Replace(
77 UPLOADER="$PROJECT_DIR/python/external/esptool/esptool.py",
78 UPLOAD_SPEED=420000,
79 UPLOADERFLAGS=[
80 "--passthrough", "-b", "$UPLOAD_SPEED", "-p", "$UPLOAD_PORT",
81 "-c", chip, "--before", "no_reset", "--after", "hard_reset", "write_flash"
84 env.AddPreAction("upload", BFinitPassthrough.init_passthrough)
86 if "_WIFI" in target_name:
87 add_target_uploadoption("uploadconfirm", "Do not upload, just send confirm")
88 if "_TX_" in target_name:
89 env.SetDefault(UPLOAD_PORT="elrs_tx.local")
90 else:
91 env.SetDefault(UPLOAD_PORT="elrs_rx.local")
93 if platform != 'native':
94 add_target_uploadoption("uploadforce", "Upload even if target mismatch")
96 # Remove stale binary so the platform is forced to build a new one and attach options/hardware-layout files
97 try:
98 os.remove(env['PROJECT_BUILD_DIR'] + '/' + env['PIOENV'] +'/'+ env['PROGNAME'] + '.bin')
99 except FileNotFoundError:
100 None
101 env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", UnifiedConfiguration.appendConfiguration)
102 if platform in ['espressif8266'] and "_WIFI" in target_name:
103 env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", esp_compress.compressFirmware)
105 def copyBootApp0bin(source, target, env):
106 file = os.path.join(env.PioPlatform().get_package_dir("framework-arduinoespressif32"), "tools", "partitions", "boot_app0.bin")
107 shutil.copy2(file, os.path.join(env['PROJECT_BUILD_DIR'], env['PIOENV']))
109 if platform in ['espressif32']:
110 env.AddPreAction("$BUILD_DIR/${PROGNAME}.bin", copyBootApp0bin)
112 if platform in ['espressif32', 'espressif8266']:
113 if not os.path.exists('hardware'):
114 elrs_helpers.git_cmd('clone', 'https://github.com/ExpressLRS/targets', 'hardware')