28a893b9b8cdf82b29bfbe432a3e547a385d9978
[litex.git] / litex / soc / software / bios / main.c
1 // This file is Copyright (c) 2013-2014 Sebastien Bourdeauducq <sb@m-labs.hk>
2 // This file is Copyright (c) 2014-2019 Florent Kermarrec <florent@enjoy-digital.fr>
3 // This file is Copyright (c) 2015 Yann Sionneau <ys@m-labs.hk>
4 // This file is Copyright (c) 2015 whitequark <whitequark@whitequark.org>
5 // This file is Copyright (c) 2019 Ambroz Bizjak <ambrop7@gmail.com>
6 // This file is Copyright (c) 2019 Caleb Jamison <cbjamo@gmail.com>
7 // This file is Copyright (c) 2018 Dolu1990 <charles.papon.90@gmail.com>
8 // This file is Copyright (c) 2018 Felix Held <felix-github@felixheld.de>
9 // This file is Copyright (c) 2019 Gabriel L. Somlo <gsomlo@gmail.com>
10 // This file is Copyright (c) 2018 Jean-François Nguyen <jf@lambdaconcept.fr>
11 // This file is Copyright (c) 2018 Sergiusz Bazanski <q3k@q3k.org>
12 // This file is Copyright (c) 2016 Tim 'mithro' Ansell <mithro@mithis.com>
13 // This file is Copyright (c) 2020 Franck Jullien <franck.jullien@gmail.com>
14 // This file is Copyright (c) 2020 Antmicro <www.antmicro.com>
15
16 // License: BSD
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <console.h>
21 #include <string.h>
22 #include <uart.h>
23 #include <system.h>
24 #include <id.h>
25 #include <irq.h>
26 #include <crc.h>
27
28 #include "boot.h"
29 #include "readline.h"
30 #include "helpers.h"
31 #include "command.h"
32
33 #include <generated/csr.h>
34 #include <generated/soc.h>
35 #include <generated/mem.h>
36 #include <generated/git.h>
37
38 #include <spiflash.h>
39
40 #include <liblitedram/sdram.h>
41
42 #include <libliteeth/udp.h>
43 #include <libliteeth/mdio.h>
44
45 #include <liblitespi/spiflash.h>
46
47 #include <liblitesdcard/sdcard.h>
48
49 static void boot_sequence(void)
50 {
51 if(serialboot()) {
52 #ifdef FLASH_BOOT_ADDRESS
53 flashboot();
54 #endif
55 #ifdef ROM_BOOT_ADDRESS
56 romboot();
57 #endif
58 #if defined(CSR_SPISDCARD_BASE) || defined(CSR_SDCORE_BASE)
59 sdcardboot();
60 #endif
61 #ifdef CSR_ETHMAC_BASE
62 #ifdef CSR_ETHPHY_MODE_DETECTION_MODE_ADDR
63 eth_mode();
64 #endif
65 netboot();
66 #endif
67 printf("No boot medium found\n");
68 }
69 }
70
71 int main(int i, char **c)
72 {
73 char buffer[CMD_LINE_BUFFER_SIZE];
74 char *params[MAX_PARAM];
75 char *command;
76 struct command_struct *cmd;
77 int nb_params;
78 int sdr_ok;
79
80 #ifdef CONFIG_CPU_HAS_INTERRUPT
81 irq_setmask(0);
82 irq_setie(1);
83 #endif
84 uart_init();
85
86 printf("\n");
87 printf("\e[1m __ _ __ _ __\e[0m\n");
88 printf("\e[1m / / (_) /____ | |/_/\e[0m\n");
89 printf("\e[1m / /__/ / __/ -_)> <\e[0m\n");
90 printf("\e[1m /____/_/\\__/\\__/_/|_|\e[0m\n");
91 printf("\e[1m Build your hardware, easily!\e[0m\n");
92 printf("\n");
93 printf(" (c) Copyright 2012-2020 Enjoy-Digital\n");
94 printf(" (c) Copyright 2007-2015 M-Labs\n");
95 printf("\n");
96 printf(" BIOS built on "__DATE__" "__TIME__"\n");
97 crcbios();
98 printf("\n");
99 printf(" Migen git sha1: "MIGEN_GIT_SHA1"\n");
100 printf(" LiteX git sha1: "LITEX_GIT_SHA1"\n");
101 printf("\n");
102 printf("--=============== \e[1mSoC\e[0m ==================--\n");
103 printf("\e[1mCPU\e[0m:\t\t%s @ %dMHz\n",
104 CONFIG_CPU_HUMAN_NAME,
105 CONFIG_CLOCK_FREQUENCY/1000000);
106 printf("\e[1mBUS\e[0m:\t\t%s %d-bit @ %dGiB\n",
107 CONFIG_BUS_STANDARD,
108 CONFIG_BUS_DATA_WIDTH,
109 (1 << (CONFIG_BUS_ADDRESS_WIDTH - 30)));
110 printf("\e[1mCSR\e[0m:\t\t%d-bit data\n",
111 CONFIG_CSR_DATA_WIDTH);
112 printf("\e[1mROM\e[0m:\t\t%dKiB\n", ROM_SIZE/1024);
113 printf("\e[1mSRAM\e[0m:\t\t%dKiB\n", SRAM_SIZE/1024);
114 #ifdef CONFIG_L2_SIZE
115 printf("\e[1mL2\e[0m:\t\t%dKiB\n", CONFIG_L2_SIZE/1024);
116 #endif
117 #ifdef MAIN_RAM_SIZE
118 #ifdef CSR_SDRAM_BASE
119 printf("\e[1mSDRAM\e[0m:\t\t%dKiB %d-bit @ %dMHz\n",
120 MAIN_RAM_SIZE/1024,
121 sdrdatabits(),
122 sdrfreq()/1000000);
123 #else
124 printf("\e[1mMAIN-RAM\e[0m:\t%dKiB \n", MAIN_RAM_SIZE/1024);
125 #endif
126 #endif
127 printf("\n");
128
129 sdr_ok = 1;
130
131 #if defined(CSR_ETHMAC_BASE) || defined(CSR_SDRAM_BASE)
132 printf("--========== \e[1mInitialization\e[0m ============--\n");
133 #ifdef CSR_ETHMAC_BASE
134 eth_init();
135 #endif
136 #ifdef CSR_SDRAM_BASE
137 sdr_ok = sdrinit();
138 #else
139 #ifdef MAIN_RAM_TEST
140 sdr_ok = memtest();
141 #endif
142 #endif
143 if (sdr_ok !=1)
144 printf("Memory initialization failed\n");
145 printf("\n");
146 #endif
147 #ifdef CSR_SPIFLASH_MMAP_BASE
148 spiflash_init();
149 #endif
150
151 if(sdr_ok) {
152 printf("--============== \e[1mBoot\e[0m ==================--\n");
153 boot_sequence();
154 printf("\n");
155 }
156
157 printf("--============= \e[1mConsole\e[0m ================--\n");
158 #if !defined(TERM_MINI) && !defined(TERM_NO_HIST)
159 hist_init();
160 #endif
161 printf("\n%s", PROMPT);
162 while(1) {
163 readline(buffer, CMD_LINE_BUFFER_SIZE);
164 if (buffer[0] != 0) {
165 printf("\n");
166 nb_params = get_param(buffer, &command, params);
167 cmd = command_dispatcher(command, nb_params, params);
168 if (!cmd)
169 printf("Command not found");
170 }
171 printf("\n%s", PROMPT);
172 }
173 return 0;
174 }