diff --git a/makefiles/boot/riotboot.mk b/makefiles/boot/riotboot.mk index 1d984f6a8a..d4a6ab6c72 100644 --- a/makefiles/boot/riotboot.mk +++ b/makefiles/boot/riotboot.mk @@ -13,13 +13,9 @@ BINDIR_APP = $(BINDIR)/$(APPLICATION) # export SLOT0_OFFSET SLOT0_LEN SLOT1_OFFSET SLOT1_LEN -# Mandatory APP_VER, set to epoch by default, or "0" for CI build -ifeq (1, RIOT_CI_BUILD) - APP_VER ?= 0 -else - EPOCH := $(shell date +%s) - APP_VER ?= $(EPOCH) -endif +# Mandatory APP_VER, set to epoch by default +EPOCH := $(shell date +%s) +APP_VER ?= $(EPOCH) # Final target for slot 0 with riot_hdr SLOT0_RIOT_BIN = $(BINDIR_APP)-slot0.$(APP_VER).riot.bin diff --git a/tests/riotboot/Makefile b/tests/riotboot/Makefile index a170b83957..31963ada8b 100644 --- a/tests/riotboot/Makefile +++ b/tests/riotboot/Makefile @@ -16,11 +16,6 @@ DEVELHELP ?= 1 # Change this to 0 show compiler invocation lines by default: QUIET ?= 1 -# The test script assumes initially version "0" is flashed, -# as done by the CI. -# Thus default to that (instead of epoch set by makefiles/boot/riotboot.inc.mk). -APP_VER?=0 - # Ensure both slot bin files are always generated and linked to avoid compiling # during the test. This ensures that "BUILD_IN_DOCKER=1 make test" # can rely on them being present without having to trigger re-compilation. diff --git a/tests/riotboot/README.md b/tests/riotboot/README.md index 589d2494e5..01e465f575 100644 --- a/tests/riotboot/README.md +++ b/tests/riotboot/README.md @@ -27,14 +27,14 @@ functionality: This will: -1. flash bootloader and slot0 with APP_VER=0, invalidate slot1 -2. verify slot0 has been booted and has APP_VER set to 0 +1. flash bootloader and slot0, invalidate slot1 +2. get the running slot and current APP_VER -3. flash slot1 with APP_VER set to 1 -4. verify slot1 has booted and shows APP_VER==1 +3. flash slot1 with APP_VER + 1 +4. verify slot1 has booted and shows version = APP_VER + 1 -5. flash slot0 with APP_VER set to 2 -6. verify slot0 has booted and shows APP_VER==2 +5. flash slot0 with APP_VER + 2 +4. verify slot0 has booted and shows version = APP_VER + 2 -If this test runs correctly, it shows that riotboot's basic functions and are +If this test runs correctly, it shows that riotboot's basic functions are working properly on the target board. diff --git a/tests/riotboot/tests/01-run.py b/tests/riotboot/tests/01-run.py new file mode 100755 index 0000000000..db9bf8fd7d --- /dev/null +++ b/tests/riotboot/tests/01-run.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2018 Federico Pellegrin +# Copyright (C) 2019 Francisco Molina +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +import sys +import subprocess +from testrunner import run + + +def flash_slot(slotnum, version): + cmd = [ + "make", + "RIOTBOOT_SKIP_COMPILE=1", + "riotboot/flash-slot{}".format(slotnum), + "APP_VER={}".format(version), + ] + assert subprocess.call(cmd) == 0 + + +def assert_check_slot(child, slotnum, version): + # Check if it's running on the expected slot + child.expect_exact('>') + child.sendline("curslotnr") + child.expect_exact("Current slot={}".format(slotnum)) + + # Ask for current slot header info and check for basic output integrity + child.expect_exact('>') + child.sendline("curslothdr") + # Magic number is "RIOT" (always in little endian) + child.expect_exact("Image magic_number: 0x544f4952") + # Other info is hardware/app dependent so we just check basic compliance + child.expect_exact("Image Version: {0:#0{1}x}".format(version, 10)) + child.expect(r"Image start address: 0x[0-9a-fA-F]{8}\r\n") + child.expect(r"Header chksum: 0x[0-9a-fA-F]{8}\r\n") + + # Ask for address of slot 0 + child.expect_exact('>') + child.sendline("getslotaddr 0") + child.expect(r"Slot 0 address=0x[0-9a-fA-F]{8}\r\n") + + # Ask for data of all slots + child.expect_exact('>') + child.sendline("dumpaddrs") + child.expect(r"slot 0: metadata: 0x[0-9a-fA-F]{1,8} " + r"image: 0x[0-9a-fA-F]{8}\r\n") + child.expect(r"slot 1: metadata: 0x[0-9a-fA-F]{1,8} " + r"image: 0x[0-9a-fA-F]{8}\r\n") + child.expect_exact('>') + + +def testfunc(child): + # Ask for current slot, should be 0 or 1 + child.expect_exact('>') + child.sendline("curslotnr") + child.expect(r"Current slot=([0-1])") + slotnum = int(child.match.group(1)) + + # Ask for current APP_VER + child.expect_exact('>') + child.sendline("curslothdr") + child.expect(r"Image Version: (?P0x[0-9a-fA-F]{8})\r\n") + current_app_ver = int(child.match.group("app_ver"), 16) + + # Flash to both slots and verify basic functions + for version in [current_app_ver + 1, current_app_ver + 2]: + slotnum = slotnum ^ 1 + flash_slot(slotnum, version) + assert_check_slot(child, slotnum, version) + + print("TEST PASSED") + + +if __name__ == "__main__": + sys.exit(run(testfunc)) diff --git a/tests/riotboot/tests/01_test_slot_selection.sh b/tests/riotboot/tests/01_test_slot_selection.sh deleted file mode 100755 index 4611ea2d4e..0000000000 --- a/tests/riotboot/tests/01_test_slot_selection.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -export RIOTBOOT_SKIP_COMPILE=1 -set -e - -${APPDIR}/tests/common/assert_slotnum.py 0 0 - -APP_VER=1 make -C${APPDIR} riotboot/flash-slot1 -${APPDIR}/tests/common/assert_slotnum.py 1 1 - -APP_VER=2 make -C${APPDIR} riotboot/flash-slot0 -${APPDIR}/tests/common/assert_slotnum.py 0 2 - -echo "[TEST PASSED]" diff --git a/tests/riotboot/tests/common/assert_slotnum.py b/tests/riotboot/tests/common/assert_slotnum.py deleted file mode 100755 index 6d1ccdc40a..0000000000 --- a/tests/riotboot/tests/common/assert_slotnum.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright (C) 2018 Federico Pellegrin -# -# This file is subject to the terms and conditions of the GNU Lesser -# General Public License v2.1. See the file LICENSE in the top level -# directory for more details. - -import sys -from testrunner import run - -slotnum = int(sys.argv[1]) -app_ver = int(sys.argv[2]) -print("expecting slot number %s, app_ver %s" % (slotnum, app_ver)) - - -def testfunc(child): - global slotnum - global app_ver - - # Ask for current slot, should be 0 or 1 - child.sendline("curslotnr") - child.expect("Current slot=%s" % (slotnum)) - child.expect('>') - - # Ask for current slot header info and checks for basic output integrity - child.sendline("curslothdr") - # Magic number is "RIOT" (always in little endian) - child.expect_exact("Image magic_number: 0x544f4952") - # Other info is hardware/app dependent so we just check basic compliance - child.expect("Image Version: %s" % ("{0:#0{1}x}".format(app_ver, 10))) - child.expect("Image start address: 0x[0-9a-fA-F]{8}") - child.expect("Header chksum: 0x[0-9a-fA-F]{8}") - child.expect('>') - - # Ask for address of slot 0 - child.sendline("getslotaddr 0") - child.expect("Slot 0 address=0x[0-9a-fA-F]{8}") - child.expect('>') - - # Ask for data of all slots - child.sendline("dumpaddrs") - child.expect("slot 0: metadata: 0x[0-9a-fA-F]{1,8} image: 0x[0-9a-fA-F]{8}") - child.expect('>') - - -if __name__ == "__main__": - sys.exit(run(testfunc))