From 3f8784782b3de17318415987fb5802b655117b7f Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 9 Nov 2021 16:13:24 +0100 Subject: [PATCH 1/4] style(chainloader): rename chainloader to seed --- Makefile | 22 +++++++++---------- {chainloader => seed}/Makefile | 0 .../include/common/status_led.h | 0 .../include/common/stdbool.h | 0 {chainloader => seed}/include/common/stddef.h | 0 {chainloader => seed}/include/common/utils.h | 0 .../include/kernel/chainload.h | 0 {chainloader => seed}/include/kernel/kernel.h | 0 {chainloader => seed}/include/kernel/load.h | 0 .../include/kernel/mailbox.h | 0 .../include/kernel/mini_uart.h | 0 .../include/kernel/peripherals/base.h | 0 .../include/kernel/peripherals/gpio.h | 0 .../include/kernel/peripherals/mailbox.h | 0 .../include/kernel/peripherals/mini_uart.h | 0 {chainloader => seed}/src/common/status_led.c | 0 {chainloader => seed}/src/common/utils.S | 0 {chainloader => seed}/src/config.txt | 0 {chainloader => seed}/src/kernel/boot.S | 0 {chainloader => seed}/src/kernel/kernel.c | 0 {chainloader => seed}/src/kernel/load.c | 0 {chainloader => seed}/src/kernel/mailbox.c | 0 {chainloader => seed}/src/kernel/mini_uart.c | 0 {chainloader => seed}/src/linker.ld | 0 {chainloader => seed}/src/mailbox.c | 0 25 files changed, 11 insertions(+), 11 deletions(-) rename {chainloader => seed}/Makefile (100%) rename {chainloader => seed}/include/common/status_led.h (100%) rename {chainloader => seed}/include/common/stdbool.h (100%) rename {chainloader => seed}/include/common/stddef.h (100%) rename {chainloader => seed}/include/common/utils.h (100%) rename {chainloader => seed}/include/kernel/chainload.h (100%) rename {chainloader => seed}/include/kernel/kernel.h (100%) rename {chainloader => seed}/include/kernel/load.h (100%) rename {chainloader => seed}/include/kernel/mailbox.h (100%) rename {chainloader => seed}/include/kernel/mini_uart.h (100%) rename {chainloader => seed}/include/kernel/peripherals/base.h (100%) rename {chainloader => seed}/include/kernel/peripherals/gpio.h (100%) rename {chainloader => seed}/include/kernel/peripherals/mailbox.h (100%) rename {chainloader => seed}/include/kernel/peripherals/mini_uart.h (100%) rename {chainloader => seed}/src/common/status_led.c (100%) rename {chainloader => seed}/src/common/utils.S (100%) rename {chainloader => seed}/src/config.txt (100%) rename {chainloader => seed}/src/kernel/boot.S (100%) rename {chainloader => seed}/src/kernel/kernel.c (100%) rename {chainloader => seed}/src/kernel/load.c (100%) rename {chainloader => seed}/src/kernel/mailbox.c (100%) rename {chainloader => seed}/src/kernel/mini_uart.c (100%) rename {chainloader => seed}/src/linker.ld (100%) rename {chainloader => seed}/src/mailbox.c (100%) diff --git a/Makefile b/Makefile index 5a986d9..03241f3 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ HOST_OS = $(shell uname -s) # Mount point and boot partition -FLASH_DEFAULT_TARGET = chainloader +FLASH_DEFAULT_TARGET = seed MNT = $(MNT_$(HOST_OS)) MNT_Linux = mnt MNT_Darwin = /Volumes/boot @@ -33,16 +33,16 @@ all: clean buildall # Remove kernel and build directory clean: rm -rf $(BUILD) *.img - $(MAKE) -C chainloader clean + $(MAKE) -C seed clean $(MAKE) -C thorn clean # Build the different OSes build: build-$(BUILD_DEFAULT_TARGET) -buildall: build-chainloader build-thorn +buildall: build-seed build-thorn -build-chainloader: - $(MAKE) -C chainloader build +build-seed: + $(MAKE) -C seed build build-thorn: $(MAKE) -C thorn build @@ -50,8 +50,8 @@ build-thorn: # Mount boot partition of SD card onto set mount point to copy image onto it flash: flash-$(FLASH_DEFAULT_TARGET) -flash-chainloader: - $(MAKE) -C chainloader flash +flash-seed: + $(MAKE) -C seed flash flash-thorn: $(MAKE) -C thorn flash @@ -71,8 +71,8 @@ resend: reboot build # send corresponding image over serial connection send: send-$(SEND_DEFAULT_TARGET) -send-chainloader: setup-serial-$(HOST_OS) - $(MAKE) -C chainloader send +send-seed: setup-serial-$(HOST_OS) + $(MAKE) -C seed send send-thorn: setup-serial-$(HOST_OS) $(MAKE) -C thorn send @@ -93,8 +93,8 @@ blank: # Emulate the corresponding kernel on qemu emulate: emulate-$(EMULATE_DEFAULT_TARGET) -emulate-chainloader: - $(MAKE) -C chainloader emulate +emulate-seed: + $(MAKE) -C seed emulate emulate-thorn: $(MAKE) -C thorn emulate diff --git a/chainloader/Makefile b/seed/Makefile similarity index 100% rename from chainloader/Makefile rename to seed/Makefile diff --git a/chainloader/include/common/status_led.h b/seed/include/common/status_led.h similarity index 100% rename from chainloader/include/common/status_led.h rename to seed/include/common/status_led.h diff --git a/chainloader/include/common/stdbool.h b/seed/include/common/stdbool.h similarity index 100% rename from chainloader/include/common/stdbool.h rename to seed/include/common/stdbool.h diff --git a/chainloader/include/common/stddef.h b/seed/include/common/stddef.h similarity index 100% rename from chainloader/include/common/stddef.h rename to seed/include/common/stddef.h diff --git a/chainloader/include/common/utils.h b/seed/include/common/utils.h similarity index 100% rename from chainloader/include/common/utils.h rename to seed/include/common/utils.h diff --git a/chainloader/include/kernel/chainload.h b/seed/include/kernel/chainload.h similarity index 100% rename from chainloader/include/kernel/chainload.h rename to seed/include/kernel/chainload.h diff --git a/chainloader/include/kernel/kernel.h b/seed/include/kernel/kernel.h similarity index 100% rename from chainloader/include/kernel/kernel.h rename to seed/include/kernel/kernel.h diff --git a/chainloader/include/kernel/load.h b/seed/include/kernel/load.h similarity index 100% rename from chainloader/include/kernel/load.h rename to seed/include/kernel/load.h diff --git a/chainloader/include/kernel/mailbox.h b/seed/include/kernel/mailbox.h similarity index 100% rename from chainloader/include/kernel/mailbox.h rename to seed/include/kernel/mailbox.h diff --git a/chainloader/include/kernel/mini_uart.h b/seed/include/kernel/mini_uart.h similarity index 100% rename from chainloader/include/kernel/mini_uart.h rename to seed/include/kernel/mini_uart.h diff --git a/chainloader/include/kernel/peripherals/base.h b/seed/include/kernel/peripherals/base.h similarity index 100% rename from chainloader/include/kernel/peripherals/base.h rename to seed/include/kernel/peripherals/base.h diff --git a/chainloader/include/kernel/peripherals/gpio.h b/seed/include/kernel/peripherals/gpio.h similarity index 100% rename from chainloader/include/kernel/peripherals/gpio.h rename to seed/include/kernel/peripherals/gpio.h diff --git a/chainloader/include/kernel/peripherals/mailbox.h b/seed/include/kernel/peripherals/mailbox.h similarity index 100% rename from chainloader/include/kernel/peripherals/mailbox.h rename to seed/include/kernel/peripherals/mailbox.h diff --git a/chainloader/include/kernel/peripherals/mini_uart.h b/seed/include/kernel/peripherals/mini_uart.h similarity index 100% rename from chainloader/include/kernel/peripherals/mini_uart.h rename to seed/include/kernel/peripherals/mini_uart.h diff --git a/chainloader/src/common/status_led.c b/seed/src/common/status_led.c similarity index 100% rename from chainloader/src/common/status_led.c rename to seed/src/common/status_led.c diff --git a/chainloader/src/common/utils.S b/seed/src/common/utils.S similarity index 100% rename from chainloader/src/common/utils.S rename to seed/src/common/utils.S diff --git a/chainloader/src/config.txt b/seed/src/config.txt similarity index 100% rename from chainloader/src/config.txt rename to seed/src/config.txt diff --git a/chainloader/src/kernel/boot.S b/seed/src/kernel/boot.S similarity index 100% rename from chainloader/src/kernel/boot.S rename to seed/src/kernel/boot.S diff --git a/chainloader/src/kernel/kernel.c b/seed/src/kernel/kernel.c similarity index 100% rename from chainloader/src/kernel/kernel.c rename to seed/src/kernel/kernel.c diff --git a/chainloader/src/kernel/load.c b/seed/src/kernel/load.c similarity index 100% rename from chainloader/src/kernel/load.c rename to seed/src/kernel/load.c diff --git a/chainloader/src/kernel/mailbox.c b/seed/src/kernel/mailbox.c similarity index 100% rename from chainloader/src/kernel/mailbox.c rename to seed/src/kernel/mailbox.c diff --git a/chainloader/src/kernel/mini_uart.c b/seed/src/kernel/mini_uart.c similarity index 100% rename from chainloader/src/kernel/mini_uart.c rename to seed/src/kernel/mini_uart.c diff --git a/chainloader/src/linker.ld b/seed/src/linker.ld similarity index 100% rename from chainloader/src/linker.ld rename to seed/src/linker.ld diff --git a/chainloader/src/mailbox.c b/seed/src/mailbox.c similarity index 100% rename from chainloader/src/mailbox.c rename to seed/src/mailbox.c From 8d17cdc3e144522775974e9043fdf9b39137b313 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Tue, 9 Nov 2021 16:17:33 +0100 Subject: [PATCH 2/4] chore(seed): handle reboot character properly * `make send` now always sends reboot command * seed now expects one extra char before the length --- Makefile | 4 ++-- seed/src/kernel/load.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 03241f3..9e53ba7 100644 --- a/Makefile +++ b/Makefile @@ -71,10 +71,10 @@ resend: reboot build # send corresponding image over serial connection send: send-$(SEND_DEFAULT_TARGET) -send-seed: setup-serial-$(HOST_OS) +send-seed: setup-serial-$(HOST_OS) reboot $(MAKE) -C seed send -send-thorn: setup-serial-$(HOST_OS) +send-thorn: setup-serial-$(HOST_OS) reboot $(MAKE) -C thorn send # Set up screen on alternate serial port diff --git a/seed/src/kernel/load.c b/seed/src/kernel/load.c index 31a9b23..636022e 100644 --- a/seed/src/kernel/load.c +++ b/seed/src/kernel/load.c @@ -31,6 +31,9 @@ void receive_kernel (void) { toggle_led (STATUS_LED); toggle_led (POWER_LED); + // Discard one char to prevent send/resend issue + uart_recv(); + for (int i = sizeof (int); i > 0;) {// 4 is size of int kernel_size_address[--i] = uart_recv (); } From 71630222b4259016e6f2672f7df8f1e46bdeaee7 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 11 Nov 2021 14:48:35 +0100 Subject: [PATCH 3/4] fix(load): ignore reboot character --- Makefile | 15 +++++++++++---- seed/src/kernel/load.c | 7 +++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 9e53ba7..2263771 100644 --- a/Makefile +++ b/Makefile @@ -64,17 +64,24 @@ setup-serial-Darwin: cat -v $(SERIAL_PORT) & stty -f $(SERIAL_PORT) $(BAUD_RATE) raw cs8 -ixoff -cstopb -parenb -resend: reboot build +# reboot and send corresponding image over serial connection +resend: resend-$(SEND_DEFAULT_TARGET) + +resend-seed: setup-serial-$(HOST_OS) reboot sleep 8 - $(MAKE) send + $(MAKE) -C seed send + +resend-thorn: setup-serial-$(HOST_OS) reboot + sleep 8 + $(MAKE) -C thorn send # send corresponding image over serial connection send: send-$(SEND_DEFAULT_TARGET) -send-seed: setup-serial-$(HOST_OS) reboot +send-seed: setup-serial-$(HOST_OS) $(MAKE) -C seed send -send-thorn: setup-serial-$(HOST_OS) reboot +send-thorn: setup-serial-$(HOST_OS) $(MAKE) -C thorn send # Set up screen on alternate serial port diff --git a/seed/src/kernel/load.c b/seed/src/kernel/load.c index 636022e..5394e40 100644 --- a/seed/src/kernel/load.c +++ b/seed/src/kernel/load.c @@ -31,11 +31,10 @@ void receive_kernel (void) { toggle_led (STATUS_LED); toggle_led (POWER_LED); - // Discard one char to prevent send/resend issue - uart_recv(); - for (int i = sizeof (int); i > 0;) {// 4 is size of int - kernel_size_address[--i] = uart_recv (); + unsigned char c = uart_recv(); + if (!i && c == 18) continue; // Ignore first char if reboot signal + kernel_size_address[--i] = c; } int length = *(int *) kernel_size_address; From eea23ff7a6da74cddc6f7e5c8ae968163b862544 Mon Sep 17 00:00:00 2001 From: Aaron Alef Date: Thu, 11 Nov 2021 16:38:34 +0100 Subject: [PATCH 4/4] fix(load): use right index for checking --- seed/src/kernel/load.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seed/src/kernel/load.c b/seed/src/kernel/load.c index 5394e40..0b71b68 100644 --- a/seed/src/kernel/load.c +++ b/seed/src/kernel/load.c @@ -33,7 +33,7 @@ void receive_kernel (void) { for (int i = sizeof (int); i > 0;) {// 4 is size of int unsigned char c = uart_recv(); - if (!i && c == 18) continue; // Ignore first char if reboot signal + if (i == sizeof (int) && c == 18) continue; // Ignore first char if reboot signal kernel_size_address[--i] = c; } int length = *(int *) kernel_size_address;