Files
luban-lite/application/baremetal/bootloader/cmd/ram_boot.c

77 lines
1.6 KiB
C
Raw Normal View History

2023-08-30 16:21:18 +08:00
/*
2024-09-30 17:06:01 +08:00
* Copyright (c) 2023-2024, Artinchip Technology Co., Ltd
2023-08-30 16:21:18 +08:00
*
* SPDX-License-Identifier: Apache-2.0
*
* Wu Dehuang <dehuang.wu@artinchip.com>
*/
#include <rtconfig.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <console.h>
#include <aic_common.h>
#include <aic_errno.h>
#include <image.h>
#include <boot.h>
#include "aic_time.h"
2024-09-30 17:06:01 +08:00
#ifdef CONFIG_LPKG_USING_FDTLIB
#include "fitimage.h"
#include "of.h"
#endif
2023-08-30 16:21:18 +08:00
#define APPLICATION_PART "os"
static int do_ram_boot(int argc, char *argv[])
{
int ret = 0;
uint8_t *data;
struct image_header head;
void *la;
unsigned long addr;
2024-09-30 17:06:01 +08:00
#ifdef CONFIG_LPKG_USING_FDTLIB
ulong entry_point;
struct spl_load_info info;
#endif
2023-08-30 16:21:18 +08:00
2024-04-03 16:40:57 +08:00
addr = strtoul(argv[1], NULL, 0);
2023-08-30 16:21:18 +08:00
data = (uint8_t *)addr;
memcpy(&head, data, sizeof(head));
ret = image_verify_magic((void *)&head, AIC_IMAGE_MAGIC);
if (ret) {
2024-09-30 17:06:01 +08:00
#ifdef CONFIG_LPKG_USING_FDTLIB
/* fitimage format */
info.dev = NULL;
info.dev_type = DEVICE_RAM;
info.bl_len = 1;
info.priv = (void *)addr;
entry_point = 0;
ret = spl_load_simple_fit(&info, &entry_point);
if (ret < 0)
return ret;
boot_app((void *)entry_point);
#else
2023-08-30 16:21:18 +08:00
printf("Application header is unknown.\n");
return -1;
2024-09-30 17:06:01 +08:00
#endif
} else {
/* AIC image format */
la = (void *)(unsigned long)head.load_address;
2023-08-30 16:21:18 +08:00
2024-09-30 17:06:01 +08:00
memcpy(la, data, head.image_len);
2023-08-30 16:21:18 +08:00
2024-09-30 17:06:01 +08:00
if (ret < 0)
return -1;
2023-08-30 16:21:18 +08:00
2024-09-30 17:06:01 +08:00
boot_app(la);
}
2023-08-30 16:21:18 +08:00
return ret;
}
CONSOLE_CMD(ram_boot, do_ram_boot, "Boot from RAM.");