1c8a3e6a8SGrant Likely#!/bin/sh
2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
3c8a3e6a8SGrant Likely# Simple script to update the version of DTC carried by the Linux kernel
4c8a3e6a8SGrant Likely#
5c8a3e6a8SGrant Likely# This script assumes that the dtc and the linux git trees are in the
6c8a3e6a8SGrant Likely# same directory. After building dtc in the dtc directory, it copies the
7e039139bSRob Herring# source files and generated source file(s) into the scripts/dtc directory
8c8a3e6a8SGrant Likely# in the kernel and creates a git commit updating them to the new
9c8a3e6a8SGrant Likely# version.
10c8a3e6a8SGrant Likely#
11c8a3e6a8SGrant Likely# Usage: from the top level Linux source tree, run:
12c8a3e6a8SGrant Likely# $ ./scripts/dtc/update-dtc-source.sh
13c8a3e6a8SGrant Likely#
14c8a3e6a8SGrant Likely# The script will change into the dtc tree, build and test dtc, copy the
15c8a3e6a8SGrant Likely# relevant files into the kernel tree and create a git commit. The commit
16c8a3e6a8SGrant Likely# message will need to be modified to reflect the version of DTC being
17c8a3e6a8SGrant Likely# imported
18c8a3e6a8SGrant Likely#
19c8a3e6a8SGrant Likely# TODO:
20c8a3e6a8SGrant Likely# This script is pretty basic, but it is seldom used so a few manual tasks
21c8a3e6a8SGrant Likely# aren't a big deal. If anyone is interested in making it more robust, the
22c8a3e6a8SGrant Likely# the following would be nice:
23c8a3e6a8SGrant Likely# * Actually fail to complete if any testcase fails.
24c8a3e6a8SGrant Likely#   - The dtc "make check" target needs to return a failure
25c8a3e6a8SGrant Likely# * Extract the version number from the dtc repo for the commit message
26c8a3e6a8SGrant Likely# * Build dtc in the kernel tree
27c8a3e6a8SGrant Likely# * run 'make check" on dtc built from the kernel tree
28c8a3e6a8SGrant Likely
29c8a3e6a8SGrant Likelyset -ev
30c8a3e6a8SGrant Likely
31c8a3e6a8SGrant LikelyDTC_UPSTREAM_PATH=`pwd`/../dtc
32c8a3e6a8SGrant LikelyDTC_LINUX_PATH=`pwd`/scripts/dtc
33c8a3e6a8SGrant Likely
34c8a3e6a8SGrant LikelyDTC_SOURCE="checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c srcpos.c \
35*ef8795f3SRob Herring		srcpos.h treesource.c util.c util.h version_gen.h \
36c8a3e6a8SGrant Likely		dtc-lexer.l dtc-parser.y"
3778154212SRob HerringLIBFDT_SOURCE="fdt.c fdt.h fdt_addresses.c fdt_empty_tree.c \
3843223230SRob Herring		fdt_overlay.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c \
3943223230SRob Herring		fdt_wip.c libfdt.h libfdt_env.h libfdt_internal.h"
40b775f49fSViresh KumarFDTOVERLAY_SOURCE=fdtoverlay.c
41c8a3e6a8SGrant Likely
4286cef614SRob Herringget_last_dtc_version() {
4386cef614SRob Herring	git log --oneline scripts/dtc/ | grep 'upstream' | head -1 | sed -e 's/^.* \(.*\)/\1/'
4486cef614SRob Herring}
4586cef614SRob Herring
4686cef614SRob Herringlast_dtc_ver=$(get_last_dtc_version)
4786cef614SRob Herring
48c8a3e6a8SGrant Likely# Build DTC
49c8a3e6a8SGrant Likelycd $DTC_UPSTREAM_PATH
50c8a3e6a8SGrant Likelymake clean
51c8a3e6a8SGrant Likelymake check
5286cef614SRob Herringdtc_version=$(git describe HEAD)
5386cef614SRob Herringdtc_log=$(git log --oneline ${last_dtc_ver}..)
5486cef614SRob Herring
55c8a3e6a8SGrant Likely
56c8a3e6a8SGrant Likely# Copy the files into the Linux tree
57c8a3e6a8SGrant Likelycd $DTC_LINUX_PATH
58b775f49fSViresh Kumarfor f in $DTC_SOURCE $FDTOVERLAY_SOURCE; do
59c8a3e6a8SGrant Likely	cp ${DTC_UPSTREAM_PATH}/${f} ${f}
60c8a3e6a8SGrant Likely	git add ${f}
61c8a3e6a8SGrant Likelydone
62695e9fddSGaurav Minochafor f in $LIBFDT_SOURCE; do
63695e9fddSGaurav Minocha       cp ${DTC_UPSTREAM_PATH}/libfdt/${f} libfdt/${f}
64695e9fddSGaurav Minocha       git add libfdt/${f}
65695e9fddSGaurav Minochadone
66695e9fddSGaurav Minocha
67695e9fddSGaurav Minochased -i -- 's/#include <libfdt_env.h>/#include "libfdt_env.h"/g' ./libfdt/libfdt.h
68695e9fddSGaurav Minochased -i -- 's/#include <fdt.h>/#include "fdt.h"/g' ./libfdt/libfdt.h
69695e9fddSGaurav Minochagit add ./libfdt/libfdt.h
70c8a3e6a8SGrant Likely
7186cef614SRob Herringcommit_msg=$(cat << EOF
7286cef614SRob Herringscripts/dtc: Update to upstream version ${dtc_version}
7386cef614SRob Herring
7486cef614SRob HerringThis adds the following commits from upstream:
7586cef614SRob Herring
7686cef614SRob Herring${dtc_log}
7786cef614SRob HerringEOF
7886cef614SRob Herring)
798654cb8dSRob Herring
8086cef614SRob Herringgit commit -e -v -s -m "${commit_msg}"
81