xref: /OK3568_Linux_fs/kernel/scripts/dtc/update-dtc-source.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/sh
2*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0
3*4882a593Smuzhiyun# Simple script to update the version of DTC carried by the Linux kernel
4*4882a593Smuzhiyun#
5*4882a593Smuzhiyun# This script assumes that the dtc and the linux git trees are in the
6*4882a593Smuzhiyun# same directory. After building dtc in the dtc directory, it copies the
7*4882a593Smuzhiyun# source files and generated source file(s) into the scripts/dtc directory
8*4882a593Smuzhiyun# in the kernel and creates a git commit updating them to the new
9*4882a593Smuzhiyun# version.
10*4882a593Smuzhiyun#
11*4882a593Smuzhiyun# Usage: from the top level Linux source tree, run:
12*4882a593Smuzhiyun# $ ./scripts/dtc/update-dtc-source.sh
13*4882a593Smuzhiyun#
14*4882a593Smuzhiyun# The script will change into the dtc tree, build and test dtc, copy the
15*4882a593Smuzhiyun# relevant files into the kernel tree and create a git commit. The commit
16*4882a593Smuzhiyun# message will need to be modified to reflect the version of DTC being
17*4882a593Smuzhiyun# imported
18*4882a593Smuzhiyun#
19*4882a593Smuzhiyun# TODO:
20*4882a593Smuzhiyun# This script is pretty basic, but it is seldom used so a few manual tasks
21*4882a593Smuzhiyun# aren't a big deal. If anyone is interested in making it more robust, the
22*4882a593Smuzhiyun# the following would be nice:
23*4882a593Smuzhiyun# * Actually fail to complete if any testcase fails.
24*4882a593Smuzhiyun#   - The dtc "make check" target needs to return a failure
25*4882a593Smuzhiyun# * Extract the version number from the dtc repo for the commit message
26*4882a593Smuzhiyun# * Build dtc in the kernel tree
27*4882a593Smuzhiyun# * run 'make check" on dtc built from the kernel tree
28*4882a593Smuzhiyun
29*4882a593Smuzhiyunset -ev
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunDTC_UPSTREAM_PATH=`pwd`/../dtc
32*4882a593SmuzhiyunDTC_LINUX_PATH=`pwd`/scripts/dtc
33*4882a593Smuzhiyun
34*4882a593SmuzhiyunDTC_SOURCE="checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c srcpos.c \
35*4882a593Smuzhiyun		srcpos.h treesource.c util.c util.h version_gen.h yamltree.c \
36*4882a593Smuzhiyun		dtc-lexer.l dtc-parser.y"
37*4882a593SmuzhiyunLIBFDT_SOURCE="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 $LIBFDT_SOURCE; do
62*4882a593Smuzhiyun       cp ${DTC_UPSTREAM_PATH}/libfdt/${f} libfdt/${f}
63*4882a593Smuzhiyun       git add libfdt/${f}
64*4882a593Smuzhiyundone
65*4882a593Smuzhiyun
66*4882a593Smuzhiyunsed -i -- 's/#include <libfdt_env.h>/#include "libfdt_env.h"/g' ./libfdt/libfdt.h
67*4882a593Smuzhiyunsed -i -- 's/#include <fdt.h>/#include "fdt.h"/g' ./libfdt/libfdt.h
68*4882a593Smuzhiyungit add ./libfdt/libfdt.h
69*4882a593Smuzhiyun
70*4882a593Smuzhiyuncommit_msg=$(cat << EOF
71*4882a593Smuzhiyunscripts/dtc: Update to upstream version ${dtc_version}
72*4882a593Smuzhiyun
73*4882a593SmuzhiyunThis adds the following commits from upstream:
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun${dtc_log}
76*4882a593SmuzhiyunEOF
77*4882a593Smuzhiyun)
78*4882a593Smuzhiyun
79*4882a593Smuzhiyungit commit -e -v -s -m "${commit_msg}"
80