dtbo_apply_overlay.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. # Treble kerenl requires the SoC device tree and the device specific
  3. # device tree overlay to be built separately. Before the bootloader
  4. # supports applying overlay, the overlay step to form the dtb passed
  5. # to the linux kernel is done on the host side with this script.
  6. set -x
  7. # prepare overlay workspace
  8. overlay_dir=`mktemp -d -t overlay.XXXXXXXXXX`
  9. TOP=${PWD}
  10. KERNEL_DTB=${TOP}/$1
  11. DTBO=${TOP}/$2
  12. trap "rm -rf ${overlay_dir}; set +x; exit" SIGINT
  13. cd ${overlay_dir}
  14. # extract soc dtb
  15. extract_dtb ${KERNEL_DTB} soc.dtb Image.lz4
  16. soc_cnt=$(ls -l soc.dtb* | wc -l)
  17. if [ ${soc_cnt} -ne 1 ]; then
  18. echo "Error: ${soc_cnt} soc.dtb(s) appended to Image.lz4-dtb" >&2
  19. exit 1
  20. fi
  21. # extract dtbo, rev and id
  22. mkdtimg dump ${DTBO} -b overlay.dtbo > dtbo.info
  23. id_arr=(`grep dtbo.info -e "id" | sed 's/.*id = \([0-9a-f]\+\)/\1/'`)
  24. rev_arr=(`grep dtbo.info -e "rev" | sed 's/.*rev = \([0-9a-f]\+\)/\1/'`)
  25. # add number if there's only one dtbo entry
  26. if [ ${#id_arr[*]} -eq 1 ]; then
  27. mv overlay.dtbo overlay.dtbo.0
  28. fi
  29. for idx in ${!id_arr[*]}; do
  30. echo "apply overlay for device id=${id_arr[$idx]} rev=${rev_arr[$idx]}"
  31. ufdt_apply_overlay soc.dtb overlay.dtbo.${idx} combined-${idx}.dtb
  32. dtc -q -O dts -o combined-${idx}.dts combined-${idx}.dtb
  33. echo "/{qcom,board-id=<0x${id_arr[$idx]} 0x${rev_arr[$idx]}>;};" >> \
  34. combined-${idx}.dts
  35. dtc -q -O dtb -o combined-${idx}.dtb combined-${idx}.dts
  36. done
  37. # ls -v is used to make sure dtb is combined as the order specified in
  38. # dtboimg.cfg, where muskie/walley dtbs are before taimen dtbs. Otherwise,
  39. # muskie/walleye's bootloader may give up looking for dtbs once it sees
  40. # an invalid dtb, i.e. taimen dtb.
  41. cat Image.lz4 `ls -v combined-*.dtb` > Image.lz4-dtb
  42. cp Image.lz4-dtb ${KERNEL_DTB}
  43. rm -rf ${overlay_dir}
  44. set +x