Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 9 files changed
  • 0 comments
  • 1 contributor
2  .gitignore
@@ -3,6 +3,8 @@ build/*
3 3
 *.o
4 4
 *.d
5 5
 *.a
  6
+*.bin
  7
+*.elf
6 8
 tools/bin2hex
7 9
 tools/flterm
8 10
 tools/mkmmimg
32  milkymist/identifier/__init__.py
... ...
@@ -0,0 +1,32 @@
  1
+from migen.fhdl.structure import *
  2
+from migen.bank.description import *
  3
+from migen.bank import csrgen
  4
+
  5
+import re
  6
+
  7
+def encode_version(version):
  8
+	match = re.match("(\d+)\.(\d+)(\.(\d+))?(rc(\d+))?", version, re.IGNORECASE)
  9
+	r = (int(match.group(1)) << 12) | (int(match.group(2)) << 8)
  10
+	subminor = match.group(4)
  11
+	rc = match.group(6)
  12
+	if subminor:
  13
+		r |= int(subminor) << 4
  14
+	if rc:
  15
+		r |= int(rc)
  16
+	return r
  17
+
  18
+class Identifier:
  19
+	def __init__(self, address, sysid, version):
  20
+		self.sysid = sysid
  21
+		self.version = encode_version(version)
  22
+		
  23
+		self._r_sysid = RegisterField("sysid", 16, access_bus=READ_ONLY, access_dev=WRITE_ONLY)
  24
+		self._r_version = RegisterField("version", 16, access_bus=READ_ONLY, access_dev=WRITE_ONLY)
  25
+		self.bank = csrgen.Bank([self._r_sysid, self._r_version], address=address)
  26
+		
  27
+	def get_fragment(self):
  28
+		comb = [
  29
+			self._r_sysid.field.w.eq(self.sysid),
  30
+			self._r_version.field.w.eq(self.version)
  31
+		]
  32
+		return self.bank.get_fragment() + Fragment(comb)
3  software/bios/main.c
@@ -344,8 +344,6 @@ static void do_command(char *c)
344 344
 	else if(strcmp(token, "crc") == 0) crc(get_token(&c), get_token(&c));
345 345
 
346 346
 	else if(strcmp(token, "version") == 0) puts(VERSION);
347  
-	else if(strcmp(token, "reboot") == 0) reboot();
348  
-	else if(strcmp(token, "reconf") == 0) reconf();
349 347
 
350 348
 	else if(strcmp(token, "help") == 0) help();
351 349
 
@@ -453,6 +451,7 @@ int main(int i, char **c)
453 451
 	crcbios();
454 452
 	if(rescue)
455 453
 		printf("Rescue mode\n");
  454
+	board_init();
456 455
 	print_mac();
457 456
 	ddr_ok = ddrinit();
458 457
 	if(ddr_ok) {
5  software/include/base/board.h
@@ -26,10 +26,11 @@ struct board_desc {
26 26
 	unsigned int ethernet_phyadr;
27 27
 };
28 28
 
29  
-const struct board_desc *get_board_desc_id(unsigned short int id);
30  
-const struct board_desc *get_board_desc(void);
31 29
 int get_pcb_revision(void);
32 30
 void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc);
33 31
 void get_soc_version_formatted(char *version);
34 32
 
  33
+extern const struct board_desc *brd_desc;
  34
+void board_init(void);
  35
+
35 36
 #endif /* __BOARD_H */
31  software/include/hw/id.h
... ...
@@ -0,0 +1,31 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010, 2012 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __HW_ID_H
  19
+#define __HW_ID_H
  20
+
  21
+#include <hw/common.h>
  22
+#include <csrbase.h>
  23
+
  24
+#define ID_CSR(x)		MMPTR(ID_BASE+(x))
  25
+
  26
+#define CSR_ID_SYSTEMH		ID_CSR(0x00)
  27
+#define CSR_ID_SYSTEML		ID_CSR(0x04)
  28
+#define CSR_ID_VERSIONH		ID_CSR(0x08)
  29
+#define CSR_ID_VERSIONL		ID_CSR(0x0c)
  30
+
  31
