Simplify system ID
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Sun, 19 May 2013 17:44:00 +0000 (19:44 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Sun, 19 May 2013 17:44:00 +0000 (19:44 +0200)
software/bios/boot.c
software/bios/main.c
software/include/base/board.h [deleted file]
software/include/base/id.h [new file with mode: 0644]
software/libbase/Makefile
software/libbase/board.c [deleted file]
software/libbase/id.c [new file with mode: 0644]

index 3cffcef8c404fe609488720e84ed5a59849ebdd1..b37f15240a648e18d251b54cf99b7379f4d8ed33 100644 (file)
@@ -2,7 +2,6 @@
 #include <console.h>
 #include <uart.h>
 #include <system.h>
-#include <board.h>
 #include <crc.h>
 #include <sfl.h>
 #include <string.h>
index ffdb9e3cd77ad01fe74a6af9c9218079d93f1757..8e372a576a8e3c3ffcc8f824e30822f0dec9a6e8 100644 (file)
@@ -4,7 +4,7 @@
 #include <string.h>
 #include <uart.h>
 #include <system.h>
-#include <board.h>
+#include <id.h>
 #include <irq.h>
 #include <version.h>
 #include <crc.h>
@@ -515,7 +515,7 @@ int main(int i, char **c)
        crcbios();
        if(rescue)
                printf("Rescue mode\n");
-       board_init();
+       id_print();
        ethreset();
        print_mac();
        ddr_ok = ddrinit();
diff --git a/software/include/base/board.h b/software/include/base/board.h
deleted file mode 100644 (file)
index 5c5f54c..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef __BOARD_H
-#define __BOARD_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define BOARD_NAME_LEN 32
-
-struct board_desc {
-       unsigned short int id;
-       char name[BOARD_NAME_LEN];
-       unsigned int ethernet_phyadr;
-};
-
-int get_pcb_revision(void);
-void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc);
-void get_soc_version_formatted(char *version);
-
-extern const struct board_desc *brd_desc;
-void board_init(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __BOARD_H */
diff --git a/software/include/base/id.h b/software/include/base/id.h
new file mode 100644 (file)
index 0000000..19202c8
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef __ID_H
+#define __ID_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void get_sysid_formatted(char *sysid);
+void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc);
+void get_soc_version_formatted(char *version);
+
+void id_print(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ID_H */
index 0a97b9730c4d10d18c1e1403b71e7c9d9410aef5..11e944d0cecb745ed146c067245e900b9e9a11dc 100644 (file)
@@ -1,7 +1,7 @@
 M2DIR=../..
 include $(M2DIR)/software/common.mak
 
-OBJECTS=setjmp.o libc.o errno.o crc16.o crc32.o console.o system.o board.o uart.o qsort.o strtod.o
+OBJECTS=setjmp.o libc.o errno.o crc16.o crc32.o console.o system.o id.o uart.o qsort.o strtod.o
 
 all: libbase.a libbase-nofloat.a
 
diff --git a/software/libbase/board.c b/software/libbase/board.c
deleted file mode 100644 (file)
index 48764a5..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-#include <hw/csr.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <version.h>
-#include <board.h>
-
-static const struct board_desc boards[1] = {
-       {
-               .id = 0x4D31, /* M1 */
-               .name = "Milkymist One",
-               .ethernet_phyadr = 1
-       },
-};
-
-static const struct board_desc *get_board_desc_id(unsigned short int id)
-{
-       unsigned int i;
-
-       for(i=0;i<sizeof(boards)/sizeof(boards[0]);i++)
-               if(boards[i].id == id)
-                       return &boards[i];
-       return NULL;
-}
-
-static const struct board_desc *get_board_desc(void)
-{
-       return get_board_desc_id(identifier_sysid_read());
-}
-
-int get_pcb_revision(void)
-{
-       /* TODO
-       int r;
-       unsigned int io;
-
-       r = 0;
-       io = CSR_GPIO_IN;
-       if(io & GPIO_PCBREV0)
-               r |= 0x1;
-       if(io & GPIO_PCBREV1)
-               r |= 0x2;
-       if(io & GPIO_PCBREV2)
-               r |= 0x4;
-       if(io & GPIO_PCBREV3)
-               r |= 0x8;
-       return r;*/
-       return 0;
-}
-
-void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc)
-{
-       unsigned int id;
-
-       id = identifier_version_read();
-       *major = (id & 0xf000) >> 12;
-       *minor = (id & 0x0f00) >> 8;
-       *subminor = (id & 0x00f0) >> 4;
-       *rc = id & 0x000f;
-}
-
-void get_soc_version_formatted(char *version)
-{
-       unsigned int major, minor, subminor, rc;
-
-       get_soc_version(&major, &minor, &subminor, &rc);
-
-       version += sprintf(version, "%u.%u", major, minor);
-       if(subminor != 0)
-               version += sprintf(version, ".%u", subminor);
-       if(rc != 0)
-               sprintf(version, "RC%u", rc);
-}
-
-const struct board_desc *brd_desc;
-
-void board_init(void)
-{
-       int rev;
-       char soc_version[13];
-
-       brd_desc = get_board_desc();
-
-       if(brd_desc == NULL) {
-               printf("Running on unknown board, startup aborted.\n");
-               while(1);
-       }
-       rev = get_pcb_revision();
-       get_soc_version_formatted(soc_version);
-       printf("Detected SoC %s at %dMHz on %s (PCB revision %d)\n", soc_version, identifier_frequency_read()/1000000,
-              brd_desc->name, rev);
-       if(strcmp(soc_version, VERSION) != 0)
-               printf("SoC and BIOS versions do not match!\n");
-       if(rev > 2)
-               printf("Unsupported PCB revision, please upgrade!\n");
-}
diff --git a/software/libbase/id.c b/software/libbase/id.c
new file mode 100644 (file)
index 0000000..bbb927d
--- /dev/null
@@ -0,0 +1,47 @@
+#include <hw/csr.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <version.h>
+#include <id.h>
+
+void get_sysid_formatted(char *sysid)
+{
+       sysid[0] = identifier_sysid_read() >> 8;
+       sysid[1] = identifier_sysid_read();
+       sysid[2] = 0;
+}
+
+void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc)
+{
+       unsigned int id;
+
+       id = identifier_version_read();
+       *major = (id & 0xf000) >> 12;
+       *minor = (id & 0x0f00) >> 8;
+       *subminor = (id & 0x00f0) >> 4;
+       *rc = id & 0x000f;
+}
+
+void get_soc_version_formatted(char *version)
+{
+       unsigned int major, minor, subminor, rc;
+
+       get_soc_version(&major, &minor, &subminor, &rc);
+
+       version += sprintf(version, "%u.%u", major, minor);
+       if(subminor != 0)
+               version += sprintf(version, ".%u", subminor);
+       if(rc != 0)
+               sprintf(version, "RC%u", rc);
+}
+
+void id_print(void)
+{
+       char soc_version[13];
+       char sysid[3];
+
+       get_soc_version_formatted(soc_version);
+       get_sysid_formatted(sysid);
+       printf("Running on Milkymist-ng SoC %s (sysid:%s) at %dMHz\n", soc_version, sysid, identifier_frequency_read()/1000000);
+}