qpi-cli 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qpi_cli/__init__.py +21 -0
- qpi_cli/__main__.py +9 -0
- qpi_cli/cli.py +184 -0
- qpi_cli/commands.py +608 -0
- qpi_cli/core.py +405 -0
- qpi_cli/templates.py +41 -0
- qpi_cli-0.2.0.dist-info/LICENSE +21 -0
- qpi_cli-0.2.0.dist-info/METADATA +307 -0
- qpi_cli-0.2.0.dist-info/RECORD +12 -0
- qpi_cli-0.2.0.dist-info/WHEEL +5 -0
- qpi_cli-0.2.0.dist-info/entry_points.txt +2 -0
- qpi_cli-0.2.0.dist-info/top_level.txt +1 -0
qpi_cli/commands.py
ADDED
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""qpi-cli 各子命令实现。"""
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import shlex
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess
|
|
10
|
+
import time
|
|
11
|
+
|
|
12
|
+
from . import CLI_NAME, __version__
|
|
13
|
+
from .core import (
|
|
14
|
+
BUILD_DIR,
|
|
15
|
+
BUILD_SH,
|
|
16
|
+
FLASH_SH,
|
|
17
|
+
INSTALL_ENV_SH,
|
|
18
|
+
VERSION_TXT,
|
|
19
|
+
banner,
|
|
20
|
+
configured_flash_entry,
|
|
21
|
+
dget,
|
|
22
|
+
dset,
|
|
23
|
+
default_config,
|
|
24
|
+
error,
|
|
25
|
+
flash_entry_error,
|
|
26
|
+
info,
|
|
27
|
+
resolve_flash_entry,
|
|
28
|
+
run_sdk,
|
|
29
|
+
verdict,
|
|
30
|
+
warn,
|
|
31
|
+
)
|
|
32
|
+
from .templates import CODE_WORKSPACE_TMPL, MAIN_C_TMPL, MAKEFILE_TMPL
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# ---------------------------------------------------------------- 子命令 ----
|
|
36
|
+
def parse_dimensions(args):
|
|
37
|
+
"""把 CLI 参数归一化成 (project, rev, os_dim, ver_dim, sec)。"""
|
|
38
|
+
cfg = args.ctx.config
|
|
39
|
+
project = args.project or dget(cfg, "build.project", "QSM565DWF")
|
|
40
|
+
rev = args.rev or args.ctx.current_rev()
|
|
41
|
+
os_dim = args.os or dget(cfg, "build.os", "LINUX")
|
|
42
|
+
ver_dim = args.variant or dget(cfg, "build.version", "STD")
|
|
43
|
+
sec = bool(args.sec)
|
|
44
|
+
return project, rev, os_dim, ver_dim, sec
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def cmd_version(args):
|
|
48
|
+
ctx = args.ctx
|
|
49
|
+
meta = ctx.sdk_meta()
|
|
50
|
+
hdr = ctx.current_header()
|
|
51
|
+
print("%s %s" % (CLI_NAME, __version__))
|
|
52
|
+
print(
|
|
53
|
+
"SDK : %s (%s)"
|
|
54
|
+
% (meta.get("SDK_NAME", "-"), meta.get("SDK_TYPE", "-"))
|
|
55
|
+
)
|
|
56
|
+
print("SDK root : %s" % ctx.root)
|
|
57
|
+
print(
|
|
58
|
+
"Platform : MACHINE=%s DISTRO=%s IMAGE=%s"
|
|
59
|
+
% (
|
|
60
|
+
meta.get("MACHINE", "-"),
|
|
61
|
+
meta.get("DISTRO", "-"),
|
|
62
|
+
meta.get("TARGET_IMAGE", "-"),
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
print(
|
|
66
|
+
"Buildconfig: project=%s rev=%s custom=%s"
|
|
67
|
+
% (
|
|
68
|
+
hdr.get("QUECTEL_PROJECT_NAME", "-"),
|
|
69
|
+
hdr.get("QUECTEL_PROJECT_REV", "-"),
|
|
70
|
+
hdr.get("QUECTEL_CUSTOM_NAME", "-"),
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
print("Flash entry: %s" % (configured_flash_entry(ctx) or "-"))
|
|
74
|
+
return 0
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def cmd_config(args):
|
|
78
|
+
ctx = args.ctx
|
|
79
|
+
if args.init:
|
|
80
|
+
if os.path.isfile(ctx.config_path) and not ctx.read_only and not args.force:
|
|
81
|
+
warn("%s 已存在, 使用 --force 覆盖" % ctx.config_path)
|
|
82
|
+
return 1
|
|
83
|
+
ctx.config = default_config()
|
|
84
|
+
ctx.save_config()
|
|
85
|
+
info("已写入默认配置: %s" % ctx.config_path)
|
|
86
|
+
return 0
|
|
87
|
+
if args.set:
|
|
88
|
+
for item in args.set:
|
|
89
|
+
if "=" not in item:
|
|
90
|
+
error("--set 期望 KEY=VALUE, 实际: %s" % item)
|
|
91
|
+
return 1
|
|
92
|
+
key, value = item.split("=", 1)
|
|
93
|
+
dset(ctx.config, key, value)
|
|
94
|
+
info("已设置 %s = %s" % (key, value))
|
|
95
|
+
ctx.save_config()
|
|
96
|
+
return 0
|
|
97
|
+
if args.get:
|
|
98
|
+
val = dget(ctx.config, args.get)
|
|
99
|
+
if val is None:
|
|
100
|
+
error("没有该配置项: %s" % args.get)
|
|
101
|
+
return 1
|
|
102
|
+
print(val)
|
|
103
|
+
return 0
|
|
104
|
+
print("Config file: %s" % ctx.config_path)
|
|
105
|
+
if ctx.read_only:
|
|
106
|
+
print(" (SDK 根下 .qpi_config.json, 只读覆盖)")
|
|
107
|
+
print(json.dumps(ctx.config, indent=2, ensure_ascii=False))
|
|
108
|
+
return 0
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def cmd_new(args):
|
|
112
|
+
ctx = args.ctx
|
|
113
|
+
app = args.name
|
|
114
|
+
if not re.match(r"^[A-Za-z_][A-Za-z0-9_.-]*$", app):
|
|
115
|
+
error(
|
|
116
|
+
"非法应用名 (仅允许字母/数字/_/./-, 且不能以数字开头): %s" % app
|
|
117
|
+
)
|
|
118
|
+
return 1
|
|
119
|
+
# 应用工程落在 SDK 根下的 projects/ (对外仓库运行时生成, 不纳入版本管理)
|
|
120
|
+
projects_dir = ctx.p(dget(ctx.config, "projects_dir", "projects"))
|
|
121
|
+
app_dir = os.path.join(projects_dir, app)
|
|
122
|
+
if os.path.exists(app_dir) and not args.force:
|
|
123
|
+
error("%s 已存在, 使用 --force 覆盖" % app_dir)
|
|
124
|
+
return 1
|
|
125
|
+
os.makedirs(app_dir, exist_ok=True)
|
|
126
|
+
|
|
127
|
+
with open(os.path.join(app_dir, "main.c"), "w") as fh:
|
|
128
|
+
fh.write(MAIN_C_TMPL % app)
|
|
129
|
+
with open(os.path.join(app_dir, "Makefile"), "w") as fh:
|
|
130
|
+
fh.write(MAKEFILE_TMPL % {"app": app})
|
|
131
|
+
meta = {
|
|
132
|
+
"name": app,
|
|
133
|
+
"sdk": "yocto-h1",
|
|
134
|
+
"board": "QCS6490",
|
|
135
|
+
"target": "qcm6490-idp",
|
|
136
|
+
"created_at": time.strftime("%Y-%m-%d %H:%M:%S"),
|
|
137
|
+
}
|
|
138
|
+
with open(os.path.join(app_dir, "qpi_app.json"), "w") as fh:
|
|
139
|
+
json.dump(meta, fh, indent=2, ensure_ascii=False)
|
|
140
|
+
fh.write("\n")
|
|
141
|
+
with open(os.path.join(app_dir, "%s.code-workspace" % app), "w") as fh:
|
|
142
|
+
fh.write(CODE_WORKSPACE_TMPL % {"app": app})
|
|
143
|
+
|
|
144
|
+
info("已创建应用工程: %s" % app_dir)
|
|
145
|
+
print(" main.c / Makefile / qpi_app.json / %s.code-workspace" % app)
|
|
146
|
+
print(" 打开: code %s" % os.path.join(app_dir, "%s.code-workspace" % app))
|
|
147
|
+
return 0
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def cmd_ls_projects(args):
|
|
151
|
+
ctx = args.ctx
|
|
152
|
+
projects_dir = ctx.p(dget(ctx.config, "projects_dir", "projects"))
|
|
153
|
+
if not os.path.isdir(projects_dir):
|
|
154
|
+
info("还没有应用工程目录: %s" % projects_dir)
|
|
155
|
+
return 0
|
|
156
|
+
names = sorted(
|
|
157
|
+
d
|
|
158
|
+
for d in os.listdir(projects_dir)
|
|
159
|
+
if os.path.isdir(os.path.join(projects_dir, d))
|
|
160
|
+
)
|
|
161
|
+
if args.json:
|
|
162
|
+
print(json.dumps(names, ensure_ascii=False))
|
|
163
|
+
return 0
|
|
164
|
+
if not names:
|
|
165
|
+
info("还没有应用工程: %s" % projects_dir)
|
|
166
|
+
return 0
|
|
167
|
+
banner("应用工程 (%s)" % projects_dir)
|
|
168
|
+
for n in names:
|
|
169
|
+
print(" %s" % n)
|
|
170
|
+
return 0
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _dir_size_mb(path):
|
|
174
|
+
total = 0
|
|
175
|
+
for dirpath, _dirs, files in os.walk(path):
|
|
176
|
+
for f in files:
|
|
177
|
+
fp = os.path.join(dirpath, f)
|
|
178
|
+
try:
|
|
179
|
+
total += os.path.getsize(fp)
|
|
180
|
+
except OSError:
|
|
181
|
+
pass
|
|
182
|
+
return total / 1024.0 / 1024.0
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def cmd_ls_versions(args):
|
|
186
|
+
ctx = args.ctx
|
|
187
|
+
dirs = ctx.rev_dirs()
|
|
188
|
+
cur_rev = ctx.current_rev()
|
|
189
|
+
cur_custom = ctx.current_custom()
|
|
190
|
+
cur_dir = cur_rev + ("_DBG" if "DBG" in cur_custom.split("/") else "")
|
|
191
|
+
|
|
192
|
+
rows = []
|
|
193
|
+
for name, path, state in dirs:
|
|
194
|
+
rows.append(
|
|
195
|
+
{
|
|
196
|
+
"name": name,
|
|
197
|
+
"path": path,
|
|
198
|
+
"state": state,
|
|
199
|
+
"size_mb": round(_dir_size_mb(path), 1),
|
|
200
|
+
"mtime": time.strftime(
|
|
201
|
+
"%Y-%m-%d %H:%M", time.localtime(os.path.getmtime(path))
|
|
202
|
+
),
|
|
203
|
+
"current": name == cur_dir,
|
|
204
|
+
}
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
cur_state = ctx.rev_state(cur_dir)
|
|
208
|
+
|
|
209
|
+
if args.json:
|
|
210
|
+
print(
|
|
211
|
+
json.dumps(
|
|
212
|
+
{"current_rev": cur_dir, "current_state": cur_state, "versions": rows},
|
|
213
|
+
indent=2,
|
|
214
|
+
ensure_ascii=False,
|
|
215
|
+
)
|
|
216
|
+
)
|
|
217
|
+
return 0
|
|
218
|
+
|
|
219
|
+
if not rows:
|
|
220
|
+
info("还没有任何固件 (quectel_build/ 下没有版本目录)")
|
|
221
|
+
info("当前 buildconfig rev: %s — %s" % (cur_dir, cur_state))
|
|
222
|
+
return 0
|
|
223
|
+
|
|
224
|
+
banner("固件版本状态 (共 %d 个)" % len(rows))
|
|
225
|
+
for r in rows:
|
|
226
|
+
mark = "*" if r["current"] else " "
|
|
227
|
+
print(
|
|
228
|
+
"%s %-56s %-14s %8.1f MB %s"
|
|
229
|
+
% (mark, r["name"], r["state"], r["size_mb"], r["mtime"])
|
|
230
|
+
)
|
|
231
|
+
print()
|
|
232
|
+
print(" * = 与当前 buildconfig 匹配的版本")
|
|
233
|
+
print(" 当前 buildconfig rev: %s — %s" % (cur_dir, cur_state))
|
|
234
|
+
return 0
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def cmd_setup(args):
|
|
238
|
+
"""首次宿主环境安装: 调用 SDK 根下的 install_build_env.sh。"""
|
|
239
|
+
ctx = args.ctx
|
|
240
|
+
env_script = ctx.p(INSTALL_ENV_SH)
|
|
241
|
+
if not os.path.isfile(env_script):
|
|
242
|
+
error("未找到 %s" % env_script)
|
|
243
|
+
error(
|
|
244
|
+
"install_build_env.sh 是对外仓库的首次宿主环境安装入口, "
|
|
245
|
+
"请确认 SDK 根目录正确 (可用 --sdk / QPI_SDK_ROOT 指定)"
|
|
246
|
+
)
|
|
247
|
+
return 1
|
|
248
|
+
extra = list(getattr(args, "extra", None) or [])
|
|
249
|
+
# argparse REMAINDER 会保留分隔用的 "--", 去掉它再透传给脚本
|
|
250
|
+
if extra and extra[0] == "--":
|
|
251
|
+
extra = extra[1:]
|
|
252
|
+
|
|
253
|
+
if args.dry_run:
|
|
254
|
+
banner("dry-run: 将要执行的环境安装命令")
|
|
255
|
+
print(" cd %s" % shlex.quote(ctx.root))
|
|
256
|
+
print(
|
|
257
|
+
" bash %s %s"
|
|
258
|
+
% (shlex.quote(env_script), " ".join(shlex.quote(a) for a in extra))
|
|
259
|
+
)
|
|
260
|
+
return 0
|
|
261
|
+
|
|
262
|
+
info("安装宿主构建环境: bash %s %s" % (INSTALL_ENV_SH, " ".join(extra)))
|
|
263
|
+
try:
|
|
264
|
+
proc = subprocess.run(["bash", env_script] + extra, cwd=ctx.root)
|
|
265
|
+
return proc.returncode
|
|
266
|
+
except OSError as exc:
|
|
267
|
+
error("执行 %s 失败: %s" % (env_script, exc))
|
|
268
|
+
return 1
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
# ------------------------------------------------------------- doctor 预检 ---
|
|
272
|
+
def _read_os_release():
|
|
273
|
+
data = {}
|
|
274
|
+
try:
|
|
275
|
+
with open("/etc/os-release", "r") as fh:
|
|
276
|
+
for line in fh:
|
|
277
|
+
line = line.strip()
|
|
278
|
+
if not line or "=" not in line:
|
|
279
|
+
continue
|
|
280
|
+
k, v = line.split("=", 1)
|
|
281
|
+
data[k.strip()] = v.strip().strip('"')
|
|
282
|
+
except OSError:
|
|
283
|
+
pass
|
|
284
|
+
return data
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _read_meminfo():
|
|
288
|
+
data = {}
|
|
289
|
+
try:
|
|
290
|
+
with open("/proc/meminfo", "r") as fh:
|
|
291
|
+
for line in fh:
|
|
292
|
+
if ":" not in line:
|
|
293
|
+
continue
|
|
294
|
+
k, v = line.split(":", 1)
|
|
295
|
+
parts = v.strip().split()
|
|
296
|
+
if parts:
|
|
297
|
+
try:
|
|
298
|
+
data[k.strip()] = int(parts[0]) # kB
|
|
299
|
+
except ValueError:
|
|
300
|
+
pass
|
|
301
|
+
except OSError:
|
|
302
|
+
pass
|
|
303
|
+
return data
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def _check_distro():
|
|
307
|
+
rel = _read_os_release()
|
|
308
|
+
if not rel:
|
|
309
|
+
return "WARN", "无法读取 /etc/os-release", "推荐 Ubuntu 22.04 LTS 宿主"
|
|
310
|
+
distro = rel.get("ID", "?").lower()
|
|
311
|
+
ver = rel.get("VERSION_ID", "?")
|
|
312
|
+
pretty = rel.get("PRETTY_NAME", distro)
|
|
313
|
+
if distro == "ubuntu" and ver.startswith("22.04"):
|
|
314
|
+
return "PASS", pretty, "推荐版本, 与 SDK 验证环境一致"
|
|
315
|
+
if distro in ("ubuntu", "debian"):
|
|
316
|
+
return "WARN", pretty, "推荐 Ubuntu 22.04 LTS, 请自行确认依赖兼容"
|
|
317
|
+
return "FAIL", pretty, "SDK 仅验证 Ubuntu 22.04 LTS, 其他发行版可能失败"
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def _check_disk(root):
|
|
321
|
+
try:
|
|
322
|
+
free = shutil.disk_usage(root).free
|
|
323
|
+
except OSError as exc:
|
|
324
|
+
return "WARN", "无法获取磁盘信息 (%s)" % exc, "确保工作分区可用空间 ≥300GB"
|
|
325
|
+
gb = free / 1024.0 / 1024.0 / 1024.0
|
|
326
|
+
human = "%.1f GB 可用 (%s)" % (gb, root)
|
|
327
|
+
if gb >= 300:
|
|
328
|
+
return "PASS", human, "满足 ≥300GB 建议"
|
|
329
|
+
if gb >= 50:
|
|
330
|
+
return "WARN", human, "BitBake 构建建议预留 ≥300GB 可用空间"
|
|
331
|
+
return "FAIL", human, "可用空间严重不足, 建议 ≥300GB"
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def _check_swap():
|
|
335
|
+
mem = _read_meminfo()
|
|
336
|
+
swap_kb = mem.get("SwapTotal")
|
|
337
|
+
if swap_kb is None:
|
|
338
|
+
return "WARN", "无法读取 /proc/meminfo", "建议配置 >32GB swap"
|
|
339
|
+
gb = swap_kb / 1024.0 / 1024.0
|
|
340
|
+
human = "%.1f GB" % gb
|
|
341
|
+
if gb > 32:
|
|
342
|
+
return "PASS", human, "满足 >32GB 建议"
|
|
343
|
+
if gb > 0:
|
|
344
|
+
return "WARN", human, "Swap 偏小, BitBake 建议 >32GB"
|
|
345
|
+
return "WARN", human, "未检测到 Swap, BitBake 并行构建建议配置 >32GB"
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def _check_memory():
|
|
349
|
+
mem = _read_meminfo()
|
|
350
|
+
total_kb = mem.get("MemTotal")
|
|
351
|
+
if total_kb is None:
|
|
352
|
+
return "WARN", "无法读取 /proc/meminfo", "建议 ≥16GB 内存"
|
|
353
|
+
gb = total_kb / 1024.0 / 1024.0
|
|
354
|
+
human = "%.1f GB" % gb
|
|
355
|
+
if gb >= 16:
|
|
356
|
+
return "PASS", human, "满足 ≥16GB 建议"
|
|
357
|
+
return "WARN", human, "内存偏小, 构建可能较慢, 建议 ≥16GB"
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def _check_userns():
|
|
361
|
+
"""检查 BitBake 用户命名空间可用性 (Ubuntu 23.10+ 限制)。"""
|
|
362
|
+
clone = None
|
|
363
|
+
maxns = None
|
|
364
|
+
try:
|
|
365
|
+
with open("/proc/sys/kernel/unprivileged_userns_clone", "r") as fh:
|
|
366
|
+
clone = int(fh.read().strip())
|
|
367
|
+
except (OSError, ValueError):
|
|
368
|
+
clone = None
|
|
369
|
+
try:
|
|
370
|
+
with open("/proc/sys/user/max_user_namespaces", "r") as fh:
|
|
371
|
+
maxns = int(fh.read().strip())
|
|
372
|
+
except (OSError, ValueError):
|
|
373
|
+
maxns = None
|
|
374
|
+
|
|
375
|
+
if clone == 0:
|
|
376
|
+
return (
|
|
377
|
+
"FAIL",
|
|
378
|
+
"kernel.unprivileged_userns_clone=0",
|
|
379
|
+
"BitBake 用户命名空间不可用, 请在 build.sh 前执行 relax_userns_for_bitbake",
|
|
380
|
+
)
|
|
381
|
+
if maxns is not None and maxns == 0:
|
|
382
|
+
return (
|
|
383
|
+
"FAIL",
|
|
384
|
+
"user.max_user_namespaces=0",
|
|
385
|
+
"BitBake 用户命名空间不可用, 请在 build.sh 前执行 relax_userns_for_bitbake",
|
|
386
|
+
)
|
|
387
|
+
if clone is None and maxns is None:
|
|
388
|
+
return (
|
|
389
|
+
"WARN",
|
|
390
|
+
"无法读取 userns 相关 sysctl",
|
|
391
|
+
"若在 Ubuntu 23.10+ 上构建失败, 请执行 relax_userns_for_bitbake",
|
|
392
|
+
)
|
|
393
|
+
detail = "unprivileged_userns_clone=%s max_user_namespaces=%s" % (
|
|
394
|
+
"n/a" if clone is None else clone,
|
|
395
|
+
"n/a" if maxns is None else maxns,
|
|
396
|
+
)
|
|
397
|
+
return "PASS", detail, "BitBake 用户命名空间可用"
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
def cmd_doctor(args):
|
|
401
|
+
"""只读预检: 不改动系统, 逐项给出 PASS/WARN/FAIL 与建议。"""
|
|
402
|
+
ctx = args.ctx
|
|
403
|
+
banner("qpi-cli doctor — 宿主环境预检 (只读)")
|
|
404
|
+
print(" SDK root: %s\n" % ctx.root)
|
|
405
|
+
|
|
406
|
+
results = []
|
|
407
|
+
|
|
408
|
+
state, detail, hint = _check_distro()
|
|
409
|
+
verdict(state, "发行版 / 版本", "%s — %s" % (detail, hint))
|
|
410
|
+
results.append(state)
|
|
411
|
+
|
|
412
|
+
state, detail, hint = _check_disk(ctx.root)
|
|
413
|
+
verdict(state, "可用磁盘 (≥300GB)", "%s — %s" % (detail, hint))
|
|
414
|
+
results.append(state)
|
|
415
|
+
|
|
416
|
+
state, detail, hint = _check_swap()
|
|
417
|
+
verdict(state, "Swap (>32GB)", "%s — %s" % (detail, hint))
|
|
418
|
+
results.append(state)
|
|
419
|
+
|
|
420
|
+
state, detail, hint = _check_memory()
|
|
421
|
+
verdict(state, "内存", "%s — %s" % (detail, hint))
|
|
422
|
+
results.append(state)
|
|
423
|
+
|
|
424
|
+
has_build = os.path.isfile(ctx.p(BUILD_SH))
|
|
425
|
+
verdict(
|
|
426
|
+
"PASS" if has_build else "FAIL",
|
|
427
|
+
"构建入口 build.sh",
|
|
428
|
+
ctx.p(BUILD_SH) if has_build else "缺失: %s" % ctx.p(BUILD_SH),
|
|
429
|
+
)
|
|
430
|
+
results.append("PASS" if has_build else "FAIL")
|
|
431
|
+
|
|
432
|
+
has_ver = os.path.isfile(ctx.p(VERSION_TXT))
|
|
433
|
+
verdict(
|
|
434
|
+
"PASS" if has_ver else "WARN",
|
|
435
|
+
"平台标识 VERSION.txt",
|
|
436
|
+
ctx.p(VERSION_TXT) if has_ver else "缺失 (可选, 建议拉取完整仓库)",
|
|
437
|
+
)
|
|
438
|
+
results.append("PASS" if has_ver else "WARN")
|
|
439
|
+
|
|
440
|
+
has_install = os.path.isfile(ctx.p(INSTALL_ENV_SH))
|
|
441
|
+
verdict(
|
|
442
|
+
"PASS" if has_install else "WARN",
|
|
443
|
+
"环境安装 install_build_env.sh",
|
|
444
|
+
ctx.p(INSTALL_ENV_SH)
|
|
445
|
+
if has_install
|
|
446
|
+
else "缺失 (首次安装入口, 可用 qpi-cli setup 定位)",
|
|
447
|
+
)
|
|
448
|
+
results.append("PASS" if has_install else "WARN")
|
|
449
|
+
|
|
450
|
+
entry_err = flash_entry_error(configured_flash_entry(ctx))
|
|
451
|
+
entry = resolve_flash_entry(ctx)
|
|
452
|
+
entry_abs = ctx.p(entry)
|
|
453
|
+
if entry_err:
|
|
454
|
+
verdict("FAIL", "烧录入口 FLASH_ENTRY", entry_err)
|
|
455
|
+
results.append("FAIL")
|
|
456
|
+
elif not os.path.isfile(entry_abs):
|
|
457
|
+
verdict(
|
|
458
|
+
"WARN",
|
|
459
|
+
"烧录入口 FLASH_ENTRY",
|
|
460
|
+
"缺失: %s (FLASH_ENTRY 与回落路径均不存在)" % entry_abs,
|
|
461
|
+
)
|
|
462
|
+
results.append("WARN")
|
|
463
|
+
elif entry_abs.lower().endswith(".sh") and not os.access(entry_abs, os.X_OK):
|
|
464
|
+
verdict("WARN", "烧录入口 FLASH_ENTRY", "存在但不可执行: %s" % entry_abs)
|
|
465
|
+
results.append("WARN")
|
|
466
|
+
else:
|
|
467
|
+
verdict("PASS", "烧录入口 FLASH_ENTRY", entry_abs)
|
|
468
|
+
results.append("PASS")
|
|
469
|
+
|
|
470
|
+
state, detail, hint = _check_userns()
|
|
471
|
+
verdict(state, "BitBake 用户命名空间", "%s — %s" % (detail, hint))
|
|
472
|
+
results.append(state)
|
|
473
|
+
|
|
474
|
+
n_pass = results.count("PASS")
|
|
475
|
+
n_warn = results.count("WARN")
|
|
476
|
+
n_fail = results.count("FAIL")
|
|
477
|
+
print()
|
|
478
|
+
banner("总结: %d PASS / %d WARN / %d FAIL" % (n_pass, n_warn, n_fail))
|
|
479
|
+
if n_fail:
|
|
480
|
+
error("存在 FAIL 项, 建议修复后再开始构建")
|
|
481
|
+
return 1
|
|
482
|
+
if n_warn:
|
|
483
|
+
warn("存在 WARN 项, 可视情况继续")
|
|
484
|
+
else:
|
|
485
|
+
info("预检全部通过")
|
|
486
|
+
return 0
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
def cmd_build(args):
|
|
490
|
+
ctx = args.ctx
|
|
491
|
+
project, rev, os_dim, ver_dim, sec = parse_dimensions(args)
|
|
492
|
+
|
|
493
|
+
cfg_cmd = "buildconfig %s %s %s %s" % (
|
|
494
|
+
shlex.quote(project),
|
|
495
|
+
shlex.quote(rev),
|
|
496
|
+
shlex.quote(os_dim),
|
|
497
|
+
shlex.quote(ver_dim),
|
|
498
|
+
)
|
|
499
|
+
if sec:
|
|
500
|
+
cfg_cmd += " SEC"
|
|
501
|
+
body = "\n".join([cfg_cmd, "buildall"])
|
|
502
|
+
|
|
503
|
+
banner("构建计划 (Build plan)")
|
|
504
|
+
print(" project : %s" % project)
|
|
505
|
+
print(" rev : %s" % rev)
|
|
506
|
+
print(" OS : %s" % os_dim)
|
|
507
|
+
print(" VERSION : %s%s" % (ver_dim, " + SECBOOT" if sec else ""))
|
|
508
|
+
print(" target : %s" % ctx.sdk_meta().get("TARGET_IMAGE", "quecpi-image"))
|
|
509
|
+
print()
|
|
510
|
+
info("运行: %s && buildall (完整 bitbake 构建, 耗时较长)" % cfg_cmd)
|
|
511
|
+
|
|
512
|
+
rc = run_sdk(body, ctx.root, verbose=args.verbose, dry_run=args.dry_run)
|
|
513
|
+
if rc == 0 and not args.dry_run:
|
|
514
|
+
dset(ctx.config, "build.project", project)
|
|
515
|
+
dset(ctx.config, "build.rev", rev)
|
|
516
|
+
dset(ctx.config, "build.os", os_dim)
|
|
517
|
+
dset(ctx.config, "build.version", ver_dim)
|
|
518
|
+
ctx.save_config()
|
|
519
|
+
info("构建完成, 配置已回写: %s" % ctx.config_path)
|
|
520
|
+
return rc
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
def cmd_package(args):
|
|
524
|
+
ctx = args.ctx
|
|
525
|
+
info("打包固件 (a_key_generation + deb-publish)")
|
|
526
|
+
rc = run_sdk("buildpackage", ctx.root, verbose=args.verbose, dry_run=args.dry_run)
|
|
527
|
+
if rc == 0 and not args.dry_run:
|
|
528
|
+
rev = ctx.current_rev()
|
|
529
|
+
custom = ctx.current_custom()
|
|
530
|
+
out = rev + ("_DBG" if "DBG" in custom.split("/") else "")
|
|
531
|
+
info("固件输出目录: %s" % ctx.p("quectel_build", out))
|
|
532
|
+
return rc
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
def cmd_flash(args):
|
|
536
|
+
ctx = args.ctx
|
|
537
|
+
storage = args.storage or "ufs"
|
|
538
|
+
|
|
539
|
+
entry_err = flash_entry_error(configured_flash_entry(ctx))
|
|
540
|
+
if entry_err:
|
|
541
|
+
error(entry_err)
|
|
542
|
+
return 1
|
|
543
|
+
entry = resolve_flash_entry(ctx)
|
|
544
|
+
entry_abs = ctx.p(entry)
|
|
545
|
+
if not os.path.isfile(entry_abs):
|
|
546
|
+
error("烧录入口脚本不存在: %s" % entry_abs)
|
|
547
|
+
warn("检查 tools/VERSION.txt 的 FLASH_ENTRY 或回落路径 %s" % FLASH_SH)
|
|
548
|
+
return 1
|
|
549
|
+
|
|
550
|
+
info("烧录固件 (storage=%s)" % storage)
|
|
551
|
+
print(" entry : %s" % entry_abs)
|
|
552
|
+
if args.dry_run:
|
|
553
|
+
banner("dry-run: 将要执行的烧录命令")
|
|
554
|
+
print(" cd %s" % shlex.quote(ctx.root))
|
|
555
|
+
print(" source %s" % shlex.quote(BUILD_SH))
|
|
556
|
+
print(" flash %s" % shlex.quote(storage))
|
|
557
|
+
print(" # FLASH_ENTRY 已解析为: %s" % entry_abs)
|
|
558
|
+
return 0
|
|
559
|
+
return run_sdk(
|
|
560
|
+
"flash %s" % shlex.quote(storage),
|
|
561
|
+
ctx.root,
|
|
562
|
+
verbose=args.verbose,
|
|
563
|
+
dry_run=False,
|
|
564
|
+
)
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
def cmd_kernel(args):
|
|
568
|
+
ctx = args.ctx
|
|
569
|
+
if args.menuconfig:
|
|
570
|
+
body = "bitbake -c menuconfig virtual/kernel"
|
|
571
|
+
info("打开内核 menuconfig")
|
|
572
|
+
elif args.dtb:
|
|
573
|
+
body = "builddtb"
|
|
574
|
+
info("重编 DTB (builddtb)")
|
|
575
|
+
else:
|
|
576
|
+
body = "buildkernel"
|
|
577
|
+
info("重编内核 (buildkernel)")
|
|
578
|
+
return run_sdk(body, ctx.root, verbose=args.verbose, dry_run=args.dry_run)
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
def cmd_clean(args):
|
|
582
|
+
ctx = args.ctx
|
|
583
|
+
targets = []
|
|
584
|
+
if args.packages:
|
|
585
|
+
targets += [path for _name, path in ctx.firmware_dirs()]
|
|
586
|
+
if args.build:
|
|
587
|
+
targets.append(ctx.p(BUILD_DIR, "tmp-glibc"))
|
|
588
|
+
|
|
589
|
+
if not targets:
|
|
590
|
+
info(
|
|
591
|
+
"未选择清理对象。选项: --packages (已打包固件) / --build (bitbake tmp 目录)"
|
|
592
|
+
)
|
|
593
|
+
info("示例: qpi-cli clean --packages --yes")
|
|
594
|
+
return 0
|
|
595
|
+
|
|
596
|
+
banner("即将删除 (%d 项)" % len(targets))
|
|
597
|
+
for t in targets:
|
|
598
|
+
print(" %s" % t)
|
|
599
|
+
|
|
600
|
+
if not args.yes:
|
|
601
|
+
warn("该操作具有破坏性; 追加 --yes 以确认")
|
|
602
|
+
return 1
|
|
603
|
+
|
|
604
|
+
for t in targets:
|
|
605
|
+
if os.path.exists(t):
|
|
606
|
+
shutil.rmtree(t, ignore_errors=True)
|
|
607
|
+
info("已删除 %s" % t)
|
|
608
|
+
return 0
|