cris: Break out image loading to hw/cris-boot.c.
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@axis.com>
This commit is contained in:
parent
2024c53950
commit
77d4f95e11
@ -233,7 +233,10 @@ obj-microblaze-y += xilinx_ethlite.o
|
|||||||
obj-microblaze-$(CONFIG_FDT) += device_tree.o
|
obj-microblaze-$(CONFIG_FDT) += device_tree.o
|
||||||
|
|
||||||
# Boards
|
# Boards
|
||||||
obj-cris-y = cris_pic_cpu.o etraxfs.o axis_dev88.o
|
obj-cris-y = cris_pic_cpu.o
|
||||||
|
obj-cris-y += cris-boot.o
|
||||||
|
obj-cris-y += etraxfs.o axis_dev88.o
|
||||||
|
obj-cris-y += axis_dev88.o
|
||||||
|
|
||||||
# IO blocks
|
# IO blocks
|
||||||
obj-cris-y += etraxfs_dma.o
|
obj-cris-y += etraxfs_dma.o
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "etraxfs.h"
|
#include "etraxfs.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "elf.h"
|
#include "elf.h"
|
||||||
|
#include "cris-boot.h"
|
||||||
|
|
||||||
#define D(x)
|
#define D(x)
|
||||||
#define DNAND(x)
|
#define DNAND(x)
|
||||||
@ -240,28 +241,7 @@ static CPUWriteMemoryFunc * const gpio_write[] = {
|
|||||||
|
|
||||||
#define INTMEM_SIZE (128 * 1024)
|
#define INTMEM_SIZE (128 * 1024)
|
||||||
|
|
||||||
static struct {
|
static struct cris_load_info li;
|
||||||
uint32_t bootstrap_pc;
|
|
||||||
uint32_t regs[16];
|
|
||||||
} loadargs;
|
|
||||||
|
|
||||||
static void main_cpu_reset(void *opaque)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
CPUState *env = opaque;
|
|
||||||
cpu_reset(env);
|
|
||||||
|
|
||||||
env->pc = loadargs.bootstrap_pc;
|
|
||||||
for (i = 0; i < 16; i++) {
|
|
||||||
env->regs[i] = loadargs.regs[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
|
|
||||||
{
|
|
||||||
return addr - 0x80000000LL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
static
|
||||||
void axisdev88_init (ram_addr_t ram_size,
|
void axisdev88_init (ram_addr_t ram_size,
|
||||||
@ -275,7 +255,6 @@ void axisdev88_init (ram_addr_t ram_size,
|
|||||||
qemu_irq irq[30], nmi[2], *cpu_irq;
|
qemu_irq irq[30], nmi[2], *cpu_irq;
|
||||||
void *etraxfs_dmac;
|
void *etraxfs_dmac;
|
||||||
struct etraxfs_dma_client *eth[2] = {NULL, NULL};
|
struct etraxfs_dma_client *eth[2] = {NULL, NULL};
|
||||||
int kernel_size;
|
|
||||||
int i;
|
int i;
|
||||||
int nand_regs;
|
int nand_regs;
|
||||||
int gpio_regs;
|
int gpio_regs;
|
||||||
@ -287,7 +266,6 @@ void axisdev88_init (ram_addr_t ram_size,
|
|||||||
cpu_model = "crisv32";
|
cpu_model = "crisv32";
|
||||||
}
|
}
|
||||||
env = cpu_init(cpu_model);
|
env = cpu_init(cpu_model);
|
||||||
qemu_register_reset(main_cpu_reset, env);
|
|
||||||
|
|
||||||
/* allocate RAM */
|
/* allocate RAM */
|
||||||
phys_ram = qemu_ram_alloc(ram_size);
|
phys_ram = qemu_ram_alloc(ram_size);
|
||||||
@ -353,35 +331,14 @@ void axisdev88_init (ram_addr_t ram_size,
|
|||||||
irq[0x14 + i]);
|
irq[0x14 + i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kernel_filename) {
|
if (!kernel_filename) {
|
||||||
uint64_t entry, high;
|
fprintf(stderr, "Kernel image must be specified\n");
|
||||||
int kcmdline_len;
|
|
||||||
|
|
||||||
/* Boots a kernel elf binary, os/linux-2.6/vmlinux from the axis
|
|
||||||
devboard SDK. */
|
|
||||||
kernel_size = load_elf(kernel_filename, translate_kernel_address, NULL,
|
|
||||||
&entry, NULL, &high, 0, ELF_MACHINE, 0);
|
|
||||||
loadargs.bootstrap_pc = entry;
|
|
||||||
if (kernel_size < 0) {
|
|
||||||
/* Takes a kimage from the axis devboard SDK. */
|
|
||||||
kernel_size = load_image_targphys(kernel_filename, 0x40004000,
|
|
||||||
ram_size);
|
|
||||||
loadargs.bootstrap_pc = 0x40004000;
|
|
||||||
loadargs.regs[9] = 0x40004000 + kernel_size;
|
|
||||||
}
|
|
||||||
loadargs.regs[8] = 0x56902387; /* RAM init magic. */
|
|
||||||
|
|
||||||
if (kernel_cmdline && (kcmdline_len = strlen(kernel_cmdline))) {
|
|
||||||
if (kcmdline_len > 256) {
|
|
||||||
fprintf(stderr, "Too long CRIS kernel cmdline (max 256)\n");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
/* Let the kernel know we are modifying the cmdline. */
|
|
||||||
loadargs.regs[10] = 0x87109563;
|
li.image_filename = kernel_filename;
|
||||||
loadargs.regs[11] = 0x40000000;
|
li.cmdline = kernel_cmdline;
|
||||||
pstrcpy_targphys("cmdline", loadargs.regs[11], 256, kernel_cmdline);
|
cris_load_image(env, &li);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QEMUMachine axisdev88_machine = {
|
static QEMUMachine axisdev88_machine = {
|
||||||
|
97
hw/cris-boot.c
Normal file
97
hw/cris-boot.c
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* CRIS image loading.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 Edgar E. Iglesias, Axis Communications AB.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "hw.h"
|
||||||
|
#include "sysemu.h"
|
||||||
|
#include "loader.h"
|
||||||
|
#include "elf.h"
|
||||||
|
#include "cris-boot.h"
|
||||||
|
|
||||||
|
static void main_cpu_reset(void *opaque)
|
||||||
|
{
|
||||||
|
CPUState *env = opaque;
|
||||||
|
struct cris_load_info *li;
|
||||||
|
|
||||||
|
li = env->load_info;
|
||||||
|
|
||||||
|
cpu_reset(env);
|
||||||
|
|
||||||
|
if (!li) {
|
||||||
|
/* nothing more to do. */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
env->pc = li->entry;
|
||||||
|
|
||||||
|
if (li->image_filename) {
|
||||||
|
env->regs[8] = 0x56902387; /* RAM boot magic. */
|
||||||
|
env->regs[9] = 0x40004000 + li->image_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (li->cmdline) {
|
||||||
|
/* Let the kernel know we are modifying the cmdline. */
|
||||||
|
env->regs[10] = 0x87109563;
|
||||||
|
env->regs[11] = 0x40000000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
|
||||||
|
{
|
||||||
|
return addr - 0x80000000LL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cris_load_image(CPUState *env, struct cris_load_info *li)
|
||||||
|
{
|
||||||
|
uint64_t entry, high;
|
||||||
|
int kcmdline_len;
|
||||||
|
int image_size;
|
||||||
|
|
||||||
|
env->load_info = li;
|
||||||
|
/* Boots a kernel elf binary, os/linux-2.6/vmlinux from the axis
|
||||||
|
devboard SDK. */
|
||||||
|
image_size = load_elf(li->image_filename, translate_kernel_address, NULL,
|
||||||
|
&entry, NULL, &high, 0, ELF_MACHINE, 0);
|
||||||
|
li->entry = entry;
|
||||||
|
if (image_size < 0) {
|
||||||
|
/* Takes a kimage from the axis devboard SDK. */
|
||||||
|
image_size = load_image_targphys(li->image_filename, 0x40004000,
|
||||||
|
ram_size);
|
||||||
|
li->entry = 0x40004000;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (image_size < 0) {
|
||||||
|
fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
||||||
|
li->image_filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (li->cmdline && (kcmdline_len = strlen(li->cmdline))) {
|
||||||
|
if (kcmdline_len > 256) {
|
||||||
|
fprintf(stderr, "Too long CRIS kernel cmdline (max 256)\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
pstrcpy_targphys("cmdline", 0x40000000, 256, li->cmdline);
|
||||||
|
}
|
||||||
|
qemu_register_reset(main_cpu_reset, env);
|
||||||
|
}
|
11
hw/cris-boot.h
Normal file
11
hw/cris-boot.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
struct cris_load_info
|
||||||
|
{
|
||||||
|
const char *image_filename;
|
||||||
|
const char *cmdline;
|
||||||
|
int image_size;
|
||||||
|
|
||||||
|
target_phys_addr_t entry;
|
||||||
|
};
|
||||||
|
|
||||||
|
void cris_load_image(CPUState *env, struct cris_load_info *li);
|
53
hw/etraxfs.c
53
hw/etraxfs.c
@ -30,23 +30,17 @@
|
|||||||
#include "etraxfs.h"
|
#include "etraxfs.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "elf.h"
|
#include "elf.h"
|
||||||
|
#include "cris-boot.h"
|
||||||
|
|
||||||
#define FLASH_SIZE 0x2000000
|
#define FLASH_SIZE 0x2000000
|
||||||
#define INTMEM_SIZE (128 * 1024)
|
#define INTMEM_SIZE (128 * 1024)
|
||||||
|
|
||||||
static uint32_t bootstrap_pc;
|
static struct cris_load_info li;
|
||||||
|
|
||||||
static void main_cpu_reset(void *opaque)
|
static void flash_cpu_reset(void *opaque)
|
||||||
{
|
{
|
||||||
CPUState *env = opaque;
|
CPUState *env = opaque;
|
||||||
cpu_reset(env);
|
cpu_reset(env);
|
||||||
|
|
||||||
env->pc = bootstrap_pc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
|
|
||||||
{
|
|
||||||
return addr - 0x80000000LL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -61,7 +55,6 @@ void bareetraxfs_init (ram_addr_t ram_size,
|
|||||||
qemu_irq irq[30], nmi[2], *cpu_irq;
|
qemu_irq irq[30], nmi[2], *cpu_irq;
|
||||||
void *etraxfs_dmac;
|
void *etraxfs_dmac;
|
||||||
struct etraxfs_dma_client *eth[2] = {NULL, NULL};
|
struct etraxfs_dma_client *eth[2] = {NULL, NULL};
|
||||||
int kernel_size;
|
|
||||||
DriveInfo *dinfo;
|
DriveInfo *dinfo;
|
||||||
int i;
|
int i;
|
||||||
ram_addr_t phys_ram;
|
ram_addr_t phys_ram;
|
||||||
@ -73,7 +66,6 @@ void bareetraxfs_init (ram_addr_t ram_size,
|
|||||||
cpu_model = "crisv32";
|
cpu_model = "crisv32";
|
||||||
}
|
}
|
||||||
env = cpu_init(cpu_model);
|
env = cpu_init(cpu_model);
|
||||||
qemu_register_reset(main_cpu_reset, env);
|
|
||||||
|
|
||||||
/* allocate RAM */
|
/* allocate RAM */
|
||||||
phys_ram = qemu_ram_alloc(ram_size);
|
phys_ram = qemu_ram_alloc(ram_size);
|
||||||
@ -137,38 +129,19 @@ void bareetraxfs_init (ram_addr_t ram_size,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (kernel_filename) {
|
if (kernel_filename) {
|
||||||
uint64_t entry, high;
|
li.image_filename = kernel_filename;
|
||||||
int kcmdline_len;
|
li.cmdline = kernel_cmdline;
|
||||||
|
cris_load_image(env, &li);
|
||||||
/* Boots a kernel elf binary, os/linux-2.6/vmlinux from the axis
|
} else {
|
||||||
devboard SDK. */
|
if (!dinfo) {
|
||||||
kernel_size = load_elf(kernel_filename, translate_kernel_address, NULL,
|
fprintf(stderr,
|
||||||
&entry, NULL, &high, 0, ELF_MACHINE, 0);
|
"Provide a kernel image or a flash image to boot from.\n");
|
||||||
bootstrap_pc = entry;
|
|
||||||
if (kernel_size < 0) {
|
|
||||||
/* Takes a kimage from the axis devboard SDK. */
|
|
||||||
kernel_size = load_image_targphys(kernel_filename, 0x40004000,
|
|
||||||
ram_size);
|
|
||||||
bootstrap_pc = 0x40004000;
|
|
||||||
env->regs[9] = 0x40004000 + kernel_size;
|
|
||||||
}
|
|
||||||
env->regs[8] = 0x56902387; /* RAM init magic. */
|
|
||||||
|
|
||||||
if (kernel_cmdline && (kcmdline_len = strlen(kernel_cmdline))) {
|
|
||||||
if (kcmdline_len > 256) {
|
|
||||||
fprintf(stderr, "Too long CRIS kernel cmdline (max 256)\n");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
/* Let the kernel know we are modifying the cmdline. */
|
|
||||||
env->regs[10] = 0x87109563;
|
|
||||||
env->regs[11] = 0x40000000;
|
|
||||||
pstrcpy_targphys("cmdline", env->regs[11], 256, kernel_cmdline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
env->pc = bootstrap_pc;
|
|
||||||
|
|
||||||
printf ("pc =%x\n", env->pc);
|
/* Nothing more to do for flash images, those boot from addr 0. */
|
||||||
printf ("ram size =%ld\n", ram_size);
|
qemu_register_reset(flash_cpu_reset, env);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static QEMUMachine bareetraxfs_machine = {
|
static QEMUMachine bareetraxfs_machine = {
|
||||||
|
@ -155,6 +155,8 @@ typedef struct CPUCRISState {
|
|||||||
uint32_t lo;
|
uint32_t lo;
|
||||||
} tlbsets[2][4][16];
|
} tlbsets[2][4][16];
|
||||||
|
|
||||||
|
void *load_info;
|
||||||
|
|
||||||
CPU_COMMON
|
CPU_COMMON
|
||||||
} CPUCRISState;
|
} CPUCRISState;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user