Skip to content

Commit

Permalink
Merge pull request #77 from YuzukiHD/dev
Browse files Browse the repository at this point in the history
[board] avaota a1 extlinux support mac gen
  • Loading branch information
YuzukiTsuru authored Apr 22, 2024
2 parents d1f10cc + 9f2d955 commit 61500ce
Show file tree
Hide file tree
Showing 12 changed files with 581 additions and 9 deletions.
2 changes: 2 additions & 0 deletions board/avaota-a1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ add_subdirectory(init_dram)

add_subdirectory(syter_boot)

add_subdirectory(syter_boot_uboot)

add_subdirectory(smhc_test)

add_subdirectory(smhc2_test)
Expand Down
71 changes: 63 additions & 8 deletions board/avaota-a1/extlinux_boot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static int fatfs_loadimage_size(char *filename, BYTE *dest, uint32_t *file_size)
fret = f_close(&file);

printk_info("FATFS: read in %ums at %.2fMB/S\n", time,
(f32) (total_read / time) / 1024.0f);
(f32) (total_read / time) / 1024.0f);

open_fail:
return ret;
Expand All @@ -200,8 +200,8 @@ static int load_sdcard(image_info_t *image) {
sdmmc_blk_read(&card0, (uint8_t *) (SDRAM_BASE), 0, CONFIG_SDMMC_SPEED_TEST_SIZE);
test_time = time_ms() - start;
printk_debug("SDMMC: speedtest %uKB in %ums at %uKB/S\n",
(CONFIG_SDMMC_SPEED_TEST_SIZE * 512) / 1024, test_time,
(CONFIG_SDMMC_SPEED_TEST_SIZE * 512) / test_time);
(CONFIG_SDMMC_SPEED_TEST_SIZE * 512) / 1024, test_time,
(CONFIG_SDMMC_SPEED_TEST_SIZE * 512) / test_time);

start = time_ms();

Expand Down Expand Up @@ -375,6 +375,43 @@ static int update_pmu_ext_info_dtb(image_info_t *image) {
return 0;
}

static char to_hex_char(uint8_t value) {
return (value < 10) ? ('0' + value) : ('A' + value - 10);
}

static void chip_sid_to_mac(uint32_t chip_sid[4], uint8_t mac_address[6]) {
mac_address[3] = chip_sid[0] & 0xFF;
mac_address[2] = (chip_sid[1] >> 8) & 0xFF;
mac_address[1] = chip_sid[1] & 0xFF;
mac_address[0] = (chip_sid[2] >> 8) & 0xFF;
mac_address[4] = chip_sid[2] & 0xFF;
mac_address[5] = 0xFF;
}

static char *get_mac_address_from_sid(uint32_t chip_sid[4], char mac_address_str[18]) {
uint8_t mac_address[6];
chip_sid_to_mac(chip_sid, mac_address);
mac_address_str[0] = to_hex_char(mac_address[0] >> 4);
mac_address_str[1] = to_hex_char(mac_address[0] & 0x0F);
mac_address_str[2] = ':';
mac_address_str[3] = to_hex_char(mac_address[1] >> 4);
mac_address_str[4] = to_hex_char(mac_address[1] & 0x0F);
mac_address_str[5] = ':';
mac_address_str[6] = to_hex_char(mac_address[2] >> 4);
mac_address_str[7] = to_hex_char(mac_address[2] & 0x0F);
mac_address_str[8] = ':';
mac_address_str[9] = to_hex_char(mac_address[3] >> 4);
mac_address_str[10] = to_hex_char(mac_address[3] & 0x0F);
mac_address_str[11] = ':';
mac_address_str[12] = to_hex_char(mac_address[4] >> 4);
mac_address_str[13] = to_hex_char(mac_address[4] & 0x0F);
mac_address_str[14] = ':';
mac_address_str[15] = to_hex_char(mac_address[5] >> 4);
mac_address_str[16] = to_hex_char(mac_address[5] & 0x0F);
mac_address_str[17] = '\0';
return mac_address_str;
}

static int load_extlinux(image_info_t *image, uint64_t dram_size) {
FATFS fs;
FRESULT fret;
Expand Down Expand Up @@ -524,25 +561,43 @@ static int load_extlinux(image_info_t *image, uint64_t dram_size) {
}
len = 0;
/* Get bootargs string */
char *bootargs = (char *) smalloc(4096);
memset(bootargs, 0, 4096);
char *bootargs_str = (void *) fdt_getprop(image->of_dest, chosen_node, "bootargs", &len);
if (bootargs_str == NULL) {
printk_warning("FDT: bootargs is null, using extlinux.conf append.\n");
bootargs_str = (char *) smalloc(strlen(data.append) + 1);
bootargs_str[0] = '\0';
} else {
strcat(bootargs_str, " ");
strcat(bootargs, " ");
strcat(bootargs, bootargs_str);
}

strcat(bootargs_str, data.append);
/* Append bootargs */
strcat(bootargs, data.append);

int dram_node = fdt_find_or_add_subnode(image->of_dest, 0, "dram");
/* Kernel only need 0: DRAM_CLK, 24: DRAM_DIV */
fdt_setprop_u32(image->of_dest, dram_node, dram_para_name[0], dram_para[0]);
fdt_setprop_u32(image->of_dest, dram_node, dram_para_name[24], dram_para[24]);

/* Append bootargs mac address */
uint32_t chip_sid[4];
chip_sid[0] = read32(SUNXI_SID_SRAM_BASE + 0x0);
chip_sid[1] = read32(SUNXI_SID_SRAM_BASE + 0x4);
chip_sid[2] = read32(SUNXI_SID_SRAM_BASE + 0x8);
chip_sid[3] = read32(SUNXI_SID_SRAM_BASE + 0xc);

char mac_address_str[18];
char *mac0_address = get_mac_address_from_sid(chip_sid, mac_address_str);
strcat(bootargs, " mac0_addr=");
strcat(bootargs, mac0_address);
chip_sid[2]++;
char *mac1_address = get_mac_address_from_sid(chip_sid, mac_address_str);
strcat(bootargs, " mac1_addr=");
strcat(bootargs, mac1_address);

_add_dts_size:
/* Modify bootargs string */
ret = fdt_setprop_string(image->of_dest, chosen_node, "bootargs", skip_spaces(bootargs_str));
ret = fdt_setprop_string(image->of_dest, chosen_node, "bootargs", skip_spaces(bootargs));
if (ret == -FDT_ERR_NOSPACE) {
printk_debug("FDT: FDT_ERR_NOSPACE, Size = %d, Increase Size = %d\n", size, 512);
ret = fdt_increase_size(image->of_dest, 512);
Expand Down
5 changes: 5 additions & 0 deletions board/avaota-a1/syter_boot_uboot/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

add_syterkit_app(syter_boot_uboot
main.c
)
Binary file added board/avaota-a1/syter_boot_uboot/bl31/bl31.bin
Binary file not shown.
Loading

0 comments on commit 61500ce

Please sign in to comment.