Skip to content

Commit

Permalink
Merge pull request #114 from YuzukiHD/dev
Browse files Browse the repository at this point in the history
[board] support empty tf card boot from emmc
  • Loading branch information
SamulKyull authored Jun 19, 2024
2 parents ec5eb8e + 2914c04 commit 193900f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
4 changes: 4 additions & 0 deletions board/avaota-a1/eabi_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ int raise(int signum) {

/* Dummy function to avoid linker complaints */
void __aeabi_unwind_cpp_pr0(void) {
}

void panic() {
asm volatile("svc #0");
}
28 changes: 21 additions & 7 deletions board/avaota-a1/extlinux_boot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ static int fatfs_loadimage_size(char *filename, BYTE *dest, uint32_t *file_size)
fret = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ);
if (fret != FR_OK) {
printk_warning("FATFS: open, filename: [%s]: error %d\n", filename, fret);
LCD_ShowString(0, 104, "WARN: Open file fail, filename:", SPI_LCD_COLOR_YELLOW, SPI_LCD_COLOR_BLACK, 12);
LCD_ShowString(10, 116, filename, SPI_LCD_COLOR_YELLOW, SPI_LCD_COLOR_BLACK, 12);
ret = -1;
goto open_fail;
}
Expand Down Expand Up @@ -780,9 +778,24 @@ int main(void) {

/* Load the DTB, kernel image, and configuration data from the SD card. */
if (load_sdcard(&image) != 0) {
printk_warning("SMHC: loading failed\n");
LCD_ShowString(0, 92, "SMHC: loading failed", SPI_LCD_COLOR_GREEN, SPI_LCD_COLOR_BLACK, 12);
goto _fail;
printk_warning("SMHC: loading failed, try to boot from SDC2\n");

if (sunxi_sdhci_init(&sdhci2) != 0) {
printk_error("SMHC: %s controller init failed\n", sdhci2.name);
LCD_ShowString(0, 92, "SMHC: SDC2 controller init failed", SPI_LCD_COLOR_GREEN, SPI_LCD_COLOR_BLACK, 12);
goto _fail;
} else {
if (sdmmc_init(&card0, &sdhci2) != 0) {
printk_warning("SMHC: SDC2 init failed.\n");
goto _fail;
} else {
printk_info("SMHC: %s controller initialized\n", sdhci2.name);
if (load_sdcard(&image) != 0) {
printk_error("SMHC: loading boot info failed, check your boot media.\n");
goto _fail;
}
}
}
}

LCD_Open_BLK();
Expand Down Expand Up @@ -823,13 +836,14 @@ int main(void) {
jmp_to_fel();

_fail:
printk_error("SyterKit Boot Failed\n");
LCD_ShowString(0, 0, "SyterKit Boot Failed", SPI_LCD_COLOR_RED, SPI_LCD_COLOR_BLACK, 12);
LCD_ShowString(0, 12, "Please Connect UART for Debug info", SPI_LCD_COLOR_RED, SPI_LCD_COLOR_BLACK, 12);
LCD_ShowString(0, 24, "Error Info:", SPI_LCD_COLOR_RED, SPI_LCD_COLOR_BLACK, 12);
LCD_Open_BLK();

abort();
printk_error("SyterKit Boot Failed, System into software_interrupt panic. Please reset your board.\n");

panic();

return 0;
}
1 change: 1 addition & 0 deletions include/drivers/mmc/sys-sdcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef struct {
* External declaration of the 'card0' SDMMC platform data structure.
*/
extern sdmmc_pdata_t card0;
extern sdmmc_pdata_t card2;

/**
* @brief Initialize the SD/MMC interface
Expand Down
5 changes: 4 additions & 1 deletion lib/fatfs/diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static DSTATUS Stat = STA_NOINIT; /* Disk status */
static uint8_t *const cache_data = (uint8_t *) CONFIG_FATFS_CACHE_ADDR; /* in CONFIG_FATFS_CACHE_ADDR */
static uint8_t cache_bitmap[FATFS_CACHE_CHUNKS / 8]; /* in SRAM */
static BYTE cache_pdrv = -1;
static int current_cache_sdhci_id = -1;

#define CACHE_SECTOR_TO_OFFSET(ss) (((ss) / FATFS_CACHE_SECTORS_PER_BIT) / 8)
#define CACHE_SECTOR_TO_BIT(ss) (((ss) / FATFS_CACHE_SECTORS_PER_BIT) % 8)
Expand Down Expand Up @@ -82,13 +83,15 @@ DRESULT disk_read(BYTE pdrv, /* Physical drive nmuber to identify the drive *
printk_trace("FATFS: read %u sectors at %llu\r\n", count, sector);

#ifdef CONFIG_FATFS_CACHE_SIZE
if (pdrv != cache_pdrv) {
if (pdrv != cache_pdrv || current_cache_sdhci_id != card0.hci->id) {
printk_debug("FATFS: cache: %u bytes in %u chunks\r\n", CONFIG_FATFS_CACHE_SIZE, FATFS_CACHE_CHUNKS);
if (cache_pdrv != -1)
memset(cache_bitmap, 0, sizeof(cache_bitmap));
cache_pdrv = pdrv;
}

current_cache_sdhci_id = card0.hci->id;

while (count) {
if (sector >= FATFS_CACHE_SECTORS) {
printk_trace("FATFS: beyond cache %llu count %u\r\n", sector, count);
Expand Down
17 changes: 15 additions & 2 deletions src/drivers/mmc/sys-sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int sdmmc_init(sdmmc_pdata_t *data, sunxi_sdhci_t *hci) {
data->hci = hci;
data->online = false;

printk_debug("SMHC: try to init sdmmc device at %s\n", data->hci->name);
if (sunxi_mmc_init(data->hci) == 0) {
printk_info("SHMC: %s card detected\n", data->hci->sdhci_mmc_type == MMC_TYPE_SD ? "SD" : "MMC");
return 0;
Expand All @@ -61,8 +62,20 @@ uint32_t sdmmc_blk_read(sdmmc_pdata_t *data, uint8_t *buf, uint32_t blkno, uint3
return sunxi_mmc_blk_read(data->hci, buf, blkno, blkcnt);
}



/**
* @brief Writes blocks of data to the SD/MMC device using the specified SDHCI instance.
*
* This function writes a specified number of blocks to the SD/MMC (Secure Digital/MultiMediaCard) device
* associated with the given SDHCI (SD Host Controller Interface) instance. It serves as a wrapper around
* the sunxi_mmc_blk_write function, providing a simplified interface for block data write operations.
*
* @param[in] data A pointer to the SD/MMC platform data structure.
* @param[in] buf A pointer to the source buffer from which data will be written to the SD/MMC device.
* @param[in] blkno The starting block number where the data writing begins.
* @param[in] blkcnt The number of blocks to write.
*
* @return The number of blocks successfully written, or 0 if writing failed.
*/
uint32_t sdmmc_blk_write(sdmmc_pdata_t *data, uint8_t *buf, uint32_t blkno, uint32_t blkcnt) {
return sunxi_mmc_blk_write(data->hci, buf, blkno, blkcnt);
}

0 comments on commit 193900f

Please sign in to comment.