diff --git a/board/avaota-a1/eabi_compat.c b/board/avaota-a1/eabi_compat.c index 93303d89..fe4ce09a 100644 --- a/board/avaota-a1/eabi_compat.c +++ b/board/avaota-a1/eabi_compat.c @@ -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"); } \ No newline at end of file diff --git a/board/avaota-a1/extlinux_boot/main.c b/board/avaota-a1/extlinux_boot/main.c index a3b19981..23ac89c4 100644 --- a/board/avaota-a1/extlinux_boot/main.c +++ b/board/avaota-a1/extlinux_boot/main.c @@ -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; } @@ -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(); @@ -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; } \ No newline at end of file diff --git a/include/drivers/mmc/sys-sdcard.h b/include/drivers/mmc/sys-sdcard.h index 6ae394d3..ea5f8ce9 100644 --- a/include/drivers/mmc/sys-sdcard.h +++ b/include/drivers/mmc/sys-sdcard.h @@ -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 diff --git a/lib/fatfs/diskio.c b/lib/fatfs/diskio.c index 77949609..69c7001f 100644 --- a/lib/fatfs/diskio.c +++ b/lib/fatfs/diskio.c @@ -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) @@ -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); diff --git a/src/drivers/mmc/sys-sdcard.c b/src/drivers/mmc/sys-sdcard.c index a4df36f9..bcf3a7d4 100644 --- a/src/drivers/mmc/sys-sdcard.c +++ b/src/drivers/mmc/sys-sdcard.c @@ -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; @@ -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); }