This commit is contained in:
刘可亮
2024-01-27 08:47:24 +08:00
parent d3bd993b5f
commit 9f7ba67007
2345 changed files with 74421 additions and 76616 deletions

View File

@@ -27,6 +27,8 @@ if GetDepend('AIC_BOOTLOADER_CMD_PSRAM_TEST'):
src += Glob('psram_test.c')
if GetDepend('AIC_BOOTLOADER_CMD_XIP_BOOT'):
src += Glob('xip_boot.c')
if GetDepend('AIC_BOOTLOADER_CMD_PART'):
src += Glob('part.c')
CPPPATH = [cwd]
ASFLAGS = ''

View File

@@ -24,21 +24,27 @@
#include <mmc.h>
#include <hal_syscfg.h>
#include <upg_uart.h>
#include <hal_rtc.h>
#include <wdt.h>
#define AICUPG_HELP \
"ArtInChip upgrading command:\n" \
"aicupg [devtype] [interface]\n" \
" - devtype: should be usb, uart, mmc, fat, brom\n" \
" - interface: specify the controller id\n" \
"e.g.\n" \
" aicupg usb 0\n" \
" aicupg mmc 1\n" \
"when devtype is fat: \n" \
"aicupg [devtype] [blkdev] [interface]\n" \
"- blkdev: should be udisk,mmc \n" \
"e.g.: \n" \
" aicupg fat udisk 0\n" \
" aicupg fat mmc 1\n" \
"when devtype is brom, device will reset to Boot ROM upgrade mode\n" \
" aicupg brom\n" \
" aicupg\n"
#define AICUPG_HELP \
"ArtInChip upgrading command:\n" \
"aicupg [devtype] [interface]\n" \
" - devtype: should be usb, uart, mmc, fat\n" \
" - interface: specify the controller id\n" \
"e.g.\n" \
" aicupg usb 0\n" \
" aicupg mmc 1\n" \
"when devtype is fat: \n" \
"aicupg [devtype] [blkdev] [interface]\n" \
"- blkdev: should be udisk,mmc \n" \
"e.g.: \n" \
" aicupg fat udisk 0\n" \
" aicupg fat mmc 1\n"
static void aicupg_help(void)
{
puts(AICUPG_HELP);
@@ -140,6 +146,7 @@ static int do_fat_upg(int intf, char *const blktype)
file_buf = (char *)aicos_malloc_align(0, 1024, CACHE_LINE_SIZE);
if (!file_buf) {
pr_err("Error, malloc buf failed.\n");
ret = -1;
goto err;
}
memset((void *)file_buf, 0, 1024);
@@ -149,6 +156,7 @@ static int do_fat_upg(int intf, char *const blktype)
#if defined(AICUPG_UDISK_ENABLE)
if (usbh_initialize(intf) < 0) {
pr_err("usbh init failed!\n");
ret = -1;
goto err;
}
@@ -227,6 +235,19 @@ err:
return ret;
}
static void do_brom_upg(void)
{
aic_set_reboot_reason(REBOOT_REASON_UPGRADE);
#ifdef AIC_WDT_DRV
wdt_init();
printf("Going to reboot ...\n");
wdt_expire_now();
while(1)
continue;
#endif
}
static int do_aicupg(int argc, char *argv[])
{
char *devtype = NULL;
@@ -234,6 +255,11 @@ static int do_aicupg(int argc, char *argv[])
aic_get_reboot_reason();
if ((argc == 1) || ((argc == 2) && (!strcmp(argv[1], "brom")))) {
do_brom_upg();
return 0;
}
if ((argc < 3) || (argc > AICUPG_ARGS_MAX))
goto help;
devtype = argv[1]; /* mmc usb fat */

View File

@@ -13,6 +13,7 @@
#include <console.h>
#include <aic_common.h>
#include <aic_errno.h>
#include <boot_param.h>
#include <mmc.h>
#include <image.h>
#include <boot.h>
@@ -20,16 +21,23 @@
#include "fitimage.h"
#define APPLICATION_PART "os"
#define MMC_BOOT_CONTROL_ID 0
static int do_mmc_boot(int argc, char *argv[])
{
int ret = 0, mmc_id = MMC_BOOT_CONTROL_ID;
int ret = 0, mmc_id = 0;
enum boot_device bd;
struct aic_sdmc *host = NULL;
struct aic_partition *part = NULL, *parts = NULL;
struct spl_load_info info;
ulong entry_point;
bd = aic_get_boot_device();
if (BD_SDMC0 == bd) {
mmc_id = 0;
} else if (BD_SDMC1 == bd) {
mmc_id = 1;
}
ret = mmc_init(mmc_id);
if (ret) {
printf("sdmc %d init failed.\n", mmc_id);

View File

@@ -13,17 +13,18 @@
#include <console.h>
#include <aic_common.h>
#include <aic_errno.h>
#include <boot_param.h>
#include <mmc.h>
#include <image.h>
#include <boot.h>
#include <hexdump.h>
#define APPLICATION_PART "os"
#define MMC_BOOT_CONTROL_ID 0
static int do_mmc_boot(int argc, char *argv[])
{
int ret = 0, mmc_id = MMC_BOOT_CONTROL_ID;
int ret = 0, mmc_id = 0;
enum boot_device bd;
struct image_header *head = NULL;
struct aic_sdmc *host = NULL;
struct aic_partition *part = NULL, *parts = NULL;
@@ -31,6 +32,13 @@ static int do_mmc_boot(int argc, char *argv[])
u64 blkstart, blkcnt;
u32 start_us;
bd = aic_get_boot_device();
if (BD_SDMC0 == bd) {
mmc_id = 0;
} else if (BD_SDMC1 == bd) {
mmc_id = 1;
}
ret = mmc_init(mmc_id);
if (ret) {
printf("sdmc %d init failed.\n", mmc_id);

View File

@@ -0,0 +1,167 @@
/*
* Copyright (c) 2023, Artinchip Technology Co., Ltd
*
* SPDX-License-Identifier: Apache-2.0
*
* Wu Dehuang <dehuang.wu@artinchip.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <console.h>
#include <mmc.h>
#include <disk_part.h>
#include <hexdump.h>
static struct aic_sdmc *mmc_host = NULL;
#define PART_HELP \
"Partition command:\n" \
" part init <id> \n" \
" <id> is mmc id." \
" part list\n" \
" part dump\n" \
" part gptwrite [partition string]\n" \
" e.g.: \n" \
" part init 0\n" \
" part list\n" \
" part dump\n" \
" part gptwrite 256k@0x4400(spl),8m(os),12m(rodata),35m(data)\n"
static void cmd_part_help(void)
{
puts(PART_HELP);
}
static unsigned long mmc_write(struct blk_desc *block_dev, u64 start,
u64 blkcnt, void *buffer)
{
return mmc_bwrite(block_dev->priv, start, blkcnt, buffer);
}
static unsigned long mmc_read(struct blk_desc *block_dev, u64 start, u64 blkcnt,
const void *buffer)
{
return mmc_bread(block_dev->priv, start, blkcnt, (void *)buffer);
}
static int cmd_part_init(int id)
{
struct aic_sdmc *host = NULL;
struct disk_blk_ops ops;
int ret;
ret = mmc_init(id);
if (ret) {
printf("sdmc %d init failed.\n", id);
return ret;
}
host = find_mmc_dev_by_index(id);
if (!host) {
pr_err("find mmc dev failed.\n");
return -1;
}
mmc_host = host;
ops.blk_write = mmc_write;
ops.blk_read = mmc_read;
aic_disk_part_set_ops(&ops);
printf("mmc controller id %d\n", id);
printf("Capacity %d MB\n", mmc_host->dev->card_capacity >> 10);
return 0;
}
static int cmd_part_list(void)
{
struct blk_desc dev_desc;
struct aic_partition *parts, *p;
dev_desc.blksz = 512;
dev_desc.lba_count = mmc_host->dev->card_capacity * 2;
dev_desc.priv = mmc_host;
parts = aic_disk_get_parts(&dev_desc);
p = parts;
while (p) {
printf("Start: 0x%08llx; Size: 0x%08llx; %s\n", p->start, p->size, p->name);
p = p->next;
}
if (parts)
aic_part_free(parts);
return 0;
}
static int cmd_part_dump_gpt(void)
{
struct blk_desc dev_desc;
dev_desc.blksz = 512;
dev_desc.lba_count = mmc_host->dev->card_capacity * 2;
dev_desc.priv = mmc_host;
aic_disk_dump_parts(&dev_desc);
return 0;
}
static int cmd_gpt_write(char *partstr)
{
struct aic_partition *partition;
struct blk_desc dev_desc;
int ret;
partition = aic_part_gpt_parse(partstr);
if (partition == NULL)
return -1;
dev_desc.blksz = 512;
dev_desc.lba_count = mmc_host->dev->card_capacity * 2;
dev_desc.priv = mmc_host;
ret = aic_disk_write_gpt(&dev_desc, partition);
if (ret) {
printf("Write PART table failed.\n");
}
aic_part_free(partition);
return 0;
}
static int do_part(int argc, char *argv[])
{
char *cmd = NULL, *part;
unsigned long id;
cmd = argv[1];
if (argc == 2) {
if (!strcmp(cmd, "list")) {
cmd_part_list();
return 0;
}
if (!strcmp(cmd, "dump")) {
cmd_part_dump_gpt();
return 0;
}
}
if (argc >= 3) {
if (!strcmp(cmd, "init")) {
id = strtol(argv[2], NULL, 0);
cmd_part_init(id);
return 0;
} else if (!strcmp(cmd, "gptwrite")) {
part = argv[2];
printf("Part: %s\n", part);
cmd_gpt_write(part);
return 0;
}
}
cmd_part_help();
return 0;
}
CONSOLE_CMD(part, do_part, "Partition util");

View File

@@ -20,6 +20,7 @@
#include <boot.h>
#include <aic_core.h>
#include <aic_flash_xip_def.h>
#include "fitimage.h"
#if defined(AIC_BOOTLOADER_CMD_XIP_BOOT) && defined(AIC_QSPI_DRV_V11)
@@ -49,7 +50,7 @@ static int aic_xip_init(struct mtd_dev *mtd, u32 msk, u32 val)
id = ((flash->chip.mf_id << 16) | (flash->chip.type_id << 8) |
(flash->chip.capacity_id << 0));
printf("XIP flasd ID: 0x%x\n", id);
printf("XIP flash ID: 0x%x\n", id);
xip_cfg = get_xip_device_cfg(id, msk, val);
if (xip_cfg == NULL) {
@@ -82,34 +83,37 @@ static struct mtd_dev *nor_flash_init(void)
return mtd;
}
static void *get_start_entry(struct mtd_dev *mtd)
{
return (void *)((unsigned long)mtd->start + FLASH_XIP_BASE + AIC_HEAD_SIZE);
}
static int do_xip_boot(int argc, char *argv[])
{
int ret = 0;
struct mtd_dev *mtd;
void (*ep)(void);
ulong entry_point;
struct spl_load_info info;
mtd = nor_flash_init();
if (!mtd) {
printf("XIP boot failed ...\n");
}
//msk = CMD_PROTO_QIO; //val = CMD_PROTO_QIO;
aic_xip_init(mtd, CMD_PROTO_QIO, CMD_PROTO_QIO);
ep = get_start_entry(mtd);
// need to delay, otherwise bootup unstable.
aicos_udelay(1000 * 100);
printf("XIP boot, start entry: 0x%lx, used %llu us...\n", (unsigned long)ep, aic_get_time_us());
info.dev = (void *)mtd;
info.dev_type = DEVICE_XIPNOR;
info.bl_len = 1;
info.priv = (void *)((unsigned long)mtd->start + FLASH_XIP_BASE);
ret = spl_load_simple_fit(&info, &entry_point);
if (ret < 0)
goto out;
/* boot */
aicos_dcache_clean();
ep();
boot_app((void *)entry_point);
out:
return ret;
}