浏览代码

config: fix marshalling of strings; handle reconfiguration events

Fix marshalling of strings, so they end up pointing to valid memory
once transferred to the FPGA.

Handle reconfiguration events, specifically enabling or disabling I/O
devices.
H. Peter Anvin 1 年之前
父节点
当前提交
bcf6d05aa2
共有 19 个文件被更改,包括 45 次插入13 次删除
  1. 4 2
      esp32/max80/sysvars_marshall.c
  2. 二进制
      esp32/output/max80.ino.bin
  3. 2 2
      fpga/max80.qpf
  4. 二进制
      fpga/output/bypass.jic
  5. 二进制
      fpga/output/max80.fw
  6. 二进制
      fpga/output/v1.fw
  7. 二进制
      fpga/output/v1.jic
  8. 二进制
      fpga/output/v1.sof
  9. 二进制
      fpga/output/v2.fw
  10. 二进制
      fpga/output/v2.jic
  11. 二进制
      fpga/output/v2.sof
  12. 11 3
      rv32/abcio.c
  13. 7 0
      rv32/abcio.h
  14. 5 0
      rv32/abcpun80.c
  15. 5 0
      rv32/abcrtc.c
  16. 1 1
      rv32/checksum.h
  17. 0 4
      rv32/common.h
  18. 5 0
      rv32/config.c
  19. 5 1
      rv32/max80.c

+ 4 - 2
esp32/max80/sysvars_marshall.c

@@ -4,6 +4,7 @@
 
 #include "common.h"
 #include "sysvars.h"
+#include <stdio.h>
 
 /*
  * Marshall a set or subset of sysvar entries into a buffer
@@ -34,7 +35,7 @@ size_t sysvar_marshall(enum sysvar_enum first, size_t count,
     intptr_t adjust = extaddr - (uintptr_t)buf;
 
     while (count--) {
-	sysvar_t vv = *vp++ = *v++;
+	sysvar_t vv = *v++;
 	sysvar_type_t type = *t++;
 	if (type && type->datasize && vv.v_ptr) {
 	    size_t dsize = type->datasize(vv);
@@ -43,9 +44,10 @@ size_t sysvar_marshall(enum sysvar_enum first, size_t count,
 		break;		/* Insufficient buffer space */
 	    char *dp = (char *)buf + adj_bytes;
 	    memcpy(dp, vv.v_ptr, dsize);
-	    vv.v_ptr = (void *)((uintptr_t)vv.v_ptr + adjust);
+	    vv.v_ptr = dp + adjust;
 	    bytes = adj_bytes + dsize;
 	}
+	*vp++ = vv;
 	ok++;
     }
     *buflen = bytes;

二进制
esp32/output/max80.ino.bin


+ 2 - 2
fpga/max80.qpf

@@ -19,12 +19,12 @@
 #
 # Quartus Prime
 # Version 22.1std.0 Build 915 10/25/2022 SC Lite Edition
-# Date created = 19:15:33  September 05, 2023
+# Date created = 21:07:40  September 05, 2023
 #
 # -------------------------------------------------------------------------- #
 
 QUARTUS_VERSION = "22.1"
-DATE = "19:15:33  September 05, 2023"
+DATE = "21:07:40  September 05, 2023"
 
 # Revisions
 

二进制
fpga/output/bypass.jic


二进制
fpga/output/max80.fw


二进制
fpga/output/v1.fw


二进制
fpga/output/v1.jic


二进制
fpga/output/v1.sof


二进制
fpga/output/v2.fw


二进制
fpga/output/v2.jic


二进制
fpga/output/v2.sof


+ 11 - 3
rv32/abcio.c

@@ -195,6 +195,7 @@ void abc_register(struct abc_dev *dev, unsigned int devsel)
 
     irqmask_t irqmask = mask_irq(ABC_IRQ);
     unsigned int old_devsel = DEVSEL_NONE;
