Skip to content

Commit 4612577

Browse files
authored
Merge pull request #4998 from willmmiles/fix-4929-sq
Add OTA metadata validation v2
2 parents ec61a35 + d538736 commit 4612577

File tree

16 files changed

+651
-108
lines changed

16 files changed

+651
-108
lines changed

pio-scripts/output_bins.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import shutil
44
import gzip
5+
import json
56

67
OUTPUT_DIR = "build_output{}".format(os.path.sep)
78
#OUTPUT_DIR = os.path.join("build_output")
@@ -22,7 +23,8 @@ def create_release(source):
2223
release_name_def = _get_cpp_define_value(env, "WLED_RELEASE_NAME")
2324
if release_name_def:
2425
release_name = release_name_def.replace("\\\"", "")
25-
version = _get_cpp_define_value(env, "WLED_VERSION")
26+
with open("package.json", "r") as package:
27+
version = json.load(package)["version"]
2628
release_file = os.path.join(OUTPUT_DIR, "release", f"WLED_{version}_{release_name}.bin")
2729
release_gz_file = release_file + ".gz"
2830
print(f"Copying {source} to {release_file}")
Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Import('env')
22
import subprocess
3+
import json
34
import re
45

56
def get_github_repo():
@@ -42,7 +43,7 @@ def get_github_repo():
4243

4344
# Check if it's a GitHub URL
4445
if 'github.com' not in remote_url.lower():
45-
return 'unknown'
46+
return None
4647

4748
# Parse GitHub URL patterns:
4849
# https://github.com/owner/repo.git
@@ -63,17 +64,53 @@ def get_github_repo():
6364
if ssh_match:
6465
return ssh_match.group(1)
6566

66-
return 'unknown'
67+
return None
6768

6869
except FileNotFoundError:
6970
# Git CLI is not installed or not in PATH
70-
return 'unknown'
71+
return None
7172
except subprocess.CalledProcessError:
7273
# Git command failed (e.g., not a git repo, no remote, etc.)
73-
return 'unknown'
74+
return None
7475
except Exception:
7576
# Any other unexpected error
76-
return 'unknown'
77+
return None
7778

78-
repo = get_github_repo()
79-
env.Append(BUILD_FLAGS=[f'-DWLED_REPO=\\"{repo}\\"'])
79+
# WLED version is managed by package.json; this is picked up in several places
80+
# - It's integrated in to the UI code
81+
# - Here, for wled_metadata.cpp
82+
# - The output_bins script
83+
# We always take it from package.json to ensure consistency
84+
with open("package.json", "r") as package:
85+
WLED_VERSION = json.load(package)["version"]
86+
87+
def has_def(cppdefs, name):
88+
""" Returns true if a given name is set in a CPPDEFINES collection """
89+
for f in cppdefs:
90+
if isinstance(f, tuple):
91+
f = f[0]
92+
if f == name:
93+
return True
94+
return False
95+
96+
97+
def add_wled_metadata_flags(env, node):
98+
cdefs = env["CPPDEFINES"].copy()
99+
100+
if not has_def(cdefs, "WLED_REPO"):
101+
repo = get_github_repo()
102+
if repo:
103+
cdefs.append(("WLED_REPO", f"\\\"{repo}\\\""))
104+
105+
cdefs.append(("WLED_VERSION", WLED_VERSION))
106+
107+
# This transforms the node in to a Builder; it cannot be modified again
108+
return env.Object(
109+
node,
110+
CPPDEFINES=cdefs
111+
)
112+
113+
env.AddBuildMiddleware(
114+
add_wled_metadata_flags,
115+
"*/wled_metadata.cpp"
116+
)

pio-scripts/set_version.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

platformio.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ ldscript_4m1m = eagle.flash.4m1m.ld
128128

129129
[scripts_defaults]
130130
extra_scripts =
131-
pre:pio-scripts/set_version.py
132-
pre:pio-scripts/set_repo.py
131+
pre:pio-scripts/set_metadata.py
133132
post:pio-scripts/output_bins.py
134133
post:pio-scripts/strip-floats.py
135134
pre:pio-scripts/user_config_copy.py

