Skip to content

Commit

Permalink
[image] use image loader to load linux
Browse files Browse the repository at this point in the history
  • Loading branch information
YuzukiTsuru committed Jan 11, 2024
1 parent 258ca2e commit e7f551a
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 570 deletions.
6 changes: 1 addition & 5 deletions board/100ask-t113i/syter_boot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ extern dram_para_t dram_para;

image_info_t image;

static int boot_image_setup(uint8_t *addr, uint32_t *entry) {
return zImage_loader(addr, entry);
}

#define CHUNK_SIZE 0x20000

static int fatfs_loadimage(char *filename, BYTE *dest) {
Expand Down Expand Up @@ -518,7 +514,7 @@ int cmd_boot(int argc, const char **argv) {
void (*kernel_entry)(int zero, int arch, uint32_t params);

/* Set up boot parameters for the kernel. */
if (boot_image_setup((uint8_t *) image.dest, &entry_point)) {
if (zImage_loader((uint8_t *) image.dest, &entry_point)) {
printk(LOG_LEVEL_ERROR, "boot setup failed\n");
abort();
}
Expand Down
46 changes: 5 additions & 41 deletions board/dongshanpi-aict/syter_amp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
#include <config.h>
#include <log.h>

#include <mmu.h>
#include <common.h>
#include <image_loader.h>
#include <jmp.h>
#include <mmu.h>

#include "sys-dram.h"
#include "sys-sdcard.h"
#include "sys-sid.h"
#include "sys-spi.h"

#include "libfdt.h"
#include "ff.h"
#include "libfdt.h"

#define CONFIG_KERNEL_FILENAME "zImage"
#define CONFIG_DTB_FILENAME "sunxi.dtb"
Expand Down Expand Up @@ -50,15 +51,6 @@ typedef struct {
char elf_filename[FILENAME_MAX_LEN];
} image_info_t;

/* Linux zImage Header */
#define LINUX_ZIMAGE_MAGIC 0x016f2818
typedef struct {
unsigned int code[9];
unsigned int magic;
unsigned int start;
unsigned int end;
} linux_zimage_header_t;

extern sunxi_serial_t uart_dbg;

extern dram_para_t dram_para;
Expand All @@ -76,33 +68,6 @@ extern sdhci_t sdhci0;

image_info_t image;

unsigned int code[9];
unsigned int magic;
unsigned int start;
unsigned int end;

static int boot_image_setup(unsigned char *addr, unsigned int *entry) {
linux_zimage_header_t *zimage_header = (linux_zimage_header_t *) addr;

printk(LOG_LEVEL_INFO, "Linux zImage->code = 0x");
for (int i = 0; i < 9; i++)
printk(LOG_LEVEL_MUTE, "%x", code[i]);

printk(LOG_LEVEL_MUTE, "\n");
printk(LOG_LEVEL_DEBUG, "Linux zImage->magic = 0x%x\n", zimage_header->magic);
printk(LOG_LEVEL_DEBUG, "Linux zImage->start = 0x%x\n", (unsigned int) addr + zimage_header->start);
printk(LOG_LEVEL_DEBUG, "Linux zImage->end = 0x%x\n", (unsigned int) addr + zimage_header->end);

if (zimage_header->magic == LINUX_ZIMAGE_MAGIC) {
*entry = ((unsigned int) addr + zimage_header->start);
return 0;
}

printk(LOG_LEVEL_ERROR, "unsupported kernel image\n");

return -1;
}

#define CHUNK_SIZE 0x20000

static int fatfs_loadimage(char *filename, BYTE *dest) {
Expand Down Expand Up @@ -202,7 +167,6 @@ static int load_sdcard(image_info_t *image) {
}



int main(void) {
sunxi_serial_init(&uart_dbg);

Expand All @@ -214,7 +178,7 @@ int main(void) {

sunxi_dram_init(&dram_para);

unsigned int entry_point = 0;
uint32_t entry_point = 0;
void (*kernel_entry)(int zero, int arch, unsigned int params);

sunxi_clk_dump();
Expand Down Expand Up @@ -258,7 +222,7 @@ int main(void) {

printk(LOG_LEVEL_INFO, "RISC-V E907 Core now Running... \n");

if (boot_image_setup((unsigned char *) image.dest, &entry_point)) {
if (zImage_loader((unsigned char *) image.dest, &entry_point)) {
printk(LOG_LEVEL_ERROR, "boot setup failed\n");
goto _fel;
}
Expand Down
43 changes: 3 additions & 40 deletions board/dongshanpi-aict/syter_boot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <cli_shell.h>
#include <cli_termesc.h>

#include <image_loader.h>

#include "sys-dram.h"
#include "sys-rtc.h"
#include "sys-sdcard.h"
Expand Down Expand Up @@ -74,15 +76,6 @@ typedef struct {

IniEntry entries[CONFIG_MAX_ENTRY];

/* Linux zImage Header */
#define LINUX_ZIMAGE_MAGIC 0x016f2818
typedef struct {
uint32_t code[9];
uint32_t magic;
uint32_t start;
uint32_t end;
} linux_zimage_header_t;

extern sunxi_serial_t uart_dbg;

extern sunxi_spi_t sunxi_spi0;
Expand All @@ -93,36 +86,6 @@ extern dram_para_t dram_para;

image_info_t image;

uint32_t code[9];
uint32_t magic;
uint32_t start;
uint32_t end;

static int boot_image_setup(uint8_t *addr, uint32_t *entry) {
linux_zimage_header_t *zimage_header = (linux_zimage_header_t *) addr;

printk(LOG_LEVEL_INFO, "Linux zImage->code = 0x");
for (int i = 0; i < 9; i++)
printk(LOG_LEVEL_MUTE, "%x", code[i]);

printk(LOG_LEVEL_MUTE, "\n");
printk(LOG_LEVEL_DEBUG, "Linux zImage->magic = 0x%x\n",
zimage_header->magic);
printk(LOG_LEVEL_DEBUG, "Linux zImage->start = 0x%x\n",
(uint32_t) addr + zimage_header->start);
printk(LOG_LEVEL_DEBUG, "Linux zImage->end = 0x%x\n",
(uint32_t) addr + zimage_header->end);

if (zimage_header->magic == LINUX_ZIMAGE_MAGIC) {
*entry = ((uint32_t) addr + zimage_header->start);
return 0;
}

printk(LOG_LEVEL_ERROR, "unsupported kernel image\n");

return -1;
}

#define CHUNK_SIZE 0x20000

static int fatfs_loadimage(char *filename, BYTE *dest) {
Expand Down Expand Up @@ -551,7 +514,7 @@ int cmd_boot(int argc, const char **argv) {
void (*kernel_entry)(int zero, int arch, uint32_t params);

/* Set up boot parameters for the kernel. */
if (boot_image_setup((uint8_t *) image.dest, &entry_point)) {
if (zImage_loader((uint8_t *) image.dest, &entry_point)) {
printk(LOG_LEVEL_ERROR, "boot setup failed\n");
abort();
}
Expand Down
43 changes: 3 additions & 40 deletions board/dongshanpi-aict/syter_boot_spi/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <cli_shell.h>
#include <cli_termesc.h>

#include <image_loader.h>

#include "sys-dram.h"
#include "sys-rtc.h"
#include "sys-sid.h"
Expand Down Expand Up @@ -55,15 +57,6 @@ typedef struct {
char of_filename[FILENAME_MAX_LEN];
} image_info_t;

/* Linux zImage Header */
#define LINUX_ZIMAGE_MAGIC 0x016f2818
typedef struct {
uint32_t code[9];
uint32_t magic;
uint32_t start;
uint32_t end;
} linux_zimage_header_t;

extern sunxi_serial_t uart_dbg;

extern sunxi_spi_t sunxi_spi0;
Expand All @@ -72,36 +65,6 @@ extern dram_para_t dram_para;

image_info_t image;

uint32_t code[9];
uint32_t magic;
uint32_t start;
uint32_t end;

static int boot_image_setup(uint8_t *addr, uint32_t *entry) {
linux_zimage_header_t *zimage_header = (linux_zimage_header_t *) addr;

printk(LOG_LEVEL_INFO, "Linux zImage->code = 0x");
for (int i = 0; i < 9; i++)
printk(LOG_LEVEL_MUTE, "%x", code[i]);

printk(LOG_LEVEL_MUTE, "\n");
printk(LOG_LEVEL_DEBUG, "Linux zImage->magic = 0x%x\n",
zimage_header->magic);
printk(LOG_LEVEL_DEBUG, "Linux zImage->start = 0x%x\n",
(uint32_t) addr + zimage_header->start);
printk(LOG_LEVEL_DEBUG, "Linux zImage->end = 0x%x\n",
(uint32_t) addr + zimage_header->end);

if (zimage_header->magic == LINUX_ZIMAGE_MAGIC) {
*entry = ((uint32_t) addr + zimage_header->start);
return 0;
}

printk(LOG_LEVEL_ERROR, "unsupported kernel image\n");

return -1;
}

int load_spi_nand(sunxi_spi_t *spi, image_info_t *image) {
linux_zimage_header_t *hdr;
unsigned int size;
Expand Down Expand Up @@ -210,7 +173,7 @@ int cmd_boot(int argc, const char **argv) {
dma_exit();

/* Set up boot parameters for the kernel. */
if (boot_image_setup((uint8_t *) image.dest, &entry_point)) {
if (zImage_loader((uint8_t *) image.dest, &entry_point)) {
printk(LOG_LEVEL_ERROR, "boot setup failed\n");
abort();
}
Expand Down
50 changes: 6 additions & 44 deletions board/dongshanpi-aict/syter_bootargs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <config.h>
#include <log.h>

#include <mmu.h>
#include <common.h>
#include <jmp.h>
#include <mmu.h>

#include "sys-dram.h"
#include "sys-sdcard.h"
Expand All @@ -21,6 +21,8 @@
#include <cli_shell.h>
#include <cli_termesc.h>

#include <image_loader.h>

#include "ff.h"
#include "libfdt.h"

Expand Down Expand Up @@ -49,15 +51,6 @@ typedef struct {
char of_filename[FILENAME_MAX_LEN];
} image_info_t;

/* Linux zImage Header */
#define LINUX_ZIMAGE_MAGIC 0x016f2818
typedef struct {
unsigned int code[9];
unsigned int magic;
unsigned int start;
unsigned int end;
} linux_zimage_header_t;

extern sunxi_serial_t uart_dbg;

extern sunxi_spi_t sunxi_spi0;
Expand All @@ -68,36 +61,6 @@ extern dram_para_t dram_para;

image_info_t image;

unsigned int code[9];
unsigned int magic;
unsigned int start;
unsigned int end;

static int boot_image_setup(unsigned char *addr, unsigned int *entry) {
linux_zimage_header_t *zimage_header = (linux_zimage_header_t *) addr;

printk(LOG_LEVEL_INFO, "Linux zImage->code = 0x");
for (int i = 0; i < 9; i++)
printk(LOG_LEVEL_MUTE, "%x", code[i]);

printk(LOG_LEVEL_MUTE, "\n");
printk(LOG_LEVEL_DEBUG, "Linux zImage->magic = 0x%x\n",
zimage_header->magic);
printk(LOG_LEVEL_DEBUG, "Linux zImage->start = 0x%x\n",
(unsigned int) addr + zimage_header->start);
printk(LOG_LEVEL_DEBUG, "Linux zImage->end = 0x%x\n",
(unsigned int) addr + zimage_header->end);

if (zimage_header->magic == LINUX_ZIMAGE_MAGIC) {
*entry = ((unsigned int) addr + zimage_header->start);
return 0;
}

printk(LOG_LEVEL_ERROR, "unsupported kernel image\n");

return -1;
}

#define CHUNK_SIZE 0x20000

static int fatfs_loadimage(char *filename, BYTE *dest) {
Expand Down Expand Up @@ -228,8 +191,7 @@ int load_spi_nand(sunxi_spi_t *spi, image_info_t *image) {
(uint32_t) sizeof(linux_zimage_header_t));
hdr = (linux_zimage_header_t *) image->dest;
if (hdr->magic != LINUX_ZIMAGE_MAGIC) {
printk(LOG_LEVEL_DEBUG,
"SPI-NAND: zImage verification failed\n");
printk(LOG_LEVEL_DEBUG, "SPI-NAND: zImage verification failed\n");
return -1;
}
size = hdr->end - hdr->start;
Expand Down Expand Up @@ -340,10 +302,10 @@ int cmd_reload(int argc, const char **argv) {
msh_declare_command(boot);
msh_define_help(boot, "boot to linux", "Usage: boot\n");
int cmd_boot(int argc, const char **argv) {
unsigned int entry_point = 0;
uint32_t entry_point = 0;
void (*kernel_entry)(int zero, int arch, unsigned int params);

if (boot_image_setup((unsigned char *) image.dest, &entry_point)) {
if (zImage_loader((unsigned char *) image.dest, &entry_point)) {
printk(LOG_LEVEL_ERROR, "boot setup failed\n");
return 0;
}
Expand Down
Loading

0 comments on commit e7f551a

Please sign in to comment.