update-dtc-source.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. # Simple script to update the version of DTC carried by the Linux kernel
  4. #
  5. # This script assumes that the dtc and the linux git trees are in the
  6. # same directory. After building dtc in the dtc directory, it copies the
  7. # source files and generated source files into the scripts/dtc directory
  8. # in the kernel and creates a git commit updating them to the new
  9. # version.
  10. #
  11. # Usage: from the top level Linux source tree, run:
  12. # $ ./scripts/dtc/update-dtc-source.sh
  13. #
  14. # The script will change into the dtc tree, build and test dtc, copy the
  15. # relevant files into the kernel tree and create a git commit. The commit
  16. # message will need to be modified to reflect the version of DTC being
  17. # imported
  18. #
  19. # TODO:
  20. # This script is pretty basic, but it is seldom used so a few manual tasks
  21. # aren't a big deal. If anyone is interested in making it more robust, the
  22. # the following would be nice:
  23. # * Actually fail to complete if any testcase fails.
  24. # - The dtc "make check" target needs to return a failure
  25. # * Extract the version number from the dtc repo for the commit message
  26. # * Build dtc in the kernel tree
  27. # * run 'make check" on dtc built from the kernel tree
  28. set -ev
  29. DTC_UPSTREAM_PATH=`pwd`/../dtc
  30. DTC_LINUX_PATH=`pwd`/scripts/dtc
  31. DTC_SOURCE="checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c srcpos.c \
  32. srcpos.h treesource.c util.c util.h version_gen.h Makefile.dtc \
  33. dtc-lexer.l dtc-parser.y"
  34. DTC_GENERATED="dtc-lexer.lex.c dtc-parser.tab.c dtc-parser.tab.h"
  35. LIBFDT_SOURCE="Makefile.libfdt fdt.c fdt.h fdt_addresses.c fdt_empty_tree.c \
  36. fdt_overlay.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c \
  37. fdt_wip.c libfdt.h libfdt_env.h libfdt_internal.h"
  38. get_last_dtc_version() {
  39. git log --oneline scripts/dtc/ | grep 'upstream' | head -1 | sed -e 's/^.* \(.*\)/\1/'
  40. }
  41. last_dtc_ver=$(get_last_dtc_version)
  42. # Build DTC
  43. cd $DTC_UPSTREAM_PATH
  44. make clean
  45. make check
  46. dtc_version=$(git describe HEAD)
  47. dtc_log=$(git log --oneline ${last_dtc_ver}..)
  48. # Copy the files into the Linux tree
  49. cd $DTC_LINUX_PATH
  50. for f in $DTC_SOURCE; do
  51. cp ${DTC_UPSTREAM_PATH}/${f} ${f}
  52. git add ${f}
  53. done
  54. for f in $DTC_GENERATED; do
  55. cp ${DTC_UPSTREAM_PATH}/$f ${f}_shipped
  56. git add ${f}_shipped
  57. done
  58. for f in $LIBFDT_SOURCE; do
  59. cp ${DTC_UPSTREAM_PATH}/libfdt/${f} libfdt/${f}
  60. git add libfdt/${f}
  61. done
  62. sed -i -- 's/#include <libfdt_env.h>/#include "libfdt_env.h"/g' ./libfdt/libfdt.h
  63. sed -i -- 's/#include <fdt.h>/#include "fdt.h"/g' ./libfdt/libfdt.h
  64. git add ./libfdt/libfdt.h
  65. commit_msg=$(cat << EOF
  66. scripts/dtc: Update to upstream version ${dtc_version}
  67. This adds the following commits from upstream:
  68. ${dtc_log}
  69. EOF
  70. )
  71. git commit -e -v -s -m "${commit_msg}"