+#endif /* __HW_ID_H */
55  software/include/hw/sysctl.h
... ...
@@ -1,55 +0,0 @@
1  
-/*
2  
- * Milkymist SoC (Software)
3  
- * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
4  
- *
5  
- * This program is free software: you can redistribute it and/or modify
6  
- * it under the terms of the GNU General Public License as published by
7  
- * the Free Software Foundation, version 3 of the License.
8  
- *
9  
- * This program is distributed in the hope that it will be useful,
10  
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  
- * GNU General Public License for more details.
13  
- *
14  
- * You should have received a copy of the GNU General Public License
15  
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  
- */
17  
-
18  
-#ifndef __HW_SYSCTL_H
19  
-#define __HW_SYSCTL_H
20  
-
21  
-#include <hw/common.h>
22  
-
23  
-#define CSR_GPIO_IN		MMPTR(0xe0001000)
24  
-#define CSR_GPIO_OUT		MMPTR(0xe0001004)
25  
-#define CSR_GPIO_INTEN		MMPTR(0xe0001008)
26  
-
27  
-#define CSR_TIMER0_CONTROL	MMPTR(0xe0001010)
28  
-#define CSR_TIMER0_COMPARE	MMPTR(0xe0001014)
29  
-#define CSR_TIMER0_COUNTER	MMPTR(0xe0001018)
30  
-
31  
-#define CSR_TIMER1_CONTROL	MMPTR(0xe0001020)
32  
-#define CSR_TIMER1_COMPARE	MMPTR(0xe0001024)
33  
-#define CSR_TIMER1_COUNTER	MMPTR(0xe0001028)
34  
-
35  
-#define TIMER_ENABLE		(0x01)
36  
-#define TIMER_AUTORESTART	(0x02)
37  
-
38  
-#define CSR_ICAP		MMPTR(0xe0001040)
39  
-
40  
-#define ICAP_READY		(0x01)
41  
-
42  
-#define ICAP_CE			(0x10000)
43  
-#define ICAP_WRITE		(0x20000)
44  
-
45  
-#define CSR_DBG_SCRATCHPAD	MMPTR(0xe0001050)
46  
-#define CSR_DBG_CTRL		MMPTR(0xe0001054)
47  
-
48  
-#define DBG_CTRL_GDB_ROM_LOCK	(0x01)
49  
-#define DBG_CTRL_BUS_ERR_EN	(0x02)
50  
-
51  
-#define CSR_FREQUENCY		MMPTR(0xe0001074)
52  
-#define CSR_CAPABILITIES	MMPTR(0xe0001078)
53  
-#define CSR_SYSTEM_ID		MMPTR(0xe000107c)
54  
-
55  
-#endif /* __HW_SYSCTL_H */
51  software/libbase/board.c
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * Milkymist SoC (Software)
3  
- * Copyright (C) 2007, 2008, 2009, 2011 Sebastien Bourdeauducq
  3
+ * Copyright (C) 2007, 2008, 2009, 2011, 2012 Sebastien Bourdeauducq
4 4
  *
5 5
  * This program is free software: you can redistribute it and/or modify
6 6
  * it under the terms of the GNU General Public License as published by
@@ -15,10 +15,12 @@
15 15
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16
  */
17 17
 
18  
-#include <hw/sysctl.h>
  18
+#include <hw/id.h>
19 19
 #include <hw/gpio.h>
20 20
 #include <stdio.h>
21 21
 #include <stdlib.h>
  22
+#include <string.h>
  23
+#include <version.h>
22 24
 #include <board.h>
23 25
 
24 26
 static const struct board_desc boards[1] = {
@@ -29,7 +31,7 @@ static const struct board_desc boards[1] = {
29 31
 	},
30 32
 };
31 33
 
32  
-const struct board_desc *get_board_desc_id(unsigned short int id)
  34
+static const struct board_desc *get_board_desc_id(unsigned short int id)
33 35
 {
34 36
 	unsigned int i;
35 37
 
@@ -39,18 +41,19 @@ const struct board_desc *get_board_desc_id(unsigned short int id)
39 41
 	return NULL;
40 42
 }
41 43
 
42  
-const struct board_desc *get_board_desc(void)
  44
+static const struct board_desc *get_board_desc(void)
43 45
 {
44  
-	return get_board_desc_id(CSR_SYSTEM_ID & 0xffff);
  46
+	return get_board_desc_id((CSR_ID_SYSTEMH << 8) | CSR_ID_SYSTEML);
45 47
 }
46 48
 
47 49
 int get_pcb_revision(void)
48 50
 {
  51
+	/* TODO
49 52
 	int r;
50 53
 	unsigned int io;
51 54
 
52  
-	io = CSR_GPIO_IN;
53 55
 	r = 0;
  56
+	io = CSR_GPIO_IN;
54 57
 	if(io & GPIO_PCBREV0)
55 58
 		r |= 0x1;
56 59
 	if(io & GPIO_PCBREV1)
@@ -59,18 +62,20 @@ int get_pcb_revision(void)
59 62
 		r |= 0x4;
60 63
 	if(io & GPIO_PCBREV3)
61 64
 		r |= 0x8;
62  
-	return r;
  65
+	return r;*/
  66
+	return 0;
63 67
 }
64 68
 
65 69
 void get_soc_version(unsigned int *major, unsigned int *minor, unsigned int *subminor, unsigned int *rc)
66 70
 {
67 71
 	unsigned int id;
68 72
 
69  
-	id = CSR_SYSTEM_ID;
70  
-	*major = (id & 0xf0000000) >> 28;
71  
-	*minor = (id & 0x0f000000) >> 24;
72  
-	*subminor = (id & 0x00f00000) >> 20;
73  
-	*rc = (id & 0x000f0000) >> 16;
  73
+	id = CSR_ID_VERSIONH;
  74
+	*major = (id & 0xf0) >> 4;
  75
+	*minor = id & 0x0f;
  76
+	id = CSR_ID_VERSIONL;
  77
+	*subminor = (id & 0xf0) >> 4;
  78
+	*rc = id & 0x0f;
74 79
 }
75 80
 
