mirror of
https://gitee.com/Vancouver2017/luban-lite-t3e-pro.git
synced 2025-12-14 10:28:54 +00:00
v1.0.2: fitimage for demo88 mmc
This commit is contained in:
@@ -19,8 +19,10 @@ if GetDepend('AIC_BOOTLOADER_CMD_NOR_BOOT') and not GetDepend('LPKG_USING_FDTLIB
|
||||
src += Glob('nor_boot_no_fitimage.c')
|
||||
if GetDepend('AIC_BOOTLOADER_CMD_NAND_BOOT'):
|
||||
src += Glob('nand_boot.c')
|
||||
if GetDepend('AIC_BOOTLOADER_CMD_MMC_BOOT'):
|
||||
if GetDepend('AIC_BOOTLOADER_CMD_MMC_BOOT') and GetDepend('LPKG_USING_FDTLIB'):
|
||||
src += Glob('mmc_boot.c')
|
||||
if GetDepend('AIC_BOOTLOADER_CMD_MMC_BOOT') and not GetDepend('LPKG_USING_FDTLIB'):
|
||||
src += Glob('mmc_boot_no_fitimage.c')
|
||||
if GetDepend('AIC_BOOTLOADER_CMD_PSRAM_TEST'):
|
||||
src += Glob('psram_test.c')
|
||||
if GetDepend('AIC_BOOTLOADER_CMD_XIP_BOOT'):
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <image.h>
|
||||
#include <boot.h>
|
||||
#include <hexdump.h>
|
||||
#include "fitimage.h"
|
||||
|
||||
#define APPLICATION_PART "os"
|
||||
#define MMC_BOOT_CONTROL_ID 0
|
||||
@@ -24,12 +25,10 @@
|
||||
static int do_mmc_boot(int argc, char *argv[])
|
||||
{
|
||||
int ret = 0, mmc_id = MMC_BOOT_CONTROL_ID;
|
||||
struct image_header *head = NULL;
|
||||
struct aic_sdmc *host = NULL;
|
||||
struct aic_partition *part = NULL, *parts = NULL;
|
||||
void *la;
|
||||
u64 blkstart, blkcnt;
|
||||
u32 start_us;
|
||||
struct spl_load_info info;
|
||||
ulong entry_point;
|
||||
|
||||
ret = mmc_init(mmc_id);
|
||||
if (ret) {
|
||||
@@ -62,39 +61,20 @@ static int do_mmc_boot(int argc, char *argv[])
|
||||
goto out;
|
||||
}
|
||||
|
||||
head = malloc(MMC_BLOCK_SIZE);
|
||||
blkstart = part->start / MMC_BLOCK_SIZE;
|
||||
ret = mmc_bread(host, blkstart, 1, (void *)head);
|
||||
if (ret < 0) {
|
||||
printf("Read image header failed.\n");
|
||||
info.dev = (void *)host;
|
||||
info.priv = (void *)part;
|
||||
info.dev_type = DEVICE_MMC;
|
||||
info.bl_len = MMC_BLOCK_SIZE;
|
||||
|
||||
ret = spl_load_simple_fit(&info, &entry_point);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = image_verify_magic((void *)head, AIC_IMAGE_MAGIC);
|
||||
if (ret) {
|
||||
printf("Application header is unknown.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
la = (void *)(unsigned long)head->load_address;
|
||||
|
||||
start_us = aic_get_time_us();
|
||||
blkcnt = ROUNDUP(head->image_len, MMC_BLOCK_SIZE) / MMC_BLOCK_SIZE;
|
||||
ret = mmc_bread(host, blkstart, blkcnt, la);
|
||||
show_speed("mmc read speed", head->image_len, aic_get_time_us() - start_us);
|
||||
|
||||
if (ret < 0) {
|
||||
printf("Read image failed.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
boot_app(la);
|
||||
boot_app((void *)entry_point);
|
||||
|
||||
out:
|
||||
if (parts)
|
||||
mmc_free_partition(parts);
|
||||
if (head)
|
||||
free(head);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
101
application/baremetal/bootloader/cmd/mmc_boot_no_fitimage.c
Normal file
101
application/baremetal/bootloader/cmd/mmc_boot_no_fitimage.c
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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 <aic_common.h>
|
||||
#include <aic_errno.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;
|
||||
struct image_header *head = NULL;
|
||||
struct aic_sdmc *host = NULL;
|
||||
struct aic_partition *part = NULL, *parts = NULL;
|
||||
void *la;
|
||||
u64 blkstart, blkcnt;
|
||||
u32 start_us;
|
||||
|
||||
ret = mmc_init(mmc_id);
|
||||
if (ret) {
|
||||
printf("sdmc %d init failed.\n", mmc_id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
host = find_mmc_dev_by_index(mmc_id);
|
||||
if (!host) {
|
||||
pr_err("find mmc dev failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
parts = mmc_create_gpt_part();
|
||||
if (!parts) {
|
||||
pr_err("sdmc %d create gpt part failed.\n", mmc_id);
|
||||
goto out;
|
||||
}
|
||||
|
||||
part = parts;
|
||||
while (part) {
|
||||
if (!strcmp(part->name, APPLICATION_PART))
|
||||
break;
|
||||
|
||||
part = part->next;
|
||||
}
|
||||
|
||||
if (!part) {
|
||||
printf("Failed to get application partition.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
head = malloc(MMC_BLOCK_SIZE);
|
||||
blkstart = part->start / MMC_BLOCK_SIZE;
|
||||
ret = mmc_bread(host, blkstart, 1, (void *)head);
|
||||
if (ret < 0) {
|
||||
printf("Read image header failed.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = image_verify_magic((void *)head, AIC_IMAGE_MAGIC);
|
||||
if (ret) {
|
||||
printf("Application header is unknown.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
la = (void *)(unsigned long)head->load_address;
|
||||
|
||||
start_us = aic_get_time_us();
|
||||
blkcnt = ROUNDUP(head->image_len, MMC_BLOCK_SIZE) / MMC_BLOCK_SIZE;
|
||||
ret = mmc_bread(host, blkstart, blkcnt, la);
|
||||
show_speed("mmc read speed", head->image_len, aic_get_time_us() - start_us);
|
||||
|
||||
if (ret < 0) {
|
||||
printf("Read image failed.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
boot_app(la);
|
||||
|
||||
out:
|
||||
if (parts)
|
||||
mmc_free_partition(parts);
|
||||
if (head)
|
||||
free(head);
|
||||
return ret;
|
||||
}
|
||||
|
||||
CONSOLE_CMD(mmc_boot, do_mmc_boot, "Boot from eMMC/SD.");
|
||||
@@ -17,6 +17,13 @@ struct spl_fit_info {
|
||||
int conf_node; /* FDT offset to selected configuration node */
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DEVICE_MMC,
|
||||
DEVICE_SPINAND,
|
||||
DEVICE_SPINOR,
|
||||
} boot_dev_type;
|
||||
|
||||
/**
|
||||
* Information required to load data from a device
|
||||
*
|
||||
@@ -27,6 +34,7 @@ struct spl_fit_info {
|
||||
struct spl_load_info {
|
||||
void *dev;
|
||||
void *priv;
|
||||
boot_dev_type dev_type;
|
||||
int bl_len;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <mtd.h>
|
||||
#include <mmc.h>
|
||||
#include <aic_core.h>
|
||||
#include <libfdt.h>
|
||||
#include <hexdump.h>
|
||||
@@ -105,10 +106,8 @@ int spl_fit_get_image_name(const struct spl_fit_info *ctx,
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
printf("no string for index %d\n", index);
|
||||
if (!found)
|
||||
return -1;
|
||||
}
|
||||
|
||||
*outname = str;
|
||||
return 0;
|
||||
@@ -238,15 +237,42 @@ int fit_image_get_entry(const void *fit, int noffset, ulong *entry)
|
||||
return fit_image_get_address(fit, noffset, FIT_ENTRY_PROP, entry);
|
||||
}
|
||||
|
||||
static int spl_read(struct spl_load_info *info, ulong offset, void *buf, int size)
|
||||
{
|
||||
int rdlen = 0;
|
||||
|
||||
if (info->dev_type == DEVICE_SPINAND || info->dev_type == DEVICE_SPINOR) {
|
||||
#if defined(AIC_MTD_BARE_DRV)
|
||||
struct mtd_dev *mtd = (struct mtd_dev *)info->dev;
|
||||
|
||||
rdlen = mtd_read(mtd, offset, buf, size);
|
||||
#endif
|
||||
} else if (info->dev_type == DEVICE_MMC) {
|
||||
#if defined(AIC_SDMC_DRV)
|
||||
int blkcnt, blkstart, blkoffset, byte_offset;
|
||||
struct aic_sdmc *host = (struct aic_sdmc *)info->dev;
|
||||
struct aic_partition *part = (struct aic_partition *)info->priv;
|
||||
|
||||
blkstart = part->start / info->bl_len;
|
||||
blkoffset = offset / info->bl_len;
|
||||
byte_offset = offset % info->bl_len;
|
||||
blkcnt = ALIGN_UP(size, info->bl_len) / info->bl_len;
|
||||
blkcnt = mmc_bread(host, blkstart + blkoffset, blkcnt, (u8 *)(buf - byte_offset));
|
||||
rdlen = info->bl_len * blkcnt;
|
||||
rdlen = min(rdlen, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
return rdlen;
|
||||
}
|
||||
|
||||
int spl_load_fit_image(struct spl_load_info *info, struct spl_fit_info *ctx, int node, ulong *entry_point)
|
||||
{
|
||||
ulong load_addr = 0;
|
||||
unsigned int length;
|
||||
int ret, offset = 0;
|
||||
int start_offset, overhead, read_length;
|
||||
const void *fit = ctx->fit;
|
||||
bool external_data = false;
|
||||
struct mtd_dev *mtd = (struct mtd_dev *)info->dev;
|
||||
u64 start_us;
|
||||
|
||||
if (fit_image_get_load(fit, node, &load_addr))
|
||||
@@ -270,17 +296,19 @@ int spl_load_fit_image(struct spl_load_info *info, struct spl_fit_info *ctx, int
|
||||
if (fit_image_get_data_size(fit, node, &length))
|
||||
return -1;
|
||||
|
||||
start_offset = ALIGN_DOWN(offset, info->bl_len);
|
||||
overhead = offset - start_offset;
|
||||
read_length = ALIGN_UP(offset + length, info->bl_len) - start_offset;
|
||||
|
||||
start_us = aic_get_time_us();
|
||||
ret = mtd_read(mtd, start_offset, (u8 *)(load_addr - overhead), read_length);
|
||||
show_speed("mtd read", read_length, aic_get_time_us() - start_us);
|
||||
ret = spl_read(info, offset, (u8 *)load_addr, length);
|
||||
show_speed("spl read", length, aic_get_time_us() - start_us);
|
||||
|
||||
#ifdef CRC32_MTD_READ
|
||||
unsigned int crc32_val = crc32(0, NULL, 0);
|
||||
crc32_val = crc32(crc32_val, (u8 *)load_addr, length);
|
||||
printf("mtd read crc32 = 0x%x KB/s\n", crc32_val);
|
||||
#endif
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("mtd read external_data error\n");
|
||||
printf("spl read external_data error\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -304,37 +332,51 @@ int spl_load_fit_image(struct spl_load_info *info, struct spl_fit_info *ctx, int
|
||||
|
||||
int spl_load_simple_fit(struct spl_load_info *info, ulong *entry_point)
|
||||
{
|
||||
struct fdt_header header;
|
||||
struct fdt_header *header;
|
||||
struct spl_fit_info ctx;
|
||||
void *buf = NULL;
|
||||
int size, ret = 0;
|
||||
int size, buf_size, ret = 0;
|
||||
int index = 0, node = -1;
|
||||
struct mtd_dev *mtd = (struct mtd_dev *)info->dev;
|
||||
|
||||
ret = mtd_read(mtd, 0, (void *)&header, sizeof(header));
|
||||
header = aicos_malloc(MEM_DEFAULT,
|
||||
ALIGN_UP(sizeof(struct fdt_header), info->bl_len));
|
||||
if (!header)
|
||||
{
|
||||
printf("No space to malloc for header\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* read itb tree header, to parse itb tree totalsize */
|
||||
ret = spl_read(info, 0, (void *)header, sizeof(struct fdt_header));
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("mtd read header error\n");
|
||||
return -1;
|
||||
printf("spl read header error\n");
|
||||
goto __exit_header;
|
||||
}
|
||||
|
||||
if (fdt_magic(&header) != FDT_MAGIC)
|
||||
if (fdt_magic(header) != FDT_MAGIC)
|
||||
{
|
||||
printf("Not found FIT\n");
|
||||
return -1;
|
||||
goto __exit_header;
|
||||
}
|
||||
|
||||
size = FIT_ALIGN(fdt_totalsize(&header), 4);
|
||||
size = FIT_ALIGN(fdt_totalsize(header), 4);
|
||||
ctx.ext_data_offset = size;
|
||||
|
||||
if (info->dev_type == DEVICE_MMC) {
|
||||
buf_size = ROUNDUP(size, info->bl_len);
|
||||
size = buf_size;
|
||||
}
|
||||
|
||||
buf = aicos_malloc(MEM_DEFAULT, size);
|
||||
if (!buf)
|
||||
{
|
||||
printf("No space to malloc for itb\n");
|
||||
return -1;
|
||||
goto __exit_header;
|
||||
}
|
||||
|
||||
ret = mtd_read(mtd, 0, buf, size);
|
||||
/* read itb tree */
|
||||
ret = spl_read(info, 0, buf, size);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("mtd read itb error\n");
|
||||
@@ -381,5 +423,7 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong *entry_point)
|
||||
|
||||
__exit:
|
||||
aicos_free(MEM_DEFAULT, buf);
|
||||
__exit_header:
|
||||
aicos_free(MEM_DEFAULT, header);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user