Skip to content

Commit

Permalink
Merge pull request #86 from YuzukiHD/dev
Browse files Browse the repository at this point in the history
[board ]add dtboverlay for avaota a1
  • Loading branch information
SamulKyull authored May 22, 2024
2 parents 2ca9483 + a761cf6 commit 056c182
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
30 changes: 30 additions & 0 deletions board/avaota-a1/extlinux_boot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define CONFIG_BL31_LOAD_ADDR (0x48000000)

#define CONFIG_DTB_LOAD_ADDR (0x40400000)
#define CONFIG_DTBO_LOAD_ADDR (0x50400000)
#define CONFIG_INITRD_LOAD_ADDR (0x43000000)
#define CONFIG_KERNEL_LOAD_ADDR (0x40800000)

Expand Down Expand Up @@ -92,6 +93,7 @@ typedef struct ext_linux_data {
char *kernel;
char *initrd;
char *fdt;
char *dtbo;
char *append;
} ext_linux_data_t;

Expand All @@ -109,6 +111,7 @@ typedef struct {
uint8_t *kernel_dest;
uint8_t *ramdisk_dest;
uint8_t *of_dest;
uint8_t *of_overlay_dest;

uint8_t *extlinux_dest;
char extlinux_filename[FILENAME_MAX_LEN];
Expand Down Expand Up @@ -315,6 +318,9 @@ static void parse_extlinux_data(char *config, ext_linux_data_t *data) {
start = find_substring(config, "fdt ");
data->fdt = copy_until_newline_or_end(start);

start = find_substring(config, "fdtoverlay ");
data->dtbo = copy_until_newline_or_end(start);

start = find_substring(config, "append ");
data->append = copy_until_newline_or_end(start);
}
Expand Down Expand Up @@ -427,6 +433,7 @@ static int load_extlinux(image_info_t *image, uint64_t dram_size) {
printk_debug("%s: kernel -> %s\n", data.os, data.kernel);
printk_debug("%s: initrd -> %s\n", data.os, data.initrd);
printk_debug("%s: fdt -> %s\n", data.os, data.fdt);
printk_debug("%s: dtbo -> %s\n", data.os, data.dtbo);
printk_debug("%s: append -> %s\n", data.os, data.append);

start = time_ms();
Expand Down Expand Up @@ -620,6 +627,28 @@ static int load_extlinux(image_info_t *image, uint64_t dram_size) {
goto _error;
}

/* Check and load dtbo */
if (data.dtbo != NULL) {
printk_info("FATFS: read %s addr=%x\n", data.dtbo, (uint32_t) image->of_overlay_dest);
ret = fatfs_loadimage(data.dtbo, image->of_overlay_dest);
if (ret) {
printk_warning("dtb overlay not find, overlay not applied.\n");
goto _error;
} else {
printk_info("dtbo load 0x%08x\n", image->of_overlay_dest);
}

if (!fdt_check_header(image->of_overlay_dest)) {
printk_warning("dtb overlay not valid, error = %s, overlay not applyed.\n", fdt_strerror(err));
goto _error;
} else {
ret = fdt_overlay_apply_verbose(image->of_dest, image->of_overlay_dest);
if (ret) {
printk_warning("dtb overlay not success applied, overlay not applied.\n");
}
}
}

err = 0;
_error:
return err;
Expand Down Expand Up @@ -723,6 +752,7 @@ int main(void) {
image.ramdisk_dest = (uint8_t *) CONFIG_INITRD_LOAD_ADDR;
image.kernel_dest = (uint8_t *) CONFIG_KERNEL_LOAD_ADDR;
image.splash_dest = (uint8_t *) CONFIG_SPLASH_LOAD_ADDR;
image.of_overlay_dest = (uint8_t *) CONFIG_DTBO_LOAD_ADDR;

strcpy(image.bl31_filename, CONFIG_BL31_FILENAME);
strcpy(image.scp_filename, CONFIG_SCP_FILENAME);
Expand Down
4 changes: 2 additions & 2 deletions board/avaota-a1/init_dram/memtester.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@ static int do_memtester(uint32_t start_addr, uint64_t dram_size) {
char *memsuffix;
int memshift;
ulv *bufa, *bufb;

wantbytes = -1;
wantbytes = 1024 * 1024;
wantmb = (wantbytes >> 20);
halflen = wantbytes / 2;
count = halflen / sizeof(ul);
Expand Down
23 changes: 17 additions & 6 deletions include/fdt_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#define __FDT_WRAPPER_H__

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
extern "C" {
#endif// __cplusplus

#ifndef __packed
#define __packed __attribute__((__packed__))
#define __packed __attribute__((__packed__))
#endif

#ifndef __aligned
#define __aligned(x) __attribute__((__aligned__(x)))
#define __aligned(x) __attribute__((__aligned__(x)))
#endif

#define MAX_LEVEL 32 /* how deeply nested we will go */
Expand Down Expand Up @@ -60,8 +60,19 @@ int fdt_increase_size(void *fdt, int add_len);
*/
int fdt_find_or_add_subnode(void *fdt, int parentoffset, const char *name);

/**
* fdt_overlay_apply_verbose - Apply an overlay with verbose error reporting
*
* @fdt: ptr to device tree
* @fdto: ptr to device tree overlay
*
* Convenience function to apply an overlay and display helpful messages
* in the case of an error
*/
int fdt_overlay_apply_verbose(void *fdt, void *fdto);

#ifdef __cplusplus
}
#endif // __cplusplus
#endif// __cplusplus

#endif //__FDT_WRAPPER_H__
#endif//__FDT_WRAPPER_H__
2 changes: 1 addition & 1 deletion lib/fdt/fdt_overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,
if (!name_len)
return -FDT_ERR_BADOVERLAY;

poffset = strtoul(sep + 1, &endptr, 10);
poffset = simple_strtoul(sep + 1, &endptr, 10);
if ((*endptr != '\0') || (endptr <= (sep + 1)))
return -FDT_ERR_BADOVERLAY;

Expand Down
18 changes: 18 additions & 0 deletions src/fdt_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,22 @@ int fdt_find_or_add_subnode(void *fdt, int parent_offset, const char *name) {
printk_warning("FDT: find or add subnode %s: %s\n", name, fdt_strerror(offset));

return offset;
}

int fdt_overlay_apply_verbose(void *fdt, void *fdto) {
int err;
bool has_symbols;

err = fdt_path_offset(fdt, "/__symbols__");
has_symbols = err >= 0;

err = fdt_overlay_apply(fdt, fdto);
if (err < 0) {
printk_warning("failed on fdt_overlay_apply(): %s\n", fdt_strerror(err));
if (!has_symbols) {
printk_warning("base fdt does not have a /__symbols__ node\n");
printk_warning("make sure you've compiled with -@\n");
}
}
return err;
}

0 comments on commit 056c182

Please sign in to comment.