From 896e1905fd61f5e0ce589cac09b5a27d83e4894b Mon Sep 17 00:00:00 2001 From: YuzukiTsuru Date: Fri, 22 Mar 2024 10:52:56 +0800 Subject: [PATCH 1/5] [driver] add GD5F2GQ4xFxxG --- src/drivers/sys-spi-nand.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/drivers/sys-spi-nand.c b/src/drivers/sys-spi-nand.c index a66bea41..e99fe4ef 100644 --- a/src/drivers/sys-spi-nand.c +++ b/src/drivers/sys-spi-nand.c @@ -65,6 +65,7 @@ static const spi_nand_info_t spi_nand_infos[] = { {"GD5F1GQ4UAWxx", {.mfr = SPI_NAND_MFR_GIGADEVICE, .dev = 0x10, 1}, 2048, 64, 64, 1024, 1, 1, SPI_IO_QUAD_RX}, {"GD5F1GQ5UExxG", {.mfr = SPI_NAND_MFR_GIGADEVICE, .dev = 0x51, 1}, 2048, 128, 64, 1024, 1, 1, SPI_IO_QUAD_RX}, {"GD5F1GQ4UExIG", {.mfr = SPI_NAND_MFR_GIGADEVICE, .dev = 0xd1, 1}, 2048, 128, 64, 1024, 1, 1, SPI_IO_QUAD_RX}, + {"GD5F2GQ4xFxxG", {.mfr = SPI_NAND_MFR_GIGADEVICE, .dev = 0xd2, 1}, 2048, 256, 64, 2048, 1, 1, SPI_IO_QUAD_RX}, {"GD5F1GQ4UExxH", {.mfr = SPI_NAND_MFR_GIGADEVICE, .dev = 0xd9, 1}, 2048, 64, 64, 1024, 1, 1, SPI_IO_QUAD_RX}, {"GD5F1GQ4xAYIG", {.mfr = SPI_NAND_MFR_GIGADEVICE, .dev = 0xf1, 1}, 2048, 64, 64, 1024, 1, 1, SPI_IO_QUAD_RX}, {"GD5F2GQ4UExIG", {.mfr = SPI_NAND_MFR_GIGADEVICE, .dev = 0xd2, 1}, 2048, 128, 64, 2048, 1, 1, SPI_IO_QUAD_RX}, From 4c415cf61537a7c2e488ce89c3f88bb90cd2435e Mon Sep 17 00:00:00 2001 From: YuzukiTsuru Date: Fri, 22 Mar 2024 10:53:16 +0800 Subject: [PATCH 2/5] [driver] add FORESEE --- src/drivers/sys-spi-nand.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/drivers/sys-spi-nand.c b/src/drivers/sys-spi-nand.c index e99fe4ef..b5663b75 100644 --- a/src/drivers/sys-spi-nand.c +++ b/src/drivers/sys-spi-nand.c @@ -98,6 +98,7 @@ static const spi_nand_info_t spi_nand_infos[] = { {"MT29F4G01ADAGD", {.mfr = SPI_NAND_MFR_MICRON, .dev = 0x36, 1}, 2048, 128, 64, 2048, 2, 2, SPI_IO_DUAL_RX}, {"MT29F8G01ADAFD", {.mfr = SPI_NAND_MFR_MICRON, .dev = 0x46, 1}, 4096, 256, 64, 2048, 1, 2, SPI_IO_DUAL_RX}, + /* FORESEE */ {"FS35SQA001G", {.mfr = SPI_NAND_MFR_FORESEE, .dev = 0x7171, 2}, 2048, 64, 64, 1024, 1, 1, SPI_IO_QUAD_RX}, }; From 6b890d2b34bfe6b2ac3160274aa86b1217f23a0b Mon Sep 17 00:00:00 2001 From: YuzukiTsuru Date: Tue, 26 Mar 2024 01:34:03 +0800 Subject: [PATCH 3/5] [board] add board yuzukihomekit --- board/yuzukihomekit/board.c | 16 +- board/yuzukihomekit/syter_boot/main.c | 378 +++++--------------------- cmake/board/yuzukihomekit.cmake | 1 + include/drivers/reg/reg-ncat.h | 1 - include/drivers/sys-spi-nor.h | 97 +++++++ src/drivers/sys-spi-nor.c | 26 ++ 6 files changed, 199 insertions(+), 320 deletions(-) create mode 100644 include/drivers/sys-spi-nor.h create mode 100644 src/drivers/sys-spi-nor.c diff --git a/board/yuzukihomekit/board.c b/board/yuzukihomekit/board.c index ac59fc7f..f493ccb1 100644 --- a/board/yuzukihomekit/board.c +++ b/board/yuzukihomekit/board.c @@ -7,16 +7,18 @@ #include -#include #include +#include #include +#include #include +#include +#include +#include #include #include -#include -#include sunxi_serial_t uart_dbg = { .base = SUNXI_UART3_BASE, @@ -56,6 +58,14 @@ sdhci_t sdhci0 = { .gpio_d3 = {GPIO_PIN(GPIO_PORTF, 4), GPIO_PERIPH_MUX2}, }; +sunxi_i2c_t i2c_pmu = { + .base = SUNXI_TWI0_BASE, + .id = SUNXI_I2C0, + .speed = 4000000, + .gpio_scl = {GPIO_PIN(GPIO_PORTL, 0), GPIO_PERIPH_MUX3}, + .gpio_sda = {GPIO_PIN(GPIO_PORTL, 1), GPIO_PERIPH_MUX3}, +}; + dram_para_t dram_para = { .dram_clk = 792, .dram_type = 3, diff --git a/board/yuzukihomekit/syter_boot/main.c b/board/yuzukihomekit/syter_boot/main.c index 56159921..004d0ee5 100644 --- a/board/yuzukihomekit/syter_boot/main.c +++ b/board/yuzukihomekit/syter_boot/main.c @@ -22,11 +22,13 @@ #include -#include "sys-dram.h" -#include "sys-rtc.h" -#include "sys-sdcard.h" -#include "sys-sid.h" -#include "sys-spi.h" +#include +#include +#include +#include +#include +#include +#include #include "fdt_wrapper.h" #include "ff.h" @@ -35,7 +37,6 @@ #define CONFIG_KERNEL_FILENAME "zImage" #define CONFIG_DTB_FILENAME "sunxi.dtb" -#define CONFIG_CONFIG_FILENAME "config.txt" #define CONFIG_SDMMC_SPEED_TEST_SIZE 1024// (unit: 512B sectors) @@ -47,20 +48,12 @@ #define CONFIG_DEFAULT_BOOTDELAY 5 -#define FILENAME_MAX_LEN 64 +#define FILENAME_MAX_LEN 16 typedef struct { uint8_t *dest; - uint8_t *of_dest; - - uint8_t *config_dest; - uint8_t is_config; - char filename[FILENAME_MAX_LEN]; - char of_filename[FILENAME_MAX_LEN]; - - char config_filename[FILENAME_MAX_LEN]; } image_info_t; #define MAX_SECTION_LEN 16 @@ -82,6 +75,8 @@ extern sunxi_spi_t sunxi_spi0; extern sdhci_t sdhci0; +extern sunxi_i2c_t i2c_pmu; + extern dram_para_t dram_para; image_info_t image; @@ -168,16 +163,6 @@ static int load_sdcard(image_info_t *image) { if (ret) return ret; - /* load config */ - printk(LOG_LEVEL_INFO, "FATFS: read %s addr=%x\n", image->config_filename, (uint32_t) image->config_dest); - ret = fatfs_loadimage(image->config_filename, image->config_dest); - if (ret) { - printk(LOG_LEVEL_INFO, "CONFIG: Cannot find config file, Using default config.\n"); - image->is_config = 0; - } else { - image->is_config = 1; - } - /* umount fs */ fret = f_mount(0, "", 0); if (fret != FR_OK) { @@ -191,172 +176,70 @@ static int load_sdcard(image_info_t *image) { return 0; } -static void trim(char *str) { - int len = strlen(str); - while (len > 0 && (str[len - 1] == ' ' || str[len - 1] == '\n' || str[len - 1] == '\r')) { - str[--len] = '\0'; - } - while (*str && (*str == ' ' || *str == '\n' || *str == '\r')) { - ++str; - --len; - } -} - -static int parse_ini_data(const char *data, size_t size, IniEntry *entries, int max_entries) { - char line[MAX_VALUE_LEN]; - char current_section[MAX_SECTION_LEN] = ""; - int entry_count = 0; - - const char *p = data; - const char *end = data + size; - - while (p < end) { - /* Read a line of data */ - size_t len = 0; - while (p + len < end && *(p + len) != '\n') { - ++len; - } - if (p + len < end && *(p + len) == '\n') { - ++len; - } - if (len > 0) { - strncpy(line, p, len); - line[len] = '\0'; - p += len; - - trim(line); - - /* Ignore empty lines and comments */ - if (line[0] == '\0' || line[0] == ';' || line[0] == '#') { - continue; - } - - /* Parse the section name */ - if (line[0] == '[' && line[strlen(line) - 1] == ']') { - strncpy(current_section, &line[1], strlen(line) - 2); - current_section[strlen(line) - 2] = '\0'; - continue; - } - - /* Parse key-value pairs */ - char *pos = strchr(line, '='); - if (pos != NULL) { - char *key_start = line; - char *value_start = pos + 1; - *pos = '\0'; - trim(key_start); - trim(value_start); - - if (strlen(current_section) > 0 && strlen(key_start) > 0 && strlen(value_start) > 0) { - if (entry_count >= max_entries) { - printk(LOG_LEVEL_ERROR, "INI: Too many entries!\n"); - break; - } - strncpy(entries[entry_count].section, current_section, MAX_SECTION_LEN - 1); - strncpy(entries[entry_count].key, key_start, MAX_KEY_LEN - 1); - strncpy(entries[entry_count].value, value_start, MAX_VALUE_LEN - 1); - ++entry_count; - } - } - } - } - - return entry_count; -} - -static const char *find_entry_value(const IniEntry *entries, int entry_count, const char *section, const char *key) { - for (int i = 0; i < entry_count; ++i) { - if (strcmp(entries[i].section, section) == 0 && strcmp(entries[i].key, key) == 0) { - return entries[i].value; - } - } - return NULL; +static int fdt_pack_reg(const void *fdt, void *buf, uint64_t address, uint64_t size) { + int i; + int address_cells = fdt_address_cells(fdt, 0); + int size_cells = fdt_size_cells(fdt, 0); + char *p = buf; + + if (address_cells == 2) + *(fdt64_t *) p = cpu_to_fdt64(address); + else + *(fdt32_t *) p = cpu_to_fdt32(address); + p += 4 * address_cells; + + if (size_cells == 2) + *(fdt64_t *) p = cpu_to_fdt64(size); + else + *(fdt32_t *) p = cpu_to_fdt32(size); + p += 4 * size_cells; + + return p - (char *) buf; } -static int update_bootargs_from_config(uint64_t dram_size) { +static int update_dtb_for_linux(uint64_t dram_size) { int ret = 0; - char *bootargs_str_config = NULL; - char *mac_addr = NULL; - - /* Check if using config file, get bootargs in the config file */ - if (image.is_config) { - size_t size_a = strlen(image.config_dest); - int entry_count = parse_ini_data(image.config_dest, size_a, entries, CONFIG_MAX_ENTRY); - for (int i = 0; i < entry_count; ++i) { - /* Print parsed INI entries */ - printk(LOG_LEVEL_DEBUG, "INI: [%s] %s = %s\n", entries[i].section, entries[i].key, entries[i].value); - } - bootargs_str_config = find_entry_value(entries, entry_count, "configs", "bootargs"); - mac_addr = find_entry_value(entries, entry_count, "configs", "mac_addr"); - } - /* Force image.dest to be a pointer to fdt_header structure */ + /* Force image.of_dest to be a pointer to fdt_header structure */ struct fdt_header *dtb_header = (struct fdt_header *) image.of_dest; /* Check if DTB header is valid */ if ((ret = fdt_check_header(dtb_header)) != 0) { printk(LOG_LEVEL_ERROR, "Invalid device tree blob: %s\n", fdt_strerror(ret)); - return -1; + goto _error; } /* Get the total size of DTB */ uint32_t size = fdt_totalsize(image.of_dest); - printk(LOG_LEVEL_DEBUG, "%s: FDT Size = %d\n", image.of_filename, size); - int len = 0; - /* Get the offset of "/chosen" node */ - uint32_t bootargs_node = fdt_path_offset(image.of_dest, "/chosen"); + printk(LOG_LEVEL_DEBUG, "FDT dtb size = %d\n", size); - /* Get bootargs string */ - char *bootargs_str = (void *) fdt_getprop(image.of_dest, bootargs_node, "bootargs", &len); - - /* If config file read fail or not using */ - if (bootargs_str_config == NULL) { - printk(LOG_LEVEL_WARNING, "INI: Cannot parse bootargs, using default bootargs in DTB.\n"); - bootargs_str_config = bootargs_str; + if ((ret = fdt_increase_size(image.of_dest, 512)) != 0) { + printk(LOG_LEVEL_ERROR, "FDT: device tree increase error: %s\n", fdt_strerror(ret)); + goto _error; } - /* update mac address of board */ - if (mac_addr != NULL) { - strcat(bootargs_str_config, " mac_addr="); - strcat(bootargs_str_config, mac_addr); - } + int memory_node = fdt_find_or_add_subnode(image.of_dest, 0, "memory"); - /* Add dram size to dtb */ - char dram_size_str[8]; - strcat(bootargs_str_config, " mem="); - strcat(bootargs_str_config, ltoa(dram_size, dram_size_str, 10)); - strcat(bootargs_str_config, "M"); - - /* Set bootargs based on the configuration file */ - printk(LOG_LEVEL_DEBUG, "INI: Set bootargs to %s\n", bootargs_str_config); - -_add_dts_size: - /* Modify bootargs string */ - ret = fdt_setprop(image.of_dest, bootargs_node, "bootargs", bootargs_str_config, strlen(bootargs_str_config) + 1); - if (ret == -FDT_ERR_NOSPACE) { - printk(LOG_LEVEL_DEBUG, "FDT: FDT_ERR_NOSPACE, Size = %d, Increase Size = %d\n", size, 512); - ret = fdt_increase_size(image.of_dest, 512); - if (!ret) - goto _add_dts_size; - else - goto _err_size; - } else if (ret < 0) { - printk(LOG_LEVEL_ERROR, "Can't change bootargs node: %s\n", fdt_strerror(ret)); - return -1; + if ((ret = fdt_setprop_string(image.of_dest, memory_node, "device_type", "memory")) != 0) { + printk(LOG_LEVEL_ERROR, "Can't change memory size node: %s\n", fdt_strerror(ret)); + goto _error; } - /* Get the total size of DTB */ - printk(LOG_LEVEL_DEBUG, "Modify FDT Size = %d\n", fdt_totalsize(image.of_dest)); + uint8_t *tmp_buf = (uint8_t *) smalloc(16 * sizeof(uint8_t)); - if (ret < 0) { - printk(LOG_LEVEL_ERROR, "libfdt fdt_setprop() error: %s\n", fdt_strerror(ret)); - return -1; + /* fix up memory region */ + int len = fdt_pack_reg(image.of_dest, tmp_buf, SDRAM_BASE, (dram_size * 1024 * 1024)); + + if ((ret = fdt_setprop(image.of_dest, memory_node, "reg", tmp_buf, len)) != 0) { + printk(LOG_LEVEL_ERROR, "Can't change memory base node: %s\n", fdt_strerror(ret)); + sfree(tmp_buf); + goto _error; } return 0; -_err_size: - printk(LOG_LEVEL_ERROR, "DTB: Can't increase blob size: %s\n", fdt_strerror(ret)); + +_error: return -1; } @@ -390,122 +273,6 @@ static int abortboot_single_key(int bootdelay) { return abort; } -msh_declare_command(bootargs); -msh_define_help(bootargs, "get/set bootargs for kernel", - "Usage: bootargs set \"bootargs\" - set new bootargs for zImage\n" - " bootargs get - get current bootargs\n"); -int cmd_bootargs(int argc, const char **argv) { - int err = 0; - - if (argc < 2) { - uart_puts(cmd_bootargs_usage); - return 0; - } - - if (strncmp(argv[1], "set", 3) == 0) { - if (argc != 3) { - uart_puts(cmd_bootargs_usage); - return 0; - } - /* Force image.of_dest to be a pointer to fdt_header structure */ - struct fdt_header *dtb_header = (struct fdt_header *) image.of_dest; - - /* Check if DTB header is valid */ - if ((err = fdt_check_header(dtb_header)) != 0) { - printk(LOG_LEVEL_ERROR, "Invalid device tree blob: %s\n", fdt_strerror(err)); - return 0; - } - - int len = 0; - /* Get the offset of "/chosen" node */ - uint32_t bootargs_node = fdt_path_offset(image.of_dest, "/chosen"); - - /* Get bootargs string */ - char *bootargs_str = (void *) fdt_getprop(image.of_dest, bootargs_node, "bootargs", &len); - printk(LOG_LEVEL_MUTE, "DTB OLD bootargs = \"%s\"\n", bootargs_str); - - /* New bootargs string */ - char *new_bootargs_str = argv[2]; - printk(LOG_LEVEL_MUTE, "Now set bootargs to \"%s\"\n", new_bootargs_str); - - _add_dts_size: - /* Modify bootargs string */ - err = fdt_setprop(image.of_dest, bootargs_node, "bootargs", new_bootargs_str, strlen(new_bootargs_str) + 1); - if (err == -FDT_ERR_NOSPACE) { - printk(LOG_LEVEL_DEBUG, "FDT: FDT_ERR_NOSPACE, Increase Size = %d\n", 512); - err = fdt_increase_size(image.of_dest, 512); - if (!err) - goto _add_dts_size; - else - goto _err_size; - } else if (err < 0) { - printk(LOG_LEVEL_ERROR, "Can't change bootargs node: %s\n", fdt_strerror(err)); - abort(); - } - - /* Get updated bootargs string */ - char *updated_bootargs_str = (void *) fdt_getprop(image.of_dest, bootargs_node, "bootargs", &len); - printk(LOG_LEVEL_MUTE, "DTB NEW bootargs = \"%s\"\n", updated_bootargs_str); - } else if (strncmp(argv[1], "get", 3) == 0) { - /* Force image.of_dest to be a pointer to fdt_header structure */ - struct fdt_header *dtb_header = (struct fdt_header *) image.of_dest; - - int err = 0; - - /* Check if DTB header is valid */ - if ((err = fdt_check_header(dtb_header)) != 0) { - printk(LOG_LEVEL_ERROR, "Invalid device tree blob: %s\n", fdt_strerror(err)); - return 0; - } - - int len = 0; - /* Get the offset of "/chosen" node */ - uint32_t bootargs_node = fdt_path_offset(image.of_dest, "/chosen"); - - /* Get bootargs string */ - char *bootargs_str = (void *) fdt_getprop(image.of_dest, bootargs_node, "bootargs", &len); - printk(LOG_LEVEL_MUTE, "DTB bootargs = \"%s\"\n", bootargs_str); - } else { - uart_puts(cmd_bootargs_usage); - } - return 0; - -_err_size: - printk(LOG_LEVEL_ERROR, "DTB: Can't increase blob size: %s\n", fdt_strerror(err)); - abort(); -} - -msh_declare_command(reload); -msh_define_help(reload, "rescan TF Card and reload DTB, Kernel zImage", "Usage: reload\n"); -int cmd_reload(int argc, const char **argv) { - if (sdmmc_init(&card0, &sdhci0) != 0) { - printk(LOG_LEVEL_ERROR, "SMHC: init failed\n"); - return 0; - } - - if (load_sdcard(&image) != 0) { - printk(LOG_LEVEL_ERROR, "SMHC: loading failed\n"); - return 0; - } - return 0; -} - -msh_declare_command(print); -msh_define_help(print, "print out env config", "Usage: print\n"); -int cmd_print(int argc, const char **argv) { - if (image.is_config) { - size_t size_a = strlen(image.config_dest); - int entry_count = parse_ini_data(image.config_dest, size_a, entries, CONFIG_MAX_ENTRY); - for (int i = 0; i < entry_count; ++i) { - /* Print parsed INI entries */ - printk(LOG_LEVEL_MUTE, "ENV: [%s] %s = %s\n", entries[i].section, entries[i].key, entries[i].value); - } - } else { - printk(LOG_LEVEL_WARNING, "ENV: Can not find env file\n"); - } - return 0; -} - msh_declare_command(boot); msh_define_help(boot, "boot to linux", "Usage: boot\n"); int cmd_boot(int argc, const char **argv) { @@ -538,10 +305,7 @@ int cmd_boot(int argc, const char **argv) { } const msh_command_entry commands[] = { - msh_define_command(bootargs), - msh_define_command(reload), msh_define_command(boot), - msh_define_command(print), msh_command_end, }; @@ -559,26 +323,24 @@ int main(void) { /* Initialize the system clock. */ sunxi_clk_init(); - /* Check rtc fel flag. if set flag, goto fel */ - if (rtc_probe_fel_flag()) { - printk(LOG_LEVEL_INFO, "RTC: get fel flag, jump to fel mode.\n"); - clean_syterkit_data(); - rtc_clear_fel_flag(); - sunxi_clk_reset(); - mdelay(100); - goto _fel; - } + /* Init IIC for PMU */ + sunxi_i2c_init(&i2c_pmu); + + pmu_axp1530_init(&i2c_pmu); + /* Init DRAM 1.5v */ + pmu_axp1530_set_vol(&i2c_pmu, "dcdc2", 1500, 1); + /* Init PERF 3.3v */ + pmu_axp1530_set_vol(&i2c_pmu, "dcdc3", 3300, 1); + /* Dump the voltage */ + pmu_axp1530_dump(&i2c_pmu); /* Initialize the DRAM and enable memory management unit (MMU). */ uint64_t dram_size = sunxi_dram_init(&dram_para); arm32_mmu_enable(SDRAM_BASE, dram_size); - /* Debug message to indicate that MMU is enabled. */ - printk(LOG_LEVEL_DEBUG, "enable mmu ok\n"); - /* Initialize the small memory allocator. */ smalloc_init(CONFIG_HEAP_BASE, CONFIG_HEAP_SIZE); - + /* Dump information about the system clocks. */ sunxi_clk_dump(); @@ -588,13 +350,10 @@ int main(void) { /* Set the destination address for the device tree binary (DTB), kernel image, and configuration data. */ image.of_dest = (uint8_t *) CONFIG_DTB_LOAD_ADDR; image.dest = (uint8_t *) CONFIG_KERNEL_LOAD_ADDR; - image.config_dest = (uint8_t *) CONFIG_CONFIG_LOAD_ADDR; - image.is_config = 0; /* Copy the filenames for the DTB, kernel image, and configuration data. */ strcpy(image.filename, CONFIG_KERNEL_FILENAME); strcpy(image.of_filename, CONFIG_DTB_FILENAME); - strcpy(image.config_filename, CONFIG_CONFIG_FILENAME); /* Initialize the SD host controller. */ if (sunxi_sdhci_init(&sdhci0) != 0) { @@ -617,25 +376,12 @@ int main(void) { } /* Update boot arguments based on configuration file. */ - if (update_bootargs_from_config(dram_size)) { + if (update_dtb_for_linux(dram_size)) { goto _shell; } int bootdelay = CONFIG_DEFAULT_BOOTDELAY; - if (image.is_config) { - size_t size_a = strlen(image.config_dest); - int entry_count = parse_ini_data(image.config_dest, size_a, entries, CONFIG_MAX_ENTRY); - for (int i = 0; i < entry_count; ++i) { - /* Print parsed INI entries */ - printk(LOG_LEVEL_DEBUG, "INI: [%s] %s = %s\n", entries[i].section, entries[i].key, entries[i].value); - } - char *bootdelay_str = find_entry_value(entries, entry_count, "configs", "bootdelay"); - if (bootdelay_str != NULL) { - bootdelay = simple_atoi(bootdelay_str); - } - } - /* Showing boot delays */ if (abortboot_single_key(bootdelay)) { goto _shell; diff --git a/cmake/board/yuzukihomekit.cmake b/cmake/board/yuzukihomekit.cmake index b57ef9b0..1d37609d 100644 --- a/cmake/board/yuzukihomekit.cmake +++ b/cmake/board/yuzukihomekit.cmake @@ -2,6 +2,7 @@ set(CONFIG_ARCH_ARM32 True) set(CONFIG_CHIP_SUN8IW20 True) +set(CONFIG_CHIP_WITHPMU True) set(CONFIG_BOARD_YUZUKIHOMEKIT True) add_definitions(-DCONFIG_CHIP_SUN8IW20) diff --git a/include/drivers/reg/reg-ncat.h b/include/drivers/reg/reg-ncat.h index 3930b259..82dea891 100644 --- a/include/drivers/reg/reg-ncat.h +++ b/include/drivers/reg/reg-ncat.h @@ -17,7 +17,6 @@ extern "C" { #include #elif defined(CONFIG_CHIP_SUN55IW3) #include - #elif defined(CONFIG_CHIP_SUN50IW10) #include #else diff --git a/include/drivers/sys-spi-nor.h b/include/drivers/sys-spi-nor.h new file mode 100644 index 00000000..704aa643 --- /dev/null +++ b/include/drivers/sys-spi-nor.h @@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#ifndef __SYS_SPI_NOR_H__ +#define __SYS_SPI_NOR_H__ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif// __cplusplus + +const int SFDP_MAX_NPH(6); + +typedef struct sfdp_header { + uint8_t sign[4]; + uint8_t minor; + uint8_t major; + uint8_t nph; + uint8_t unused; +} sfdp_header_t; + +typedef struct sfdp_parameter_header { + uint8_t idlsb; + uint8_t minor; + uint8_t major; + uint8_t length; + uint8_t ptp[3]; + uint8_t idmsb; +} sfdp_parameter_header_t; + +typedef struct sfdp_basic_table { + uint8_t minor; + uint8_t major; + uint8_t table[16 * 4]; +} sfdp_basic_table_t; + +typedef struct sfdp { + sfdp_header_t header{}; + sfdp_parameter_header_t parameter_header[SFDP_MAX_NPH]{}; + sfdp_basic_table_t basic_table{}; +} sfdp_t; + +typedef struct spi_nor_info { + char *name; + uint32_t id; + uint32_t capacity; + uint32_t blksz; + uint32_t read_granularity; + uint32_t write_granularity; + uint8_t address_length; + uint8_t opcode_read; + uint8_t opcode_write; + uint8_t opcode_write_enable; + uint8_t opcode_erase_4k; + uint8_t opcode_erase_32k; + uint8_t opcode_erase_64k; + uint8_t opcode_erase_256k; +} spi_nor_info_t; + +typedef struct spi_nor_pdata { + spi_nor_info_t info; + uint32_t swap_buf{}; + uint32_t swap_len{}; + uint32_t cmd_len{}; +} spi_nor_pdata_t; + +enum SPI_NOR_OPS { + NOR_OPCODE_SFDP = 0x5a, + NOR_OPCODE_RDID = 0x9f, + NOR_OPCODE_WRSR = 0x01, + NOR_OPCODE_RDSR = 0x05, + NOR_OPCODE_WREN = 0x06, + NOR_OPCODE_READ = 0x03, + NOR_OPCODE_PROG = 0x02, + NOR_OPCODE_E4K = 0x20, + NOR_OPCODE_E32K = 0x52, + NOR_OPCODE_E64K = 0xd8, + NOR_OPCODE_ENTER_4B = 0xb7, + NOR_OPCODE_EXIT_4B = 0xe9, +}; + +#ifdef __cplusplus +} +#endif// __cplusplus + +#endif// __SYS_SPI_NOR_H__ \ No newline at end of file diff --git a/src/drivers/sys-spi-nor.c b/src/drivers/sys-spi-nor.c new file mode 100644 index 00000000..f1d86067 --- /dev/null +++ b/src/drivers/sys-spi-nor.c @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include + +#include +#include + +static const spi_nor_info_t spi_nor_info_table[] = { + {"W25X40", 0xef3013, 512 * 1024, 4096, 1, 256, 3, NOR_OPCODE_READ, NOR_OPCODE_PROG, NOR_OPCODE_WREN, NOR_OPCODE_E4K, 0, NOR_OPCODE_E64K, 0}, + {"W25Q128JVEIQ", 0xefc018, 16 * 1024 * 1024, 4096, 1, 256, 3, NOR_OPCODE_READ, NOR_OPCODE_PROG, NOR_OPCODE_WREN, NOR_OPCODE_E4K, NOR_OPCODE_E32K, NOR_OPCODE_E64K, 0}, + {"GD25D10B", 0xc84011, 128 * 1024, 4096, 1, 256, 3, NOR_OPCODE_READ, NOR_OPCODE_PROG, NOR_OPCODE_WREN, NOR_OPCODE_E4K, NOR_OPCODE_E32K, NOR_OPCODE_E64K, 0}, +}; + From c8fff79d5d15f901dd487b7bd3e60de9862e66a8 Mon Sep 17 00:00:00 2001 From: YuzukiTsuru Date: Fri, 29 Mar 2024 17:32:52 +0800 Subject: [PATCH 4/5] [board] fix init rd --- board/longanpi-4b/extlinux_boot/main.c | 75 ++++++++++++++------------ board/yuzukihomekit/syter_boot/main.c | 2 +- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/board/longanpi-4b/extlinux_boot/main.c b/board/longanpi-4b/extlinux_boot/main.c index f21257f3..352f06a7 100644 --- a/board/longanpi-4b/extlinux_boot/main.c +++ b/board/longanpi-4b/extlinux_boot/main.c @@ -446,41 +446,41 @@ static int load_extlinux(image_info_t *image, uint64_t dram_size) { uint64_t ramdisk_start = (uint64_t) (uintptr_t) image->ramdisk_dest; uint64_t ramdisk_end = ramdisk_start + ramdisk_size; - if (ramdisk_size > 0) { - uint64_t addr, size; - - printk(LOG_LEVEL_DEBUG, "initrd_start = 0x%08x, initrd_end = 0x%08x\n", ramdisk_start, ramdisk_end); - int total = fdt_num_mem_rsv(image->of_dest); - - printk(LOG_LEVEL_DEBUG, "Look for an existing entry %d\n", total); - - /* Look for an existing entry and update it. If we don't find the entry, we will add a available slot. */ - for (int j = 0; j < total; j++) { - ret = fdt_get_mem_rsv(image->of_dest, j, &addr, &size); - if (addr == ramdisk_start) { - fdt_del_mem_rsv(image->of_dest, j); - break; - } - } - - ret = fdt_add_mem_rsv(image->of_dest, ramdisk_start, ramdisk_end - ramdisk_start); - if (ret < 0) { - printk(LOG_LEVEL_DEBUG, "fdt_initrd: %s\n", fdt_strerror(ret)); - goto _error; - } - - ret = fdt_setprop_u64(image->of_dest, chosen_node, "linux,initrd-start", (uint64_t) ramdisk_start); - if (ret < 0) { - printk(LOG_LEVEL_DEBUG, "WARNING: could not set linux,initrd-start %s.\n", fdt_strerror(ret)); - goto _error; - } - - ret = fdt_setprop_u64(image->of_dest, chosen_node, "linux,initrd-end", (uint64_t) ramdisk_end); - if (ret < 0) { - printk(LOG_LEVEL_DEBUG, "WARNING: could not set linux,initrd-end %s.\n", fdt_strerror(ret)); - goto _error; - } - } + // if (ramdisk_size > 0) { + // uint64_t addr, size; + + // printk(LOG_LEVEL_DEBUG, "initrd_start = 0x%08x, initrd_end = 0x%08x\n", ramdisk_start, ramdisk_end); + // int total = fdt_num_mem_rsv(image->of_dest); + + // printk(LOG_LEVEL_DEBUG, "Look for an existing entry %d\n", total); + + // /* Look for an existing entry and update it. If we don't find the entry, we will add a available slot. */ + // for (int j = 0; j < total; j++) { + // ret = fdt_get_mem_rsv(image->of_dest, j, &addr, &size); + // if (addr == ramdisk_start) { + // fdt_del_mem_rsv(image->of_dest, j); + // break; + // } + // } + + // ret = fdt_add_mem_rsv(image->of_dest, ramdisk_start, ramdisk_end - ramdisk_start); + // if (ret < 0) { + // printk(LOG_LEVEL_DEBUG, "fdt_initrd: %s\n", fdt_strerror(ret)); + // goto _error; + // } + + // ret = fdt_setprop_u64(image->of_dest, chosen_node, "linux,initrd-start", (uint64_t) ramdisk_start); + // if (ret < 0) { + // printk(LOG_LEVEL_DEBUG, "WARNING: could not set linux,initrd-start %s.\n", fdt_strerror(ret)); + // goto _error; + // } + + // ret = fdt_setprop_u64(image->of_dest, chosen_node, "linux,initrd-end", (uint64_t) ramdisk_end); + // if (ret < 0) { + // printk(LOG_LEVEL_DEBUG, "WARNING: could not set linux,initrd-end %s.\n", fdt_strerror(ret)); + // goto _error; + // } + // } len = 0; /* Get bootargs string */ @@ -497,6 +497,11 @@ static int load_extlinux(image_info_t *image, uint64_t dram_size) { strcat(bootargs_str, data.append); + /* initrd small fix */ + if (ramdisk_size > 0) { + strcat(bootargs_str, " initrd=0x43000000,8M"); + } + printk(LOG_LEVEL_INFO, "Kernel cmdline = [%s]\n", bootargs_str); _add_dts_size: diff --git a/board/yuzukihomekit/syter_boot/main.c b/board/yuzukihomekit/syter_boot/main.c index 004d0ee5..a24ca3b6 100644 --- a/board/yuzukihomekit/syter_boot/main.c +++ b/board/yuzukihomekit/syter_boot/main.c @@ -253,7 +253,7 @@ static int abortboot_single_key(int bootdelay) { if (tstc()) { /* we got a key press */ uart_getchar(); /* consume input */ printk(LOG_LEVEL_MUTE, "\b\b\b%2d", bootdelay); - abort = 1; /* don't auto boot */ + abort = 0; /* auto boot */ } while ((bootdelay > 0) && (!abort)) { From 3c8107ac0e0f11f3985d58926b88ba7cf3e71a3a Mon Sep 17 00:00:00 2001 From: YuzukiTsuru Date: Fri, 29 Mar 2024 22:29:13 +0800 Subject: [PATCH 5/5] [board] fix init rd --- board/longanpi-4b/extlinux_boot/main.c | 79 ++++++++++++-------------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/board/longanpi-4b/extlinux_boot/main.c b/board/longanpi-4b/extlinux_boot/main.c index 352f06a7..72bfe5b6 100644 --- a/board/longanpi-4b/extlinux_boot/main.c +++ b/board/longanpi-4b/extlinux_boot/main.c @@ -444,43 +444,43 @@ static int load_extlinux(image_info_t *image, uint64_t dram_size) { /* Get the offset of "/chosen" node */ int chosen_node = fdt_find_or_add_subnode(image->of_dest, 0, "chosen"); - uint64_t ramdisk_start = (uint64_t) (uintptr_t) image->ramdisk_dest; - uint64_t ramdisk_end = ramdisk_start + ramdisk_size; - // if (ramdisk_size > 0) { - // uint64_t addr, size; - - // printk(LOG_LEVEL_DEBUG, "initrd_start = 0x%08x, initrd_end = 0x%08x\n", ramdisk_start, ramdisk_end); - // int total = fdt_num_mem_rsv(image->of_dest); - - // printk(LOG_LEVEL_DEBUG, "Look for an existing entry %d\n", total); - - // /* Look for an existing entry and update it. If we don't find the entry, we will add a available slot. */ - // for (int j = 0; j < total; j++) { - // ret = fdt_get_mem_rsv(image->of_dest, j, &addr, &size); - // if (addr == ramdisk_start) { - // fdt_del_mem_rsv(image->of_dest, j); - // break; - // } - // } - - // ret = fdt_add_mem_rsv(image->of_dest, ramdisk_start, ramdisk_end - ramdisk_start); - // if (ret < 0) { - // printk(LOG_LEVEL_DEBUG, "fdt_initrd: %s\n", fdt_strerror(ret)); - // goto _error; - // } - - // ret = fdt_setprop_u64(image->of_dest, chosen_node, "linux,initrd-start", (uint64_t) ramdisk_start); - // if (ret < 0) { - // printk(LOG_LEVEL_DEBUG, "WARNING: could not set linux,initrd-start %s.\n", fdt_strerror(ret)); - // goto _error; - // } - - // ret = fdt_setprop_u64(image->of_dest, chosen_node, "linux,initrd-end", (uint64_t) ramdisk_end); - // if (ret < 0) { - // printk(LOG_LEVEL_DEBUG, "WARNING: could not set linux,initrd-end %s.\n", fdt_strerror(ret)); - // goto _error; - // } - // } + uint32_t ramdisk_start = (uint32_t) (uintptr_t) image->ramdisk_dest; + uint32_t ramdisk_end = (uint32_t) ramdisk_start + (uint32_t) ramdisk_size; + if (ramdisk_size > 0) { + uint64_t addr, size; + + printk(LOG_LEVEL_DEBUG, "initrd_start = 0x%08x, initrd_end = 0x%08x\n", ramdisk_start, ramdisk_end); + int total = fdt_num_mem_rsv(image->of_dest); + + printk(LOG_LEVEL_DEBUG, "Look for an existing entry %d\n", total); + + /* Look for an existing entry and update it. If we don't find the entry, we will add a available slot. */ + for (int j = 0; j < total; j++) { + ret = fdt_get_mem_rsv(image->of_dest, j, &addr, &size); + if (addr == ramdisk_start) { + fdt_del_mem_rsv(image->of_dest, j); + break; + } + } + + ret = fdt_add_mem_rsv(image->of_dest, ramdisk_start, ramdisk_end - ramdisk_start); + if (ret < 0) { + printk(LOG_LEVEL_DEBUG, "fdt_initrd: %s\n", fdt_strerror(ret)); + goto _error; + } + + ret = fdt_setprop_u64(image->of_dest, chosen_node, "linux,initrd-start", (uint64_t) ramdisk_start); + if (ret < 0) { + printk(LOG_LEVEL_DEBUG, "WARNING: could not set linux,initrd-start %s.\n", fdt_strerror(ret)); + goto _error; + } + + ret = fdt_setprop_u64(image->of_dest, chosen_node, "linux,initrd-end", (uint64_t) ramdisk_end); + if (ret < 0) { + printk(LOG_LEVEL_DEBUG, "WARNING: could not set linux,initrd-end %s.\n", fdt_strerror(ret)); + goto _error; + } + } len = 0; /* Get bootargs string */ @@ -497,11 +497,6 @@ static int load_extlinux(image_info_t *image, uint64_t dram_size) { strcat(bootargs_str, data.append); - /* initrd small fix */ - if (ramdisk_size > 0) { - strcat(bootargs_str, " initrd=0x43000000,8M"); - } - printk(LOG_LEVEL_INFO, "Kernel cmdline = [%s]\n", bootargs_str); _add_dts_size: