Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Simplify system ID

  • Loading branch information...
commit 3eb41f73e637f5e0ef87c9a163b00936455443f1 1 parent d487dc6
Sébastien Bourdeauducq authored May 19, 2013
1  software/bios/boot.c
@@ -2,7 +2,6 @@
2 2
 #include <console.h>
3 3
 #include <uart.h>
4 4
 #include <system.h>
5  
-#include <board.h>
6 5
 #include <crc.h>
7 6
 #include <sfl.h>
8 7
 #include <string.h>
4  software/bios/main.c
@@ -4,7 +4,7 @@
4 4
 #include <string.h>
5 5
 #include <uart.h>
6 6
 #include <system.h>
7  
-#include <board.h>
  7
+#include <id.h>
8 8
 #include <irq.h>
9 9
 #include <version.h>
10 10
 #include <crc.h>
@@ -515,7 +515,7 @@ int main(int i, char **c)
515 515
 	crcbios();
516 516
 	if(rescue)
517 517
 		printf("Rescue mode\n");
518  
-	board_init();
  518
+	id_print();
519 519
 	ethreset();
520 520
 	print_mac();
521 521
 	ddr_ok = ddrinit();
27  software/include/base/board.h
... ...
@@ -1,27 +0,0 @@
1  
-#ifndef __BOARD_H
2  
-#define __BOARD_H
3  
-
4  
-#ifdef __cplusplus
5  
-extern "C" {
6  
-#endif
7  
-
8  
-#define BOARD_NAME_LEN 32
9  
-
10  
-struct board_desc {
11  
-	unsigned short int id;
12  
-	char name[BOARD_NAME_LEN];
13  
-	unsigned int ethernet_phyadr;
14  
-};
15  
-
16  
-int get_pcb_revision(void);
17  
-void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc);
18  
-void get_soc_version_formatted(char *version);
19  
-
20  
-extern const struct board_desc *brd_desc;
21  
-void board_init(void);
22  
-
23  
-#ifdef __cplusplus
24  
-}
25  
-#endif
26  
-
27  
-#endif /* __BOARD_H */
18  software/include/base/id.h
... ...
@@ -0,0 +1,18 @@
  1
+#ifndef __ID_H
  2
+#define __ID_H
  3
+
  4
+#ifdef __cplusplus
  5
+extern "C" {
  6
+#endif
  7
+
  8
+void get_sysid_formatted(char *sysid);
  9
+void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc);
  10
+void get_soc_version_formatted(char *version);
  11
+
  12
+void id_print(void);
  13
+
  14
+#ifdef __cplusplus
  15
+}
  16
+#endif
  17
+
  18
+#endif /* __ID_H */
2  software/libbase/Makefile
... ...
@@ -1,7 +1,7 @@
1 1
 M2DIR=../..
2 2
 include $(M2DIR)/software/common.mak
3 3
 
4  
-OBJECTS=setjmp.o libc.o errno.o crc16.o crc32.o console.o system.o board.o uart.o qsort.o strtod.o
  4
+OBJECTS=setjmp.o libc.o errno.o crc16.o crc32.o console.o system.o id.o uart.o qsort.o strtod.o
5 5
 
6 6
 all: libbase.a libbase-nofloat.a
7 7
 
96  software/libbase/board.c
... ...
@@ -1,96 +0,0 @@
1  
-#include <hw/csr.h>
2  
-#include <stdio.h>
3  
-#include <stdlib.h>
4  
-#include <string.h>
5  
-#include <version.h>
6  
-#include <board.h>
7  
-
8  
-static const struct board_desc boards[1] = {
9  
-	{
10  
-		.id = 0x4D31, /* M1 */
11  
-		.name = "Milkymist One",
12  
-		.ethernet_phyadr = 1
13  
-	},
14  
-};
15  
-
16  
-static const struct board_desc *get_board_desc_id(unsigned short int id)
17  
-{
18  
-	unsigned int i;
19  
-
20  
-	for(i=0;i<sizeof(boards)/sizeof(boards[0]);i++)
21  
-		if(boards[i].id == id)
22  
-			return &boards[i];
23  
-	return NULL;
24  
-}
25  
-
26  
-static const struct board_desc *get_board_desc(void)
27  
-{
28  
-	return get_board_desc_id(identifier_sysid_read());
29  
-}
30  
-
31  
-int get_pcb_revision(void)
32  
-{
33  
-	/* TODO
34  
-	int r;
35  
-	unsigned int io;
36  
-
37  
-	r = 0;
38  
-	io = CSR_GPIO_IN;
39  
-	if(io & GPIO_PCBREV0)
40  
-		r |= 0x1;
41  
-	if(io & GPIO_PCBREV1)
42  
-		r |= 0x2;
43  
-	if(io & GPIO_PCBREV2)
44  
-		r |= 0x4;
45  
-	if(io & GPIO_PCBREV3)
46  
-		r |= 0x8;
47  
-	return r;*/
48  
-	return 0;
49  
-}
50  
-
51  
-void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc)
52  
-{
53  
-	unsigned int id;
54  
-
55  
-	id = identifier_version_read();
56  
-	*major = (id & 0xf000) >> 12;
57  
-	*minor = (id & 0x0f00) >> 8;
58  
-	*subminor = (id & 0x00f0) >> 4;
59  
-	*rc = id & 0x000f;
60  
-}
61  
-
62  
-void get_soc_version_formatted(char *version)
63  
-{
64  
-	unsigned int major, minor, subminor, rc;
65  
-
66  
-	get_soc_version(&major, &minor, &subminor, &rc);
67  
-
68  
-	version += sprintf(version, "%u.%u", major, minor);
69  
-	if(subminor != 0)
70  
-		version += sprintf(version, ".%u", subminor);
71  
-	if(rc != 0)
72  
-		sprintf(version, "RC%u", rc);
73  
-}
74  
-
75  
-const struct board_desc *brd_desc;
76  
-
77  
-void board_init(void)
78  
-{
79  
-	int rev;
80  
-	char soc_version[13];
81  
-
82  
-	brd_desc = get_board_desc();
83  
-
84  
-	if(brd_desc == NULL) {
85  
-		printf("Running on unknown board, startup aborted.\n");
86  
-		while(1);
87  
-	}
88  
-	rev = get_pcb_revision();
89  
-	get_soc_version_formatted(soc_version);
90  
-	printf("Detected SoC %s at %dMHz on %s (PCB revision %d)\n", soc_version, identifier_frequency_read()/1000000,
91  
-	       brd_desc->name, rev);
92  
-	if(strcmp(soc_version, VERSION) != 0)
93  
-		printf("SoC and BIOS versions do not match!\n");
94  
-	if(rev > 2)
95  
-		printf("Unsupported PCB revision, please upgrade!\n");
96  
-}
47  software/libbase/id.c
... ...
@@ -0,0 +1,47 @@
  1
+#include <hw/csr.h>
  2
+#include <stdio.h>
  3
+#include <stdlib.h>
  4
+#include <string.h>
  5
+#include <version.h>
  6
+#include <id.h>
  7
+
  8
+void get_sysid_formatted(char *sysid)
  9
+{
  10
+	sysid[0] = identifier_sysid_read() >> 8;
  11
+	sysid[1] = identifier_sysid_read();
  12
+	sysid[2] = 0;
  13
+}
  14
+
  15
+void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc)
  16
+{
  17
+	unsigned int id;
  18
+
  19
+	id = identifier_version_read();
  20
+	*major = (id & 0xf000) >> 12;
  21
+	*minor = (id & 0x0f00) >> 8;
  22
+	*subminor = (id & 0x00f0) >> 4;
  23
+	*rc = id & 0x000f;
  24
+}
  25
+
  26
+void get_soc_version_formatted(char *version)
  27
+{
  28
+	unsigned int major, minor, subminor, rc;
  29
+
  30
+	get_soc_version(&major, &minor, &subminor, &rc);
  31
+
  32
+	version += sprintf(version, "%u.%u", major, minor);
  33
+	if(subminor != 0)
  34
+		version += sprintf(version, ".%u", subminor);
  35
+	if(rc != 0)
  36
+		sprintf(version, "RC%u", rc);
  37
+}
  38
+
  39
+void id_print(void)
  40
+{
  41
+	char soc_version[13];
  42
+	char sysid[3];
  43
+
  44
+	get_soc_version_formatted(soc_version);
  45
+	get_sysid_formatted(sysid);
  46
+	printf("Running on Milkymist-ng SoC %s (sysid:%s) at %dMHz\n", soc_version, sysid, identifier_frequency_read()/1000000);
  47
+}

0 notes on commit 3eb41f7

Please sign in to comment.
Something went wrong with that request. Please try again.