76 81
 void get_soc_version_formatted(char *version)
@@ -85,3 +90,25 @@ void get_soc_version_formatted(char *version)
85 90
 	if(rc != 0)
86 91
 		sprintf(version, "RC%u", rc);
87 92
 }
  93
+
  94
+const struct board_desc *brd_desc;
  95
+
  96
+void board_init(void)
  97
+{
  98
+	int rev;
  99
+	char soc_version[13];
  100
+
  101
+	brd_desc = get_board_desc();
  102
+
  103
+	if(brd_desc == NULL) {
  104
+		printf("Running on unknown board, startup aborted.\n");
  105
+		while(1);
  106
+	}
  107
+	rev = get_pcb_revision();
  108
+	get_soc_version_formatted(soc_version);
  109
+	printf("Detected SoC %s on %s (PCB revision %d)\n", soc_version, brd_desc->name, rev);
  110
+	if(strcmp(soc_version, VERSION) != 0)
  111
+		printf("SoC and BIOS versions do not match!\n");
  112
+	if(rev > 2)
  113
+		printf("Unsupported PCB revision, please upgrade!\n");
  114
+}
42  software/libbase/system.c
@@ -17,7 +17,6 @@
17 17
 
18 18
 #include <irq.h>
19 19
 #include <uart.h>
20  
-#include <hw/sysctl.h>
21 20
 
22 21
 #include <system.h>
23 22
 
@@ -39,44 +38,3 @@ void flush_cpu_dcache(void)
39 38
 		"nop\n"
40 39
 	);
41 40
 }
42  
-
43  
-__attribute__((noreturn)) void reboot(void)
44  
-{
45  
-	uart_sync();
46  
-	irq_setmask(0);
47  
-	irq_setie(0);
48  
-	CSR_SYSTEM_ID = 1; /* Writing to CSR_SYSTEM_ID causes a system reset */
49  
-	while(1);
50  
-}
51  
-
52  
-static void icap_write(int val, unsigned int w)
53  
-{
54  
-	while(!(CSR_ICAP & ICAP_READY));
55  
-	if(!val)
56  
-		w |= ICAP_CE|ICAP_WRITE;
57  
-	CSR_ICAP = w;
58  
-}
59  
-
60  
-__attribute__((noreturn)) void reconf(void)
61  
-{
62  
-	uart_sync();
63  
-	irq_setmask(0);
64  
-	irq_setie(0);
65  
-	icap_write(0, 0xffff); /* dummy word */
66  
-	icap_write(0, 0xffff); /* dummy word */
67  
-	icap_write(0, 0xffff); /* dummy word */
68  
-	icap_write(0, 0xffff); /* dummy word */
69  
-	icap_write(1, 0xaa99); /* sync word part 1 */
70  
-	icap_write(1, 0x5566); /* sync word part 2 */
71  
-	icap_write(1, 0x30a1); /* write to command register */
72  
-	icap_write(1, 0x0000); /* null command */
73  
-	icap_write(1, 0x30a1); /* write to command register */
74  
-	icap_write(1, 0x000e); /* reboot command */
75  
-	icap_write(1, 0x2000); /* NOP */
76  
-	icap_write(1, 0x2000); /* NOP */
77  
-	icap_write(1, 0x2000); /* NOP */
78  
-	icap_write(1, 0x2000); /* NOP */
79  
-	icap_write(0, 0x1111); /* NULL */
80  
-	icap_write(0, 0xffff); /* dummy word */
81  
-	while(1);
82  
-}
8  top.py
@@ -5,7 +5,7 @@
5 5
 from migen.fhdl import verilog, autofragment
6 6
 from migen.bus import wishbone, wishbone2asmi, csr, wishbone2csr, dfi
7 7
 
8  
-from milkymist import m1crg, lm32, norflash, uart, sram, s6ddrphy, dfii, asmicon
  8
+from milkymist import m1crg, lm32, norflash, uart, sram, s6ddrphy, dfii, asmicon, identifier
9 9
 from cmacros import get_macros
10 10
 from constraints import Constraints
11 11
 
@@ -63,6 +63,8 @@ def csr_offset(name):
63 63
 	assert((base >= 0xe0000000) and (base <= 0xe0010000))
64 64
 	return (base - 0xe0000000)//0x800
65 65
 
  66
+version = get_macros("common/version.h")["VERSION"][1:-1]
  67
+
66 68
 def get():
67 69
 	#
68 70
 	# ASMI
@@ -112,9 +114,11 @@ def get():
112 114
 	# CSR
113 115
 	#
114 116
 	uart0 = uart.UART(csr_offset("UART"), clk_freq, baud=115200)
  117
+	identifier0 = identifier.Identifier(csr_offset("ID"), 0x4D31, version)
115 118
 	csrcon0 = csr.Interconnect(wishbone2csr0.csr, [
116 119
 		uart0.bank.interface,
117  
-		dfii0.bank.interface
  120
+		dfii0.bank.interface,
  121
+		identifier0.bank.interface
118 122
 	])
119 123
 	
120 124
 	#

No commit comments for this range

Something went wrong with that request. Please try again.