Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/misoc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 59a5dede39ef
Choose a base ref
...
head repository: m-labs/misoc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 43b15f95dc63
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Feb 26, 2016

  1. Copy the full SHA
    aa3a1c4 View commit details
  2. Copy the full SHA
    43b15f9 View commit details
Showing with 29 additions and 50 deletions.
  1. +26 −8 misoc/software/bios/boot.c
  2. +1 −1 misoc/software/bios/boot.h
  3. +2 −41 misoc/software/bios/main.c
34 changes: 26 additions & 8 deletions misoc/software/bios/boot.c
Original file line number Diff line number Diff line change
@@ -27,6 +27,12 @@ static void __attribute__((noreturn)) boot(unsigned int r1, unsigned int r2, uns
while(1);
}

enum {
ACK_TIMEOUT,
ACK_CANCELLED,
ACK_OK
};

static int check_ack(void)
{
int recognized;
@@ -42,10 +48,12 @@ static int check_ack(void)
if(uart_read_nonblock()) {
char c;
c = uart_read();
if((c == 'Q') || (c == '\e'))
return ACK_CANCELLED;
if(c == str[recognized]) {
recognized++;
if(recognized == SFL_MAGIC_LEN)
return 1;
return ACK_OK;
} else {
if(c == str[0])
recognized = 1;
@@ -55,30 +63,39 @@ static int check_ack(void)
}
timer0_update_value_write(1);
}
return 0;
return ACK_TIMEOUT;
}

#define MAX_FAILED 5

void serialboot(void)
/* Returns 1 if other boot methods should be tried */
int serialboot(void)
{
struct sfl_frame frame;
int failed;
unsigned int cmdline_adr, initrdstart_adr, initrdend_adr;
static const char str[SFL_MAGIC_LEN+1] = SFL_MAGIC_REQ;
const char *c;
int ack_status;

printf("Booting from serial...\n");
printf("Press Q or ESC to abort boot completely.\n");

c = str;
while(*c) {
uart_write(*c);
c++;
}
if(!check_ack()) {
ack_status = check_ack();
if(ack_status == ACK_TIMEOUT) {
printf("Timeout\n");
return;
return 1;
}
if(ack_status == ACK_CANCELLED) {
printf("Cancelled\n");
return 0;
}
/* assume ACK_OK */

failed = 0;
cmdline_adr = initrdstart_adr = initrdend_adr = 0;
@@ -102,7 +119,7 @@ void serialboot(void)
failed++;
if(failed == MAX_FAILED) {
printf("Too many consecutive errors, aborting");
return;
return 1;
}
uart_write(SFL_ACK_CRCERROR);
continue;
@@ -113,7 +130,7 @@ void serialboot(void)
case SFL_CMD_ABORT:
failed = 0;
uart_write(SFL_ACK_SUCCESS);
return;
return 1;
case SFL_CMD_LOAD: {
char *writepointer;

@@ -168,12 +185,13 @@ void serialboot(void)
failed++;
if(failed == MAX_FAILED) {
printf("Too many consecutive errors, aborting");
return;
return 1;
}
uart_write(SFL_ACK_UNKNOWN);
break;
}
}
return 1;
}

#ifdef CSR_ETHMAC_BASE
2 changes: 1 addition & 1 deletion misoc/software/bios/boot.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __BOOT_H
#define __BOOT_H

void serialboot(void);
int serialboot(void);
void netboot(void);
void flashboot(void);
void romboot(void);
43 changes: 2 additions & 41 deletions misoc/software/bios/main.c
Original file line number Diff line number Diff line change
@@ -456,51 +456,12 @@ static void readstr(char *s, int size)
}
}

static int test_user_abort(void)
{
char c;

printf("Automatic boot in 2 seconds...\n");
printf("Q/ESC: abort boot\n");
printf("F7: boot from serial\n");
#ifdef CSR_ETHMAC_BASE
printf("F8: boot from network\n");
#endif
timer0_en_write(0);
timer0_reload_write(0);
timer0_load_write(CONFIG_CLOCK_FREQUENCY*2);
timer0_en_write(1);
timer0_update_value_write(1);
while(timer0_value_read()) {
if(readchar_nonblock()) {
c = readchar();
if((c == 'Q')||(c == '\e')) {
puts("Aborted");
return 0;
}
if(c == 0x06) {
serialboot();
return 0;
}
#ifdef CSR_ETHMAC_BASE
if(c == 0x07) {
netboot();
return 0;
}
#endif
}
timer0_update_value_write(1);
}
return 1;
}

static void boot_sequence(void)
{
if(test_user_abort()) {
if(serialboot()) {
#ifdef FLASH_BOOT_ADDRESS
flashboot();
#endif
serialboot();
#ifdef CSR_ETHMAC_BASE
#ifdef CSR_ETHPHY_MODE_DETECTION_MODE_ADDR
eth_mode();
@@ -523,7 +484,7 @@ int main(int i, char **c)
irq_setie(1);
uart_init();
puts("\nMiSoC BIOS\n"
"(c) Copyright 2007-2015 M-Labs Limited\n"
"(c) Copyright 2007-2016 M-Labs Limited\n"
"Built "__DATE__" "__TIME__"\n");
crcbios();
#ifdef CSR_ETHMAC_BASE