From 3eb41f73e637f5e0ef87c9a163b00936455443f1 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 19 May 2013 19:44:00 +0200 Subject: [PATCH] Simplify system ID --- software/bios/boot.c | 1 - software/bios/main.c | 4 +- software/include/base/board.h | 27 ---------- software/include/base/id.h | 18 +++++++ software/libbase/Makefile | 2 +- software/libbase/board.c | 96 ----------------------------------- software/libbase/id.c | 47 +++++++++++++++++ 7 files changed, 68 insertions(+), 127 deletions(-) delete mode 100644 software/include/base/board.h create mode 100644 software/include/base/id.h delete mode 100644 software/libbase/board.c create mode 100644 software/libbase/id.c diff --git a/software/bios/boot.c b/software/bios/boot.c index 3cffcef8..b37f1524 100644 --- a/software/bios/boot.c +++ b/software/bios/boot.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include diff --git a/software/bios/main.c b/software/bios/main.c index ffdb9e3c..8e372a57 100644 --- a/software/bios/main.c +++ b/software/bios/main.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include @@ -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 index 5c5f54c2..00000000 --- a/software/include/base/board.h +++ /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 index 00000000..19202c8b --- /dev/null +++ b/software/include/base/id.h @@ -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 */ diff --git a/software/libbase/Makefile b/software/libbase/Makefile index 0a97b973..11e944d0 100644 --- a/software/libbase/Makefile +++ b/software/libbase/Makefile @@ -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 index 48764a53..00000000 --- a/software/libbase/board.c +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include -#include -#include -#include -#include - -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> 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 index 00000000..bbb927da --- /dev/null +++ b/software/libbase/id.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include + +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); +} -- 2.30.2