Skip to content

Commit

Permalink
parser,fdtQueryEngine: Fix parser bug with queries
Browse files Browse the repository at this point in the history
When using dtb queries on a type that has multiple instances, when the
second or additional instances are evaluated, their settings have bad
values: `gpio_mux_server1.gpio.dtb = dtb({})` instead of the expected:
`gpio_mux_server1.gpio.dtb = dtb({"path" : "/gpio@2200000"})`.  This is
due to a parser bug that mutates the internal dictionary object instead
of mutating a copy.

Switching to a deep copy avoids mutating the AST object.

```
component GPIOMUXServer {

  emits FDT dummy_source;
  consumes FDT gpio;
  consumes FDT mux;

  composition {

    connection seL4DTBHardware gpio_conn(from dummy_source, to gpio);
    connection seL4DTBHardware mux_conn(from dummy_source, to mux);

  }

  configuration {
    gpio.dtb = dtb({"path" : "/gpio@2200000"});
    mux.dtb = dtb({"path" : "/pinmux@2430000"});

  }
}

assembly {
  composition {
    component GPIOMUXServer gpio_mux_server0;
    component GPIOMUXServer gpio_mux_server1;
  }
  configuration {}

}

```

Signed-off-by: Kent McLeod <[email protected]>
  • Loading branch information
kent-mcleod committed Jun 1, 2023
1 parent 73c90a4 commit fd099f3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion camkes/parser/fdtQueryEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import functools
import os
import copy
import six
import re
import logging
Expand Down Expand Up @@ -405,7 +406,12 @@ def _match_attr_dict(self, attr_dict):

def query(self, attr):
assert isinstance(attr, list)
return [self._match_attr_dict(attr_dict) for attr_dict in attr]

# Make a copy of each internal dict as _match_attr_dict mutates
# its arguments but we aren't allowed to mutate our arguments.
# Use deepcopy because the dict could contain more compound objects
# but can't contain recursive references.
return [self._match_attr_dict(copy.deepcopy(attr_dict)) for attr_dict in attr]


class DtbMatchQuery(Query):
Expand Down

0 comments on commit fd099f3

Please sign in to comment.