From ca7ae6df6c2c2e5e47591265ec83a9098b9cbc35 Mon Sep 17 00:00:00 2001 From: nearology Date: Mon, 9 Nov 2026 20:48:32 +0330 Subject: [PATCH] =?UTF-8?q?=D8=A7=D8=B5=D9=84=D8=A7=D8=AD=20=D9=88=D8=B1?= =?UTF-8?q?=DA=A9=20=D9=81=D9=84=D9=88=20=D9=81=D9=84=D8=B4=20u-boot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/uboot-transfer.yml | 4 ++-- firmware/README.md | 18 ++++++++++-------- scripts/serial_command.py | 25 ++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/.gitea/workflows/uboot-transfer.yml b/.gitea/workflows/uboot-transfer.yml index a2732c4..28ec48d 100644 --- a/.gitea/workflows/uboot-transfer.yml +++ b/.gitea/workflows/uboot-transfer.yml @@ -1,4 +1,4 @@ -name: Transfer U-Boot to RAM +name: Transfer, Write and Verify U-Boot on: workflow_dispatch: @@ -11,6 +11,6 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - - name: Transfer firmware and verify RAM contents + - name: Transfer firmware, write SPI flash and verify read-back run: | /usr/bin/python3 scripts/serial_command.py transfer diff --git a/firmware/README.md b/firmware/README.md index 6a96a4e..9c67382 100644 --- a/firmware/README.md +++ b/firmware/README.md @@ -1,10 +1,12 @@ -Place `u-boot-sunxi-with-spl.bin` in this directory before running the -Transfer U-Boot to RAM workflow. +Place `u-boot-sunxi-with-spl.bin` here before running the workflow. +The existing TFTP server (`serverip`) must serve this directory as its root. +Checkout alone does not publish files over TFTP. -The existing TFTP server (`serverip` in U-Boot) must serve this directory -as its TFTP root, so the file is available as `u-boot-sunxi-with-spl.bin`. -Checking out this repository alone does not publish files over TFTP. +The workflow clears stale `filesize`, requires a successful TFTP transfer, +and checks hexadecimal `filesize` against both the transfer count and local +file size (32 through 0x200000 bytes). It compares the first 32 RAM bytes +with the local file, probes SPI flash, writes at offset 0, reads back to +0x42800000 and compares the full transferred length with `cmp.b`. -The workflow uses the current U-Boot network settings. It verifies the -transferred size and the first 32 bytes against this local file. It does -not erase or write SPI flash, save the environment, or boot the image. +No erase, reboot or saveenv command is issued. Any failed or unverified +command stops execution; flash writes are never automatically retried. diff --git a/scripts/serial_command.py b/scripts/serial_command.py index 70fbe19..e6bac86 100644 --- a/scripts/serial_command.py +++ b/scripts/serial_command.py @@ -84,8 +84,10 @@ class UBoot: def transfer(cli, firmware): image = firmware.read_bytes() - if not 32 <= len(image) <= 0x02000000: - raise RuntimeError("Firmware must contain at least 32 bytes and fit RAM at 0x42000000") + if not 32 <= len(image) <= 0x200000: + raise RuntimeError("Firmware size must be between 32 and 0x200000 bytes") + # Invalidate any previous transfer length before attempting a new transfer. + cli.command("setenv filesize") output = cli.command( "tftp 0x42000000 u-boot-sunxi-with-spl.bin", r"^Bytes transferred = \d+", timeout=120, @@ -106,7 +108,24 @@ def transfer(cli, firmware): dumped.extend(bytes.fromhex(rows[0])) if dumped != image[:32]: raise RuntimeError("First 32 bytes in RAM differ from the local firmware file") - print("\nTransfer verified: size and first 32 bytes match; no flash write performed.") + print("\nTransfer verified: size and first 32 bytes match.") + cli.command("sf probe 0:0", r"^SF: Detected .+", timeout=20) + cli.command( + "sf write 0x42000000 0x0 ${filesize}", + rf"^SF: {len(image)} bytes @ 0x0 Written: OK\s*$", timeout=120, + ) + cli.command( + "sf read 0x42800000 0x0 ${filesize}", + rf"^SF: {len(image)} bytes @ 0x0 Read: OK\s*$", timeout=120, + ) + output = cli.command( + "cmp.b 0x42000000 0x42800000 ${filesize}", + r"^Total of \d+ byte\(s\) were the same", timeout=60, + ) + compared = re.findall(r"^Total of (\d+) byte\(s\) were the same", output, re.MULTILINE) + if compared != [str(len(image))]: + raise RuntimeError("Flash comparison byte count differs from firmware size") + print("\nU-Boot flash write and full read-back comparison verified.") def main():