Files
luban-lite-t3e-pro/application/baremetal/bootloader/cmd/nand_boot.c

80 lines
1.6 KiB
C
Raw Normal View History

2023-08-30 16:21:18 +08:00
/*
* Copyright (c) 2023, Artinchip Technology Co., Ltd
*
* 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 <spinand_port.h>
#include <mtd.h>
#include <image.h>
#include <boot.h>
#include <hexdump.h>
2023-11-09 20:19:51 +08:00
#include "fitimage.h"
2023-08-30 16:21:18 +08:00
#define APPLICATION_PART "os"
#define PAGE_MAX_SIZE 4096
2023-11-09 20:19:51 +08:00
#ifdef AIC_AB_SYSTEM_INTERFACE
#include <absystem.h>
char target[32] = { 0 };
#endif
2023-08-30 16:21:18 +08:00
static int do_nand_boot(int argc, char *argv[])
{
int ret = 0;
struct mtd_dev *mtd;
2023-11-09 20:19:51 +08:00
ulong entry_point;
struct spl_load_info info;
2023-08-30 16:21:18 +08:00
mtd_probe();
2023-11-09 20:19:51 +08:00
#ifdef AIC_AB_SYSTEM_INTERFACE
ret = aic_ota_check();
if (ret) {
printf("Aic ota check error.\n");
2023-08-30 16:21:18 +08:00
}
2023-11-09 20:19:51 +08:00
ret = aic_get_os_to_startup(target);
2023-08-30 16:21:18 +08:00
if (ret) {
2023-11-09 20:19:51 +08:00
printf("Aic get os fail, startup from %s default.\n", APPLICATION_PART);
mtd = mtd_get_device(APPLICATION_PART);
} else {
mtd = mtd_get_device(target);
printf("Start-up from %s\n", target);
2023-08-30 16:21:18 +08:00
}
2023-11-09 20:19:51 +08:00
#else
mtd = mtd_get_device(APPLICATION_PART);
2023-08-30 16:21:18 +08:00
#endif
2023-11-09 20:19:51 +08:00
if (!mtd) {
printf("Failed to get application partition.\n");
2023-08-30 16:21:18 +08:00
return -1;
}
2023-11-09 20:19:51 +08:00
info.dev = (void *)mtd;
info.bl_len = mtd->writesize;
2023-12-22 10:19:53 +08:00
info.dev_type = DEVICE_SPINAND;
2023-11-09 20:19:51 +08:00
2023-12-22 10:19:53 +08:00
ret = spl_load_simple_fit(&info, &entry_point);
if (ret < 0)
goto out;
2023-11-09 20:19:51 +08:00
boot_app((void *)entry_point);
2023-12-22 10:19:53 +08:00
out:
2023-08-30 16:21:18 +08:00
return ret;
}
CONSOLE_CMD(nand_boot, do_nand_boot, "Boot from NAND.");