[RTEMS Project] #4728: RISC-V console device tree parsing fails with a list of properties

RTEMS trac trac at rtems.org
Thu Sep 29 01:31:01 UTC 2022


#4728: RISC-V console device tree parsing fails with a list of properties
---------------------------+-------------------------------
  Reporter:  Alan Cudmore  |      Owner:  (none)
      Type:  defect        |     Status:  new
  Priority:  normal        |  Milestone:
 Component:  bsps          |    Version:  6
  Severity:  normal        |   Keywords:  riscv,fdt,console
Blocked By:                |   Blocking:
---------------------------+-------------------------------
 The riscv console configuration code uses a macro:
 #define RISCV_CONSOLE_IS_COMPATIBLE(actual, actual_len, desired) \
   (actual_len == sizeof(desired) \
      && memcmp(actual, desired, sizeof(desired) - 1) == 0)

 And is used to find a compatible console device in the device tree like
 this:
     if (RISCV_CONSOLE_IS_COMPATIBLE(compat, compat_len, "ucb,htif0")) {
       htif_console_context_init(&htif_console_instance.base, node);

 An example device tree entry:
 compatible = "ns16550a";
 works with the macro, but when the device tree entry has multiple items
 like:
 compatible = "canaan,k210-uarths", "sifive,uart0";
 the macro cannot parse the entry because the list is being treated like a
 single string. The compat_len variable ends up having the length of the
 entire list, causing the comparison to fail.

 If the macro is replaced with a call to fdt_stringlist_contains like:
     if (fdt_stringlist_contains(compat, compat_len, "ucb,htif0")) {
       htif_console_context_init(&htif_console_instance.base, node);

 The substring can be found in the compatible list.

 This works with my use case where there are multiple items in the
 compatible list.

 Unless there is a reason why the macro is used, I can submit a patch that
 replaces the macros with fdt_stringlist_contains calls.

 Note: I am not sure how to test all cases of this code, I can test the
 generic riscv-v/qemu based BSP, and the BSP I am working on, but I do not
 have access to a FE310/Arty system

--
Ticket URL: <http://devel.rtems.org/ticket/4728>
RTEMS Project <http://www.rtems.org/>
RTEMS Project


More information about the bugs mailing list