Skip to content

Commit 6324e8f

Browse files
committed
[CI] SPI tests fixed
1 parent da8175b commit 6324e8f

6 files changed

Lines changed: 79 additions & 27 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ wolfboot-align.bin: wolfboot.elf
154154

155155

156156
test-app/image.bin:
157-
make -C test-app TARGET=$(TARGET) EXT_FLASH=$(EXT_FLASH)
157+
make -C test-app TARGET=$(TARGET) EXT_FLASH=$(EXT_FLASH) SPI_FLASH=$(SPI_FLASH)
158158

159159
include tools/test.mk
160160

include/spi_flash.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
#ifndef SPI_FLASH_DRI_H
2828
#define SPI_FLASH_DRI_H
2929

30+
#define SPI_FLASH_SECTOR_SIZE (4096)
31+
#define SPI_FLASH_PAGE_SIZE (256)
32+
3033
#ifdef SPI_FLASH
3134
#include <stdint.h>
3235

33-
#define SPI_FLASH_SECTOR_SIZE (4096)
34-
#define SPI_FLASH_PAGE_SIZE (256)
3536

3637
uint16_t spi_flash_probe(void);
3738
void spi_flash_sector_erase(uint32_t address);

src/loader.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static int wolfBoot_copy_sector(struct wolfBoot_image *src, struct wolfBoot_imag
4444
wb_flash_erase(dst, dst_sector_offset, WOLFBOOT_SECTOR_SIZE);
4545
while (pos < WOLFBOOT_SECTOR_SIZE) {
4646
if (src_sector_offset + pos < (src->fw_size + IMAGE_HEADER_SIZE + FLASHBUFFER_SIZE)) {
47-
ext_flash_read((uint32_t)(src->hdr) + src_sector_offset + pos, (void *)buffer, FLASHBUFFER_SIZE);
47+
ext_flash_read((uint32_t)(src->hdr) + src_sector_offset + pos, (void *)buffer, FLASHBUFFER_SIZE);
4848
wb_flash_write(dst, dst_sector_offset + pos, buffer, FLASHBUFFER_SIZE);
4949
}
5050
pos += FLASHBUFFER_SIZE;
@@ -87,16 +87,16 @@ static int wolfBoot_update(int fallback_allowed)
8787
/* Check the first sector to detect interrupted update */
8888
if ((wolfBoot_get_sector_flag(PART_UPDATE, 0, &flag) < 0) || (flag == SECT_FLAG_NEW))
8989
{
90-
/* In case this is a new update, do the required
91-
* checks on the firmware update
90+
/* In case this is a new update, do the required
91+
* checks on the firmware update
9292
* before starting the swap
9393
*/
94-
if (!update.hdr_ok || (wolfBoot_verify_integrity(&update) < 0)
94+
if (!update.hdr_ok || (wolfBoot_verify_integrity(&update) < 0)
9595
|| (wolfBoot_verify_authenticity(&update) < 0)) {
9696
return -1;
9797
}
9898
#ifndef ALLOW_DOWNGRADE
99-
if ( !fallback_allowed &&
99+
if ( !fallback_allowed &&
100100
(wolfBoot_update_firmware_version() <= wolfBoot_current_firmware_version()) )
101101
return -1;
102102
#endif
@@ -157,11 +157,15 @@ static void wolfBoot_start(void)
157157
{
158158
uint8_t st;
159159
struct wolfBoot_image boot, update;
160-
if ((wolfBoot_get_partition_state(PART_UPDATE, &st) == 0) && (st == IMG_STATE_UPDATING)) {
161-
wolfBoot_update(0);
162-
} else if ((wolfBoot_get_partition_state(PART_BOOT, &st) == 0) && (st == IMG_STATE_TESTING)) {
160+
/* First, check if the BOOT partition is still in TESTING,
161+
* to trigger fallback.
162+
*/
163+
if ((wolfBoot_get_partition_state(PART_BOOT, &st) == 0) && (st == IMG_STATE_TESTING)) {
163164
wolfBoot_update_trigger();
164165
wolfBoot_update(1);
166+
/* Check for new updates in the UPDATE partition */
167+
} else if ((wolfBoot_get_partition_state(PART_UPDATE, &st) == 0) && (st == IMG_STATE_UPDATING)) {
168+
wolfBoot_update(0);
165169
}
166170
if ((wolfBoot_open_image(&boot, PART_BOOT) < 0) ||
167171
(wolfBoot_verify_integrity(&boot) < 0) ||
@@ -171,6 +175,7 @@ static void wolfBoot_start(void)
171175
/* panic */;
172176
}
173177
}
178+
hal_prepare_boot();
174179
do_boot((void *)boot.fw_base);
175180
}
176181

src/spi_flash.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,15 @@ static int spi_flash_write_sb(uint32_t address, const void *data, int len)
150150
wait_busy();
151151
spi_flash_read(address, &verify, 1);
152152
if ((verify & ~(buf[j])) == 0) {
153+
if (verify != buf[j])
154+
return -1;
153155
j++;
154156
len--;
155157
address++;
156158
}
157159
wait_busy();
158160
}
159-
return j;
161+
return 0;
160162
}
161163

162164
/* --- */

test-app/main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333

3434
#ifdef PLATFORM_stm32f4
3535

36+
#ifdef SPI_FLASH
37+
extern void spi_release(void);
38+
#else
39+
#define spi_release() do{}while(0)
40+
#endif
41+
3642

3743
#define UART1 (0x40011000)
3844

@@ -200,7 +206,6 @@ void main(void) {
200206
led_pwm_setup();
201207
pwm_init(CPU_FREQ, 0);
202208

203-
spi_flash_probe();
204209
/* Dim the led by altering the PWM duty-cicle
205210
* in isr_tim2 (timer.c)
206211
*
@@ -281,7 +286,9 @@ void main(void) {
281286
ack(next_seq);
282287
if (next_seq >= tot_len) {
283288
/* Update complete */
289+
spi_flash_probe();
284290
wolfBoot_update_trigger();
291+
spi_release();
285292
hal_flash_lock();
286293
break;
287294
}

tools/test.mk

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,48 @@ $(EXPVER):
66
make -C tools/test-expect-version
77

88
# Testbed actions
9+
#
10+
#
11+
12+
test-spi-on: FORCE
13+
@echo "8" >/sys/class/gpio/unexport || true
14+
@echo "9" >/sys/class/gpio/unexport || true
15+
@echo "10" >/sys/class/gpio/unexport || true
16+
@echo "11" >/sys/class/gpio/unexport || true
17+
@modprobe spi_bcm2835
18+
@modprobe spidev
19+
20+
test-spi-off: FORCE
21+
@rmmod spi_bcm2835
22+
@rmmod spidev
23+
@echo "8" >/sys/class/gpio/export
24+
@echo "9" >/sys/class/gpio/export
25+
@echo "10" >/sys/class/gpio/export
26+
@echo "11" >/sys/class/gpio/export
27+
@echo "in" >/sys/class/gpio/gpio8/direction
28+
@echo "in" >/sys/class/gpio/gpio9/direction
29+
@echo "in" >/sys/class/gpio/gpio10/direction
30+
@echo "in" >/sys/class/gpio/gpio11/direction
31+
932

1033
test-update: test-app/image.bin FORCE
1134
@$(SIGN_TOOL) test-app/image.bin $(PRIVATE_KEY) $(TEST_UPDATE_VERSION) 131072 >/dev/null
1235
@dd if=test-app/image.bin.v$(TEST_UPDATE_VERSION).signed of=test-update.bin bs=1 count=131067
1336
@printf "pBOOT" >> test-update.bin
1437
@make test-reset
1538
@sleep 2
16-
@sudo st-flash --reset write test-update.bin 0x08040000 || \
17-
(make test-reset && sleep 1 && sudo st-flash --reset write test-update.bin 0x08040000) || \
18-
(make test-reset && sleep 1 && sudo st-flash --reset write test-update.bin 0x08040000)
39+
@st-flash --reset write test-update.bin 0x08040000 || \
40+
(make test-reset && sleep 1 && st-flash --reset write test-update.bin 0x08040000) || \
41+
(make test-reset && sleep 1 && st-flash --reset write test-update.bin 0x08040000)
1942

20-
test-update-ext:
43+
test-update-ext: test-app/image.bin FORCE
2144
@$(SIGN_TOOL) test-app/image.bin $(PRIVATE_KEY) $(TEST_UPDATE_VERSION) 524288 >/dev/null
2245
@$$(dd if=/dev/zero bs=1M count=1 | tr '\000' '\377' > test-update.rom)
2346
@dd if=test-app/image.bin.v$(TEST_UPDATE_VERSION).signed of=test-update.rom bs=1 count=524283 conv=notrunc
2447
@printf "pBOOT" | dd of=test-update.rom obs=1 seek=524283 count=5 conv=notrunc
25-
flashrom -c $(SPI_CHIP) -p linux_spi:dev=/dev/spidev0.0 -w update.rom
48+
@make test-spi-on
49+
flashrom -c $(SPI_CHIP) -p linux_spi:dev=/dev/spidev0.0 -w test-update.rom
50+
@make test-spi-off
2651
@make test-reset
2752
@sleep 2
2853
@make clean
@@ -31,24 +56,31 @@ test-erase: FORCE
3156
@echo Mass-erasing the internal flash:
3257
@make test-reset
3358
@sleep 2
34-
@sudo st-flash erase
59+
@st-flash erase
60+
61+
test-erase-ext: FORCE
62+
@make test-spi-on
63+
@echo Mass-erasing the external SPI flash:
64+
flashrom -c $(SPI_CHIP) -p linux_spi:dev=/dev/spidev0.0 -E
65+
@make test-spi-off
3566

3667

3768
test-factory: factory.bin
3869
@make test-reset
3970
@sleep 2
40-
@sudo st-flash --reset write factory.bin 0x08000000 || \
41-
(make test-reset && sleep 1 && sudo st-flash --reset write factory.bin 0x08000000) || \
42-
(make test-reset && sleep 1 && sudo st-flash --reset write factory.bin 0x08000000)
71+
@st-flash --reset write factory.bin 0x08000000 || \
72+
(make test-reset && sleep 1 && st-flash --reset write factory.bin 0x08000000) || \
73+
(make test-reset && sleep 1 && st-flash --reset write factory.bin 0x08000000)
4374

4475
test-reset: FORCE
45-
@sudo st-info --reset
76+
@$$(sleep 1 && st-info --reset) &
4677

4778

4879

4980
## Test cases:
5081

5182
test-01-forward-update-no-downgrade: $(EXPVER) FORCE
83+
@make test-erase
5284
@echo Creating and uploading factory image...
5385
@make test-factory
5486
@echo Expecting version '1'
@@ -67,6 +99,7 @@ test-01-forward-update-no-downgrade: $(EXPVER) FORCE
6799
@echo TEST PASSED
68100

69101
test-02-forward-update-allow-downgrade: $(EXPVER) FORCE
102+
@make test-erase
70103
@echo Creating and uploading factory image...
71104
@make test-factory ALLOW_DOWNGRADE=1
72105
@echo Expecting version '1'
@@ -85,6 +118,7 @@ test-02-forward-update-allow-downgrade: $(EXPVER) FORCE
85118
@echo TEST PASSED
86119

87120
test-03-rollback: $(EXPVER) FORCE
121+
@make test-erase
88122
@echo Creating and uploading factory image...
89123
@make test-factory
90124
@echo Expecting version '1'
@@ -112,7 +146,8 @@ test-11-forward-update-no-downgrade-ECC: $(EXPVER) FORCE
112146
test-13-rollback-ECC: $(EXPVER) FORCE
113147
@make test-03-rollback SIGN=ECC256
114148

115-
test-21-forward-update-no-downgrade-SPI: FORCE
149+
test-21-forward-update-no-downgrade-SPI: $(EXPVER) FORCE
150+
@make test-erase-ext
116151
@echo Creating and uploading factory image...
117152
@make test-factory SPI_FLASH=1
118153
@echo Expecting version '1'
@@ -130,9 +165,10 @@ test-21-forward-update-no-downgrade-SPI: FORCE
130165
@make clean
131166
@echo TEST PASSED
132167

133-
test-23-rollback-SPI:
168+
test-23-rollback-SPI: $(EXPVER) FORCE
169+
@make test-erase-ext
134170
@echo Creating and uploading factory image...
135-
@make test-factory SPI_FLASH=1
171+
@make test-factory SPI_FLASH=1
136172
@echo Expecting version '1'
137173
@$$(test `$(EXPVER)` -eq 1)
138174
@echo
@@ -148,8 +184,9 @@ test-23-rollback-SPI:
148184
@echo
149185
@echo Resetting to trigger rollback...
150186
@make test-reset
187+
@sleep 2
151188
@$$(test `$(EXPVER)` -eq 4)
152189
@make clean
153190
@echo TEST PASSED
154191

155-
test-all: clean test-01-forward-update-no-downgrade test-02-forward-update-allow-downgrade test-03-rollback test-11-forward-update-no-downgrade-ECC test-13-rollback-ECC
192+
test-all: clean test-01-forward-update-no-downgrade test-02-forward-update-allow-downgrade test-03-rollback test-11-forward-update-no-downgrade-ECC test-13-rollback-ECC test-21-forward-update-no-downgrade-SPI test-23-rollback-SPI

0 commit comments

Comments
 (0)