bios: move helper functions to their own file
This commit is contained in:
parent
bc5a1986e2
commit
86cab3d362
|
@ -10,7 +10,13 @@ ifdef TFTP_SERVER_PORT
|
|||
CFLAGS += -DTFTP_SERVER_PORT=$(TFTP_SERVER_PORT)
|
||||
endif
|
||||
|
||||
OBJECTS=isr.o sdram.o sdcard.o main.o boot-helper.o boot.o
|
||||
OBJECTS = isr.o \
|
||||
sdram.o \
|
||||
sdcard.o \
|
||||
main.o \
|
||||
boot-helper.o \
|
||||
boot.o \
|
||||
helpers.o
|
||||
|
||||
ifdef TERM_NO_HIST
|
||||
CFLAGS += -DTERM_NO_HIST
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
// This file is Copyright (c) 2017 Florent Kermarrec <florent@enjoy-digital.fr>
|
||||
|
||||
// SPDX-License-Identifier: BSD-Source-Code
|
||||
|
||||
#include <stdio.h>
|
||||
#include <console.h>
|
||||
#include <crc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "readline.h"
|
||||
#include "helpers.h"
|
||||
|
||||
extern unsigned int _ftext, _edata;
|
||||
|
||||
#define NUMBER_OF_BYTES_ON_A_LINE 16
|
||||
void dump_bytes(unsigned int *ptr, int count, unsigned long addr)
|
||||
{
|
||||
char *data = (char *)ptr;
|
||||
int line_bytes = 0, i = 0;
|
||||
|
||||
putsnonl("Memory dump:");
|
||||
while (count > 0) {
|
||||
line_bytes =
|
||||
(count > NUMBER_OF_BYTES_ON_A_LINE)?
|
||||
NUMBER_OF_BYTES_ON_A_LINE : count;
|
||||
|
||||
printf("\n0x%08x ", addr);
|
||||
for (i = 0; i < line_bytes; i++)
|
||||
printf("%02x ", *(unsigned char *)(data+i));
|
||||
|
||||
for (; i < NUMBER_OF_BYTES_ON_A_LINE; i++)
|
||||
printf(" ");
|
||||
|
||||
printf(" ");
|
||||
|
||||
for (i = 0; i<line_bytes; i++) {
|
||||
if ((*(data+i) < 0x20) || (*(data+i) > 0x7e))
|
||||
printf(".");
|
||||
else
|
||||
printf("%c", *(data+i));
|
||||
}
|
||||
|
||||
for (; i < NUMBER_OF_BYTES_ON_A_LINE; i++)
|
||||
printf(" ");
|
||||
|
||||
data += (char)line_bytes;
|
||||
count -= line_bytes;
|
||||
addr += line_bytes;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void crcbios(void)
|
||||
{
|
||||
unsigned long offset_bios;
|
||||
unsigned long length;
|
||||
unsigned int expected_crc;
|
||||
unsigned int actual_crc;
|
||||
|
||||
/*
|
||||
* _edata is located right after the end of the flat
|
||||
* binary image. The CRC tool writes the 32-bit CRC here.
|
||||
* We also use the address of _edata to know the length
|
||||
* of our code.
|
||||
*/
|
||||
offset_bios = (unsigned long)&_ftext;
|
||||
expected_crc = _edata;
|
||||
length = (unsigned long)&_edata - offset_bios;
|
||||
actual_crc = crc32((unsigned char *)offset_bios, length);
|
||||
if (expected_crc == actual_crc)
|
||||
printf(" BIOS CRC passed (%08x)\n", actual_crc);
|
||||
else {
|
||||
printf(" BIOS CRC failed (expected %08x, got %08x)\n", expected_crc, actual_crc);
|
||||
printf(" The system will continue, but expect problems.\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef __HELPERS_H__
|
||||
#define __HELPERS_H__
|
||||
|
||||
void dump_bytes(unsigned int *ptr, int count, unsigned long addr);
|
||||
void crcbios(void);
|
||||
|
||||
#endif
|
|
@ -44,47 +44,10 @@
|
|||
#include "sdcard.h"
|
||||
#include "boot.h"
|
||||
#include "readline.h"
|
||||
#include "helpers.h"
|
||||
|
||||
/* General address space functions */
|
||||
|
||||
#define NUMBER_OF_BYTES_ON_A_LINE 16
|
||||
static void dump_bytes(unsigned int *ptr, int count, unsigned long addr)
|
||||
{
|
||||
char *data = (char *)ptr;
|
||||
int line_bytes = 0, i = 0;
|
||||
|
||||
putsnonl("Memory dump:");
|
||||
while(count > 0){
|
||||
line_bytes =
|
||||
(count > NUMBER_OF_BYTES_ON_A_LINE)?
|
||||
NUMBER_OF_BYTES_ON_A_LINE : count;
|
||||
|
||||
printf("\n0x%08x ", addr);
|
||||
for(i=0;i<line_bytes;i++)
|
||||
printf("%02x ", *(unsigned char *)(data+i));
|
||||
|
||||
for(;i<NUMBER_OF_BYTES_ON_A_LINE;i++)
|
||||
printf(" ");
|
||||
|
||||
printf(" ");
|
||||
|
||||
for(i=0;i<line_bytes;i++) {
|
||||
if((*(data+i) < 0x20) || (*(data+i) > 0x7e))
|
||||
printf(".");
|
||||
else
|
||||
printf("%c", *(data+i));
|
||||
}
|
||||
|
||||
for(;i<NUMBER_OF_BYTES_ON_A_LINE;i++)
|
||||
printf(" ");
|
||||
|
||||
data += (char)line_bytes;
|
||||
count -= line_bytes;
|
||||
addr += line_bytes;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void mr(char *startaddr, char *len)
|
||||
{
|
||||
char *c;
|
||||
|
@ -523,33 +486,6 @@ static void do_command(char *c)
|
|||
printf("Command not found\n");
|
||||
}
|
||||
|
||||
extern unsigned int _ftext, _edata;
|
||||
|
||||
static void crcbios(void)
|
||||
{
|
||||
unsigned long offset_bios;
|
||||
unsigned long length;
|
||||
unsigned int expected_crc;
|
||||
unsigned int actual_crc;
|
||||
|
||||
/*
|
||||
* _edata is located right after the end of the flat
|
||||
* binary image. The CRC tool writes the 32-bit CRC here.
|
||||
* We also use the address of _edata to know the length
|
||||
* of our code.
|
||||
*/
|
||||
offset_bios = (unsigned long)&_ftext;
|
||||
expected_crc = _edata;
|
||||
length = (unsigned long)&_edata - offset_bios;
|
||||
actual_crc = crc32((unsigned char *)offset_bios, length);
|
||||
if(expected_crc == actual_crc)
|
||||
printf(" BIOS CRC passed (%08x)\n", actual_crc);
|
||||
else {
|
||||
printf(" BIOS CRC failed (expected %08x, got %08x)\n", expected_crc, actual_crc);
|
||||
printf(" The system will continue, but expect problems.\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void boot_sequence(void)
|
||||
{
|
||||
if(serialboot()) {
|
||||
|
|
Loading…
Reference in New Issue