Skip to content

Commit

Permalink
[lib][fdtwalk] fix some unfound bugs in the riscv isa string detection
Browse files Browse the repository at this point in the history
  • Loading branch information
travisg committed Jun 17, 2024
1 parent e63c132 commit e3a5f9c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions lib/fdtwalk/fdtwalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ status_t fdt_walk_find_cpus(const void *fdt, struct fdt_walk_cpu_info *cpu, size
const size_t max_cpu_count = *cpu_count;
*cpu_count = 0;

auto walker = [&](const fdt_walk_state &state, const char *name) {
auto walker = [max_cpu_count, cpu, cpu_count](const fdt_walk_state &state, const char *name) {
/* look for a cpu leaf and count the number of cpus */
if (*cpu_count < max_cpu_count && strncmp(name, "cpu@", 4) == 0 && state.depth == 2) {
int lenp;
Expand All @@ -222,23 +222,29 @@ status_t fdt_walk_find_cpus(const void *fdt, struct fdt_walk_cpu_info *cpu, size
// is it disabled?
if (check_prop_is_val_string(state.fdt, state.offset, "status", "disabled")) {
LTRACEF("cpu id %#x is disabled, skipping...\n", id);
} else {
LTRACEF("calling cpu callback with id %#x\n", id);
cpu[*cpu_count].id = id;
(*cpu_count)++;
return;
}

// clear the cpu state, we're about to write down some information about it
cpu[*cpu_count] = {};

#if ARCH_RISCV
// look for riscv,isa and riscv,isa-extensions
auto isa_string = get_prop_string(state.fdt, state.offset, "riscv,isa");
if (isa_string) {
cpu->isa_string = isa_string;
cpu[*cpu_count].isa_string = isa_string;
}

auto isa_extensions_string = get_prop_string(state.fdt, state.offset, "riscv,isa-extensions");
if (isa_extensions_string) {
cpu->isa_extensions_string = isa_extensions_string;
cpu[*cpu_count].isa_extensions_string = isa_extensions_string;
}
#endif

// cpu is found
LTRACEF("found cpu id %u\n", id);
cpu[*cpu_count].id = id;
(*cpu_count)++;
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion lib/fdtwalk/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ status_t fdtwalk_setup_cpus_riscv(const void *fdt) {
// save the first isa string we found
isa_string = cpus[i].isa_string;
} else {
if (!strcmp(cpus[i].isa_string, isa_string)) {
if (strcmp(cpus[i].isa_string, isa_string) != 0) {
printf("FDT Warning: isa_strings do not match between cpus, using first found\n");
}
}
Expand Down

0 comments on commit e3a5f9c

Please sign in to comment.