Simplify system ID

This commit is contained in:
Sebastien Bourdeauducq 2013-05-19 19:44:00 +02:00
parent d487dc607f
commit 3eb41f73e6
7 changed files with 68 additions and 127 deletions

View 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>

View 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();

View file

@ -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 */

View file

@ -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 */

View 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

View file

@ -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");
}

47
software/libbase/id.c Normal file
View file

@ -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);
}