diff options
author | Nathaniel Graff <nathaniel.graff@sifive.com> | 2019-05-07 16:39:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-07 16:39:19 +0000 |
commit | 770b3ded63b3099fe48b4c6ffa5ba22ee06e9f9b (patch) | |
tree | 896f31afcd55d27f270aa9e0b21f5824ac11dab5 | |
parent | 139149a670354a74cb2a5693c270bb24ea39dc05 (diff) | |
parent | 610c24a3c4059ba8a7eeba95046aba9f1e24359b (diff) |
Merge pull request #242 from sifive/improve-fixups
Improvements to DTS fixups
-rwxr-xr-x | scripts/fixup-dts | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/scripts/fixup-dts b/scripts/fixup-dts index ddbbd0c..92e96d0 100755 --- a/scripts/fixup-dts +++ b/scripts/fixup-dts @@ -4,6 +4,7 @@ set -e set -o pipefail unset dts +unset SED while [ "$1" != "" ] do @@ -20,15 +21,32 @@ then exit 1 fi +# When installed on MacOS with Homebrew, GNU sed is named gsed. +# If gsed exists, use it. +if [ `which gsed` == "" ]; then + SED=sed +else + SED=gsed +fi + # Add a PMP node if it doesn't exist -if [ `grep -c 'riscv,pmp' ${dts}` -eq 0 ] -then +if [ `grep -c 'riscv,pmp' ${dts}` -eq 0 ]; then + echo "$0: PMP node not found in ${dts}." - sed -i 's/ranges;/ranges;\n\t\tpmp: pmp@0 {\n\t\t\tcompatible = "riscv,pmp";\n\t\t\tregions = <1>;\n\t\t};/' ${dts} + # Check for targets without PMP support - echo -e "$0: \tAdded pmp@0" + TARGET=`echo ${dts} | cut -d '/' -f 1` + if [ $TARGET != "freedom-e310-arty" -a \ + $TARGET != "sifive-hifive1" -a \ + $TARGET != "coreip-e20-rtl" -a \ + $TARGET != "coreip-e20-arty" ]; then + + ${SED} -i 's/ranges;/ranges;\n\t\tpmp: pmp@0 {\n\t\t\tcompatible = "riscv,pmp";\n\t\t\tregions = <1>;\n\t\t};/' ${dts} + + echo -e "$0: \tAdded pmp@0" + fi fi # Add numintbits for the clic node if it doesn't exist @@ -37,7 +55,7 @@ if [ `grep -c 'sifive,clic0' ${dts}` -ne 0 ]; then if [ `grep -c 'sifive,numintbits' ${dts}` -eq 0 ]; then echo "$0: Clic missing numintbits in ${dts}." - sed -i 's/interrupt-controller@2000000 {/interrupt-controller@2000000 {\n\t\t\tsifive,numintbits = <2>;/g' ${dts} + ${SED} -i 's/interrupt-controller@2000000 {/interrupt-controller@2000000 {\n\t\t\tsifive,numintbits = <2>;/g' ${dts} echo -e "$0: \tAdded numintbits to clic." fi @@ -49,7 +67,7 @@ if [ `grep -c 'global-external-interrupts {' ${dts}` -ne 0 ]; then if [ `grep -c 'sifive,global-external-interrupts0' ${dts}` -eq 0 ]; then echo "$0: Global external interrupts missing compat string in ${dts}." - sed -i 's/global-external-interrupts {/global-external-interrupts {\n\t\t\tcompatible = "sifive,global-external-interrupts0";/g' ${dts} + ${SED} -i 's/global-external-interrupts {/global-external-interrupts {\n\t\t\tcompatible = "sifive,global-external-interrupts0";/g' ${dts} echo -e "$0: \tAdded compat string to global-external-interrupts." fi @@ -61,12 +79,32 @@ if [ `grep -c 'local-external-interrupts-0 {' ${dts}` -ne 0 ]; then if [ `grep -c 'sifive,local-external-interrupts0' ${dts}` -eq 0 ]; then echo "$0: Local external interrupts missing compat string in ${dts}." - sed -i 's/local-external-interrupts-0 {/local-external-interrupts {\n\t\t\tcompatible = "sifive,local-external-interrupts0";/g' ${dts} + ${SED} -i 's/local-external-interrupts-0 {/local-external-interrupts {\n\t\t\tcompatible = "sifive,local-external-interrupts0";/g' ${dts} echo -e "$0: \tAdded compat string to local-external-interrupts-0." fi fi +# Add a stdout-path to the chosen node if one doesn't exist and a serial port does + +if [ `grep -c 'stdout-path' ${dts}` -eq 0 ]; then + if [ `grep -c 'sifive,uart0' ${dts}` -ne 0 ]; then + echo "$0: stdout-path property not given, but a UART device exists." + + serial_node=`grep -oP "serial@\d+" ${dts} | sort | uniq | head -n 1` + serial_path="/soc/${serial_node}:115200" + + if [ `grep -c 'chosen' ${dts}` -eq 0 ]; then + ${SED} -i "/cpus/i chosen {\n};" ${dts} + fi + + ${SED} -i "/chosen/a stdout-path=\"${serial_path}\";" ${dts} + + echo -e "$0: \tAdded stdout-path ${serial_path}" + fi +fi + + # Add a test memory node if one doesn't exist if [ `grep -c 'sifive,testram0' ${dts}` -eq 0 ]; then @@ -137,7 +175,7 @@ if [ `grep -c 'sifive,testram0' ${dts}` -eq 0 ]; then echo -e "$0: \tWord size \t${word_size}" # Create the test memory - sed -i "s/ranges;/ranges;\n\t\ttest_memory: testram@${node_name_addr} {\n\t\t\tcompatible = \"sifive,testram0\";\n\t\t\treg = <${base_address} ${size}>;\n\t\t\treg-names = \"mem\";\n\t\t\tword-size-bytes = <${word_size}>;\n\t\t};/" ${dts} + ${SED} -i "s/ranges;/ranges;\n\t\ttest_memory: testram@${node_name_addr} {\n\t\t\tcompatible = \"sifive,testram0\";\n\t\t\treg = <${base_address} ${size}>;\n\t\t\treg-names = \"mem\";\n\t\t\tword-size-bytes = <${word_size}>;\n\t\t};/" ${dts} echo -e "$0: \tAdded testram@${node_name_addr}" # Break out of both loops |