Browse Source

rv32: do graceful shutdown whereever possible

In particular, after FPGA update...
H. Peter Anvin 1 year ago
parent
commit
1ffb9183cf

BIN
esp32/output/max80.ino.bin


+ 2 - 2
fpga/max80.qpf

@@ -19,12 +19,12 @@
 #
 # Quartus Prime
 # Version 22.1std.2 Build 922 07/20/2023 SC Lite Edition
-# Date created = 16:13:11  October 01, 2023
+# Date created = 18:52:09  October 01, 2023
 #
 # -------------------------------------------------------------------------- #
 
 QUARTUS_VERSION = "22.1"
-DATE = "16:13:11  October 01, 2023"
+DATE = "18:52:09  October 01, 2023"
 
 # Revisions
 

BIN
fpga/output/bypass.jic


BIN
fpga/output/max80.fw


BIN
fpga/output/v1.fw


BIN
fpga/output/v1.jic


BIN
fpga/output/v1.sof


BIN
fpga/output/v2.fw


BIN
fpga/output/v2.jic


BIN
fpga/output/v2.sof


+ 2 - 2
rv32/Makefile

@@ -38,7 +38,7 @@ VPATH    := .:../common
 genhdrs = iodevs.h irqtable.h
 gensrcs =
 
-all: sram.bin jtagupd.bin dram.bin dram.hex checksum.h
+all: sram.bin dram.bin dram.hex checksum.h
 
 LIBS    = max80.a fatfs.a zlib.a
 
@@ -102,7 +102,7 @@ checksum.h: dram.bin sram.bin checksum.pl
 	$(PERL) checksum.pl -o $@ -p sram.bin \
 		-l $$(($$($(NM) -n max80.elf --radix=decimal | \
 			grep ' [A-Z] __dram_init_end$$' | \
-	                awk '{ print $$1; }') - (1 << 30))) \
+			awk '{ print $$1; }') - (1 << 30))) \
 		dram.bin
 
 testimg.bin: testimg.elf

+ 25 - 0
rv32/abcdisk.c

@@ -652,6 +652,7 @@ static void do_next_command(struct ctl_state *state)
 }
 
 static FATFS sd_fs;
+static bool sd_mounted;
 
 static int mount_disk(void)
 {
@@ -668,6 +669,7 @@ static int mount_disk(void)
 	set_led(LED_DISKIO, false);
 	return -1;
     }
+    sd_mounted = true;
 
     label[0] = '\0';
     volid = 0;
@@ -827,3 +829,26 @@ void abcdisk_config(void)
 	abc_register(&state->iodev, devsel);
     }
 }
+
+/*
+ * Shut down the disk subsystem for reboot
+ */
+void abcdisk_shutdown(void)
+{
+    if (!sd_mounted)
+	return;			/* Nothing to do */
+
+    for (int i = 0; i < CONTROLLER_TYPES; i++) {
+	struct ctl_state * const state = &controllers[i];
+	if (state->initialized)
+	    unmount_drives(state);
+    }
+
+    /* Unmount the SD card filesystem */
+    f_unmount("");
+
+    /* Check one last time to see if anything needs to be written out */
+    disk_ioctl(0, CTRL_SYNC, NULL);
+
+    sd_mounted = false;
+}

+ 1 - 0
rv32/abcio.h

@@ -108,6 +108,7 @@ void abc_init(void);
 void abcdisk_init(void);
 void abcdisk_config(void);
 void abcdisk_io_poll(void);
+void abcdisk_shutdown(void);
 
 void rtc_abc_init(void);
 void rtc_abc_config(void);

+ 1 - 1
rv32/checksum.h

@@ -1,4 +1,4 @@
 #ifndef CHECKSUM_H
 #define CHECKSUM_H
-#define SDRAM_SUM 0x92273ba2
+#define SDRAM_SUM 0x52bf7103
 #endif

+ 2 - 4
rv32/romcopy.c

@@ -325,7 +325,7 @@ void rom_flash_from_memory(void *buf, size_t buflen)
     con_puts("update: flash complete, restarting in 500 ms...\n");
     udelay(500000);
 
-    reset(SYS_RESET_RECONFIG);
+    shutdown(SYS_RESET_RECONFIG);
 }
 
 static int rom_sdcard_read_data(void *cookie, void *buf, unsigned int bufsize)
@@ -402,14 +402,12 @@ void rom_flash_from_sdcard(void)
 	return;
     }
 
-    /* Close file and then umount the filesystem to force sync */
     f_close(&f);
-    f_unmount("");
 
     con_puts("update: flash complete, restarting in 500 ms...\n");
     udelay(500000);
 
-    reset(SYS_RESET_RECONFIG);
+    shutdown(SYS_RESET_RECONFIG);
 }
 
 static bool boardinfo_valid(const struct board_info *bi)

+ 4 - 3
rv32/shutdown.c

@@ -1,6 +1,7 @@
 #include "common.h"
 #include "io.h"
-#include "sdcard.h"
+#include "abcio.h"
+#include "ff.h"
 #include "console.h"
 
 /*
@@ -8,8 +9,8 @@
  */
 no_return shutdown(unsigned int type)
 {
-    /* Flush disk cache */
-    disk_ioctl(0, CTRL_SYNC, NULL);
+    /* Finish any SD card I/O and unmount the SD card */
+    abcdisk_shutdown();
 
     con_puts("Rebooting...\n");
     reset(type);