+    struct abc_dev *old_dev = NULL;
 
     if (dev) {
 	if (dev->devsel < DEVSEL_NONE && abc_device[dev->devsel] == dev) {
@@ -211,8 +212,9 @@ void abc_register(struct abc_dev *dev, unsigned int devsel)
     }
 
     if (devsel < DEVSEL_NONE) {
-	if (abc_device[devsel])
-	    abc_device[devsel]->devsel = DEVSEL_NONE;
+	old_dev = abc_device[devsel];
+	if (old_dev)
+	    old_dev->devsel = DEVSEL_NONE;
 
 	abc_device[devsel] = dev;
 	if (devsel == abc_devsel)
@@ -223,8 +225,14 @@ done:
     restore_irq(irqmask, ABC_IRQ);
 
     if (dev) {
+	if (old_dev) {
+	    con_printf("[ABC] Unregistered device %s from devsel %u\n",
+		       old_dev->name, devsel);
+	}
 	if (old_devsel < DEVSEL_NONE) {
-	    if (devsel < DEVSEL_NONE) {
+	    if (devsel == old_devsel) {
+		/* Print nothing */
+	    } else if (devsel < DEVSEL_NONE) {
 		con_printf("[ABC] Moved device %s from devsel %u to %u\n",
 			   dev->name, old_devsel, devsel);
 	    } else {

+ 7 - 0
rv32/abcio.h

@@ -100,6 +100,13 @@ void abcdisk_init(void);
 void abcdisk_config(void);
 void abcdisk_io_poll(void);
 
+void rtc_abc_init(void);
+void rtc_abc_config(void);
+void rtc_abc_io_poll(void);
+
+void pun80_init(void);
+void pun80_config(void);
+
 void abc_init_memmap(void);
 
 #endif /* ABCIO_H */

+ 5 - 0
rv32/abcpun80.c

@@ -124,6 +124,11 @@ void pun80_init(void)
     PUN_IRQEN  = PUN_IRQ_MASK;
     unmask_irq(PUN_IRQ);
 
+    pun80_config();
+}
+
+void pun80_config(void)
+{
     unsigned int devsel = getvar_uint(config_abc_io_pun80_devsel);
     if (!getvar_bool(config_abc_io_pun80_enable))
 	devsel = DEVSEL_NONE;

+ 5 - 0
rv32/abcrtc.c

@@ -108,6 +108,11 @@ static struct abc_dev rtc_iodev = {
 };
 
 void rtc_abc_init(void)
+{
+    rtc_abc_config();
+}
+
+void rtc_abc_config(void)
 {
     unsigned int devsel = getvar_uint(config_abc_io_rtc_devsel);
     if (!getvar_bool(config_abc_io_rtc_enable))

+ 1 - 1
rv32/checksum.h

@@ -1,4 +1,4 @@
 #ifndef CHECKSUM_H
 #define CHECKSUM_H
-#define SDRAM_SUM 0xc6250815
+#define SDRAM_SUM 0x140405d7
 #endif

+ 0 - 4
rv32/common.h

@@ -99,10 +99,6 @@ extern void mount_abcdrives(void);
 extern void read_rtc(void);
 extern void write_rtc(void);
 extern volatile bool do_write_rtc;
-extern void rtc_abc_init(void);
-extern void rtc_abc_io_poll(void);
-
-extern void pun80_init(void);
 
 extern void romcopy_download(void *, size_t, size_t);
 extern void romcopy_bzero(void *, size_t);

+ 5 - 0
rv32/config.c

@@ -17,12 +17,17 @@ void update_config(void)
     con_puts("[ESP] Configuration received: ");
     con_puts(_configured ? "update\n" : "initial\n");
 
+#if 0
+    con_printf("config_buf = %p\n", config_buf);
     for (enum sysvar_enum i = sysvar_null+1; i < sysvar_count; i++) {
 	con_puts(sysvar_name[i]);
 	con_putc('=');
 	con_puts(notempty(getvar_tostr(i)));
+	if (sysvar_types[i]->datasize)
+	    con_printf(" (%p)", sysvar_val[i].v_ptr);
 	con_putc('\n');
     }
+#endif
 
     if (!_configured) {
 	_configured = true;

+ 5 - 1
rv32/max80.c

@@ -22,8 +22,12 @@ void __hot main(void)
 	if (unlikely(do_update_boardinfo))
 	    rom_update_boardinfo();
 
-	if (unlikely(do_update_config))
+	if (unlikely(do_update_config)) {
 	    update_config();
+	    rtc_abc_config();
+	    abcdisk_config();
+	    pun80_config();
+	}
 
 	abcdisk_io_poll();