Adds openocd with nrf support build to the server update function. Adds 2bad8ad2cd889d8c8d255b8e0dc0e7a187b98c9a hci_uart_beacon commit build hex file to project. (#26)
Co-authored-by: Pbopbo <p.obernesser@freenet.de> Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
@@ -1384,7 +1384,141 @@ async def system_update():
|
||||
log.error("poetry install failed: %s", stderr.decode())
|
||||
raise HTTPException(status_code=500, detail=f"poetry install failed: {stderr.decode()}")
|
||||
|
||||
# 3. Restart services via the update script
|
||||
# 3. Clone/update and build sw_openocd if needed
|
||||
openocd_src = os.path.expanduser("~/sw_openocd")
|
||||
openocd_repo_url = "ssh://git@gitea.summitwave.work:222/auracaster/sw_openocd.git"
|
||||
openocd_branch = "change-8818"
|
||||
openocd_marker = os.path.join(openocd_src, ".last_built_commit")
|
||||
openocd_dir = os.path.join(project_root, 'src', 'openocd')
|
||||
|
||||
if not os.path.isdir(openocd_src):
|
||||
log.info("Installing sw_openocd build dependencies...")
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"sudo", "apt", "install", "-y",
|
||||
"git", "build-essential", "libtool", "autoconf", "texinfo",
|
||||
"libusb-1.0-0-dev", "libftdi1-dev", "libhidapi-dev", "pkg-config",
|
||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
log.warning("apt install deps failed: %s", stderr.decode())
|
||||
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"sudo", "apt-get", "install", "-y", "pkg-config", "libjim-dev",
|
||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
log.warning("apt-get install libjim-dev failed: %s", stderr.decode())
|
||||
|
||||
log.info("Cloning sw_openocd branch %s...", openocd_branch)
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"git", "clone", "--branch", openocd_branch, "--single-branch",
|
||||
openocd_repo_url, openocd_src,
|
||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
log.error("git clone sw_openocd failed: %s", stderr.decode())
|
||||
raise HTTPException(status_code=500, detail=f"git clone sw_openocd failed: {stderr.decode()}")
|
||||
else:
|
||||
log.info("Updating sw_openocd...")
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"git", "fetch", "origin", openocd_branch,
|
||||
cwd=openocd_src,
|
||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
await proc.communicate()
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"git", "checkout", openocd_branch,
|
||||
cwd=openocd_src,
|
||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
await proc.communicate()
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"git", "pull",
|
||||
cwd=openocd_src,
|
||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
await proc.communicate()
|
||||
|
||||
# Get current HEAD commit of sw_openocd
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"git", "rev-parse", "HEAD",
|
||||
cwd=openocd_src,
|
||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, _ = await proc.communicate()
|
||||
openocd_commit = stdout.decode().strip()
|
||||
|
||||
last_built = ""
|
||||
if os.path.isfile(openocd_marker):
|
||||
with open(openocd_marker) as f:
|
||||
last_built = f.read().strip()
|
||||
|
||||
if openocd_commit != last_built:
|
||||
log.info("Building sw_openocd (commit %s)...", openocd_commit)
|
||||
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"./bootstrap",
|
||||
cwd=openocd_src,
|
||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
raise HTTPException(status_code=500, detail=f"openocd bootstrap failed: {stderr.decode()}")
|
||||
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"./configure", "--enable-bcm2835gpio", "--enable-sysfsgpio",
|
||||
cwd=openocd_src,
|
||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
raise HTTPException(status_code=500, detail=f"openocd configure failed: {stderr.decode()}")
|
||||
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"make",
|
||||
cwd=openocd_src,
|
||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
raise HTTPException(status_code=500, detail=f"openocd make failed: {stderr.decode()}")
|
||||
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"sudo", "make", "install",
|
||||
cwd=openocd_src,
|
||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
raise HTTPException(status_code=500, detail=f"openocd make install failed: {stderr.decode()}")
|
||||
|
||||
with open(openocd_marker, 'w') as f:
|
||||
f.write(openocd_commit)
|
||||
log.info("sw_openocd built and installed (commit %s).", openocd_commit)
|
||||
else:
|
||||
log.info("sw_openocd up to date (commit %s), skipping build.", openocd_commit)
|
||||
|
||||
# 4. Flash firmware to both SWD interfaces
|
||||
log.info("Flashing firmware...")
|
||||
flash_script = os.path.join(openocd_dir, 'flash.sh')
|
||||
hex_file = os.path.join(openocd_dir, 'merged.hex')
|
||||
|
||||
for interface in ["swd0", "swd1"]:
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"bash", flash_script, "-i", interface, "-f", hex_file,
|
||||
cwd=openocd_dir,
|
||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
log.error("Flash %s failed: %s", interface, stderr.decode())
|
||||
raise HTTPException(status_code=500, detail=f"Flash {interface} failed: {stderr.decode()}")
|
||||
log.info("Flash %s complete.", interface)
|
||||
|
||||
# 5. Restart services via the update script
|
||||
update_script = os.path.join(project_root, 'src', 'service', 'update_and_run_server_and_frontend.sh')
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
"bash", update_script,
|
||||
|
||||
40
src/openocd/flash.sh
Normal file
40
src/openocd/flash.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
INTERFACE="swd0"
|
||||
HEX_FILE=""
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 -f <hex_file> [-i swd0|swd1]"
|
||||
exit 1
|
||||
}
|
||||
|
||||
while getopts "f:i:h" opt; do
|
||||
case "$opt" in
|
||||
f) HEX_FILE="$OPTARG" ;;
|
||||
i)
|
||||
if [[ "$OPTARG" == "swd0" || "$OPTARG" == "swd1" ]]; then
|
||||
INTERFACE="$OPTARG"
|
||||
else
|
||||
usage
|
||||
fi
|
||||
;;
|
||||
h) usage ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ -n "$HEX_FILE" ]] || usage
|
||||
[[ -f "$HEX_FILE" ]] || { echo "HEX file not found: $HEX_FILE"; exit 1; }
|
||||
|
||||
sudo openocd \
|
||||
-f ./raspberrypi-${INTERFACE}.cfg \
|
||||
-c "init" \
|
||||
-c "reset init" \
|
||||
-c "flash banks" \
|
||||
-c "flash write_image $HEX_FILE" \
|
||||
-c "verify_image $HEX_FILE" \
|
||||
-c "reset run" \
|
||||
-c "shutdown"
|
||||
|
||||
echo "Flashing complete."
|
||||
13111
src/openocd/merged.hex
Normal file
13111
src/openocd/merged.hex
Normal file
File diff suppressed because it is too large
Load Diff
@@ -5,4 +5,9 @@ adapter gpio swdio 26
|
||||
#adapter gpio trst 26
|
||||
#reset_config trst_only
|
||||
|
||||
|
||||
source [find target/nordic/nrf54l.cfg]
|
||||
|
||||
flash bank $_CHIPNAME.flash nrf54 0x00000000 0 0 0 $_TARGETNAME
|
||||
|
||||
adapter speed 1000
|
||||
|
||||
@@ -5,4 +5,9 @@ adapter gpio swdio 24
|
||||
#adapter gpio trst 27
|
||||
#reset_config trst_only
|
||||
|
||||
|
||||
source [find target/nordic/nrf54l.cfg]
|
||||
|
||||
flash bank $_CHIPNAME.flash nrf54 0x00000000 0 0 0 $_TARGETNAME
|
||||
|
||||
adapter speed 1000
|
||||
|
||||
Reference in New Issue
Block a user