Files
luban-lite-t3e-pro/bsp/artinchip/sys/d21x/boot_param.c

75 lines
1.6 KiB
C
Raw Normal View History

2023-08-30 16:21:18 +08:00
/*
* Copyright (C) 2023 ArtInChip Technology Co.,Ltd
* Author: Dehuang Wu <dehuang.wu@artinchip.com>
*/
#include <stdio.h>
#include <aic_common.h>
#include <boot_param.h>
/*
* Save boot parameters and context when save_boot_params is called.
*/
union boot_params boot_params_stash __attribute__((section(".data")));
enum boot_reason aic_get_boot_reason(void)
{
enum boot_reason reason;
/* SPL use a0 */
reason = get_boot_reason(boot_params_stash.r.a[0]);
return reason;
}
static const char *const boot_device_name[] = {
"BD_NONE", "BD_SDMC0", "BD_SDMC1", "BD_SDMC2",
"BD_SPINOR", "BD_SPINAND", "BD_SDFAT32", "BD_USB",
};
static void show_boot_device(u32 dev)
{
static u32 show_flag = 1;
const char *p;
if (show_flag) {
/* Print once only */
if (dev < 8)
p = boot_device_name[dev];
else
p = "BD_NONE";
printf("Boot device = %u(%s)\n", dev, p);
show_flag = 0;
}
}
enum boot_device aic_get_boot_device(void)
{
enum boot_device dev;
/* SPL use a0 */
dev = get_boot_device(boot_params_stash.r.a[0]);
show_boot_device(dev);
return dev;
}
enum boot_controller aic_get_boot_controller(void)
{
return get_boot_controller(boot_params_stash.r.a[0]);
}
int aic_get_boot_image_id(void)
{
return get_boot_image_id(boot_params_stash.r.a[0]);
}
unsigned long aic_timer_get_us(void)
{
register unsigned long tick;
__asm volatile("csrr %0, 0xc01"
: "=r"(tick)::"memory"); /* 0xc01 is csr time. */
return (tick >> 2);
}