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