tools/cdata.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,6 @@ const char PAGE_dmxmap[] PROGMEM = R"=====()=====";
388388
name: "PAGE_update",
389389
method: "gzip",
390390
filter: "html-minify",
391-
mangle: (str) =>
392-
str
393-
.replace(
394-
/function GetV().*\<\/script\>/gms,
395-
"</script><script src=\"/settings/s.js?p=9\"></script>"
396-
)
397391
},
398392
{
399393
file: "welcome.htm",

wled00/data/update.htm

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,26 @@
1717
}
1818
window.open(getURL("/update?revert"),"_self");
1919
}
20-
function GetV() {/*injected values here*/}
20+
function GetV() {
21+
// Fetch device info via JSON API instead of compiling it in
22+
fetch('/json/info')
23+
.then(response => response.json())
24+
.then(data => {
25+
document.querySelector('.installed-version').textContent = `${data.brand} ${data.ver} (${data.vid})`;
26+
document.querySelector('.release-name').textContent = data.release;
27+
// TODO - assemble update URL
28+
// TODO - can this be done at build time?
29+
if (data.arch == "esp8266") {
30+
toggle('rev');
31+
}
32+
})
33+
.catch(error => {
34+
console.log('Could not fetch device info:', error);
35+
// Fallback to compiled-in value if API call fails
36+
document.querySelector('.installed-version').textContent = 'Unknown';
37+
document.querySelector('.release-name').textContent = 'Unknown';
38+
});
39+
}
2140
</script>
2241
<style>
2342
@import url("style.css");
@@ -27,11 +46,15 @@
2746
<body onload="GetV()">
2847
<h2>WLED Software Update</h2>
2948
<form method='POST' action='./update' id='upd' enctype='multipart/form-data' onsubmit="toggle('upd')">
30-
Installed version: <span class="sip">WLED ##VERSION##</span><br>
49+
Installed version: <span class="sip installed-version">Loading...</span><br>
50+
Release: <span class="sip release-name">Loading...</span><br>
3151
Download the latest binary: <a href="https://github.com/wled-dev/WLED/releases" target="_blank"
3252
style="vertical-align: text-bottom; display: inline-flex;">
3353
<img src="https://img.shields.io/github/release/wled-dev/WLED.svg?style=flat-square"></a><br>
54+
<input type="hidden" name="skipValidation" value="" id="sV">
3455
<input type='file' name='update' required><br> <!--should have accept='.bin', but it prevents file upload from android app-->
56+
<input type='checkbox' onchange="sV.value=checked?1:''" id="skipValidation">
57+
<label for='skipValidation'>Ignore firmware validation</label><br>
3558
<button type="submit">Update!</button><br>
3659
<hr class="sml">
3760
<button id="rev" type="button" onclick="cR()">Revert update</button><br>

wled00/dmx_input.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ static dmx_config_t createConfig()
5555
config.software_version_id = VERSION;
5656
strcpy(config.device_label, "WLED_MM");
5757

58-
const std::string versionString = "WLED_V" + std::to_string(VERSION);
59-
strncpy(config.software_version_label, versionString.c_str(), 32);
58+
const std::string dmxWledVersionString = "WLED_V" + std::to_string(VERSION);
59+
strncpy(config.software_version_label, dmxWledVersionString.c_str(), 32);
6060
config.software_version_label[32] = '\0'; // zero termination in case versionString string was longer than 32 chars
6161

6262
config.personalities[0].description = "SINGLE_RGB";

wled00/e131.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ void prepareArtnetPollReply(ArtPollReply *reply) {
422422

423423
reply->reply_port = ARTNET_DEFAULT_PORT;
424424

425-
char * numberEnd = versionString;
425+
char * numberEnd = (char*) versionString; // strtol promises not to try to edit this.
426426
reply->reply_version_h = (uint8_t)strtol(numberEnd, &numberEnd, 10);
427427
numberEnd++;
428428
reply->reply_version_l = (uint8_t)strtol(numberEnd, &numberEnd, 10);

0 commit comments

Comments
 (0)