abagu
5 years ago
8 changed files with 439 additions and 41 deletions
@ -0,0 +1,133 @@ |
|||||
|
/* vim: set ts=4 et sw=4:
|
||||
|
* @file nor.c |
||||
|
* |
||||
|
* @brief The nor boot driver |
||||
|
*/ |
||||
|
#include "types.h" |
||||
|
#include "vsky/libdsp/inc/elfloader.h" |
||||
|
#include <vsky/libdsp/fs/vsky_yaffs2.h> |
||||
|
#include <vsky/libdsp/inc/nand.h> |
||||
|
#include <stdio.h> |
||||
|
#include <string.h> |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
/**
|
||||
|
* @brief The nor master control block which tracks the current nor boot information |
||||
|
*/ |
||||
|
typedef struct nandmcb_s { |
||||
|
uint32 fpos; /**< Current file position. This is an absolute address, not relative to startPos */ |
||||
|
uint32 startPos; /**< Initial file position */ |
||||
|
int fd; |
||||
|
} nandmcb_t; |
||||
|
|
||||
|
static nandmcb_t nmcb; |
||||
|
|
||||
|
/**
|
||||
|
* @brief |
||||
|
* Set the current file position |
||||
|
*/ |
||||
|
static Int32 __yaffs_seek (Int32 loc, Int32 from) |
||||
|
{ |
||||
|
/* Can't seek from the end of the file, since the end is not known */ |
||||
|
if (from == 0) |
||||
|
nmcb.fpos = nmcb.startPos + loc; |
||||
|
else if (from == 1) |
||||
|
nmcb.fpos += loc; |
||||
|
else |
||||
|
return (-1); |
||||
|
|
||||
|
if (nmcb.fpos < nmcb.startPos) |
||||
|
nmcb.fpos = nmcb.startPos; |
||||
|
|
||||
|
return (0); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* @brief |
||||
|
* Initialize the control structure. Note that the interface value was |
||||
|
* previously verified in the top level nor boot control. |
||||
|
*/ |
||||
|
static Int32 __yaffs_open (void *ptr_driver, void (*asyncComplete)(void *)) |
||||
|
{ |
||||
|
const char *name = ptr_driver; |
||||
|
nmcb.fd = yaffs_open(name, O_RDONLY, S_IREAD); |
||||
|
if (nmcb.fd < 0) { |
||||
|
printf("cant open %s to parse\r\n", name); |
||||
|
return -1; |
||||
|
} |
||||
|
nmcb.startPos = 0; |
||||
|
nmcb.fpos = 0; |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
/**
|
||||
|
* @brief |
||||
|
* Read data from the current address. This function is used |
||||
|
* for peek as well as read. |
||||
|
*/ |
||||
|
static Int32 __yaffs_read (Uint8 *ptr_buf, Uint32 num_bytes) |
||||
|
{ |
||||
|
int nr; |
||||
|
if (nmcb.fd < 0) |
||||
|
return (-1); |
||||
|
|
||||
|
yaffs_lseek(nmcb.fd, nmcb.fpos, SEEK_SET); |
||||
|
nr = yaffs_read(nmcb.fd, ptr_buf, num_bytes); |
||||
|
nmcb.fpos += nr; |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
static Int32 __yaffs_peek(Uint8 *ptr_buf, Uint32 num) |
||||
|
{ |
||||
|
Uint32 pos = nmcb.fpos; |
||||
|
int r = yaffs_read(nmcb.fd, ptr_buf, num); |
||||
|
nmcb.fpos = pos; |
||||
|
return (r); |
||||
|
} |
||||
|
|
||||
|
/**
|
||||
|
* @brief |
||||
|
* Return the number of bytes available for current read. |
||||
|
* Always return 1k |
||||
|
*/ |
||||
|
static Int32 __yaffs_query (void) |
||||
|
{ |
||||
|
return 0x400; |
||||
|
} |
||||
|
|
||||
|
/**
|
||||
|
* @brief |
||||
|
* Close the nor driver |
||||
|
*/ |
||||
|
static Int32 __yaffs_close (void) |
||||
|
{ |
||||
|
yaffs_close(nmcb.fd); |
||||
|
return (0); |
||||
|
} |
||||
|
|
||||
|
/**
|
||||
|
* @brief |
||||
|
* The global nor module function table |
||||
|
*/ |
||||
|
static BOOT_MODULE_FXN_TABLE __boot_module = { |
||||
|
__yaffs_open, /* Open API */ |
||||
|
__yaffs_close, /* Close API */ |
||||
|
__yaffs_read, /* Read API */ |
||||
|
NULL, /* Write API */ |
||||
|
__yaffs_peek, /* Peek API */ |
||||
|
__yaffs_seek, /* Seek API */ |
||||
|
__yaffs_query /* Query API */ |
||||
|
}; |
||||
|
|
||||
|
unsigned int yaffs_load_elf(const char *file) |
||||
|
{ |
||||
|
unsigned int entry = 0; |
||||
|
|
||||
|
if (__boot_module.open((void *)file, NULL)) { |
||||
|
return 0; |
||||
|
} |
||||
|
load_elf(&__boot_module, &entry); |
||||
|
__boot_module.close(); |
||||
|
return entry; |
||||
|
} |
@ -1,34 +1,34 @@ |
|||||
-c -heap 0x100000 -stack 0x4000 |
-c -heap 0x8000000 -stack 0x2000000 |
||||
|
|
||||
/* Memory Map */ |
/* Memory Map */ |
||||
MEMORY { |
MEMORY { |
||||
L1PSRAM (RWX) : org = 0x0E00000, len = 0x7FFF |
L1PSRAM (RWX) : org = 0x0E00000, len = 0x7FFF |
||||
L1DSRAM (RWX) : org = 0x0F00000, len = 0x7FFF |
L1DSRAM (RWX) : org = 0x0F00000, len = 0x7FFF |
||||
L2SRAM (RWX) : org = 0x0800000, len = 0x080000 |
L2SRAM (RWX) : org = 0x0800000, len = 0x080000 |
||||
MSMCSRAM (RWX) : org = 0xc000000, len = 0x200000 |
MSMCSRAM (RWX) : org = 0xc000000, len = 0x400000 |
||||
DDR3 (RWX) : org = 0x80000000,len = 0x40000000 |
DDR3 (RWX) : org = 0x80000000,len = 0x10000000 |
||||
} |
} |
||||
|
|
||||
SECTIONS { |
SECTIONS { |
||||
.sysmem > MSMCSRAM |
.sysmem > DDR3 |
||||
.csl_vect > MSMCSRAM |
.csl_vect > DDR3 |
||||
.text > MSMCSRAM |
.text > DDR3 |
||||
GROUP (NEAR_DP) |
GROUP (NEAR_DP) |
||||
{ |
{ |
||||
.neardata |
.neardata |
||||
.rodata |
.rodata |
||||
.bss |
.bss |
||||
} load > MSMCSRAM |
} load > DDR3 |
||||
|
|
||||
.stack > MSMCSRAM |
.stack > DDR3 |
||||
.cinit > MSMCSRAM |
.cinit > DDR3 |
||||
.cio > MSMCSRAM |
.cio > DDR3 |
||||
.const > MSMCSRAM |
.const > DDR3 |
||||
.data > MSMCSRAM |
.data > DDR3 |
||||
.switch > MSMCSRAM |
.switch > DDR3 |
||||
.far > MSMCSRAM |
.far > DDR3 |
||||
.testMem > MSMCSRAM |
.testMem > DDR3 |
||||
.fardata > MSMCSRAM |
.fardata > DDR3 |
||||
.init_array > MSMCSRAM |
.init_array > DDR3 |
||||
.serial_buffer > MSMCSRAM |
.serial_buffer > DDR3 |
||||
} |
} |
||||
|
Loading…
Reference in new issue