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 7c8a3e6a8SGrant Likely# source files and generated source files 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 \ 35c8a3e6a8SGrant Likely srcpos.h treesource.c util.c util.h version_gen.h Makefile.dtc \ 36c8a3e6a8SGrant Likely dtc-lexer.l dtc-parser.y" 37c8a3e6a8SGrant LikelyDTC_GENERATED="dtc-lexer.lex.c dtc-parser.tab.c dtc-parser.tab.h" 38695e9fddSGaurav MinochaLIBFDT_SOURCE="Makefile.libfdt fdt.c fdt.h fdt_empty_tree.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c fdt_wip.c libfdt.h libfdt_env.h libfdt_internal.h" 39c8a3e6a8SGrant Likely 4086cef614SRob Herringget_last_dtc_version() { 4186cef614SRob Herring git log --oneline scripts/dtc/ | grep 'upstream' | head -1 | sed -e 's/^.* \(.*\)/\1/' 4286cef614SRob Herring} 4386cef614SRob Herring 4486cef614SRob Herringlast_dtc_ver=$(get_last_dtc_version) 4586cef614SRob Herring 46c8a3e6a8SGrant Likely# Build DTC 47c8a3e6a8SGrant Likelycd $DTC_UPSTREAM_PATH 48c8a3e6a8SGrant Likelymake clean 49c8a3e6a8SGrant Likelymake check 5086cef614SRob Herringdtc_version=$(git describe HEAD) 5186cef614SRob Herringdtc_log=$(git log --oneline ${last_dtc_ver}..) 5286cef614SRob Herring 53c8a3e6a8SGrant Likely 54c8a3e6a8SGrant Likely# Copy the files into the Linux tree 55c8a3e6a8SGrant Likelycd $DTC_LINUX_PATH 56c8a3e6a8SGrant Likelyfor f in $DTC_SOURCE; do 57c8a3e6a8SGrant Likely cp ${DTC_UPSTREAM_PATH}/${f} ${f} 58c8a3e6a8SGrant Likely git add ${f} 59c8a3e6a8SGrant Likelydone 60c8a3e6a8SGrant Likelyfor f in $DTC_GENERATED; do 61c8a3e6a8SGrant Likely cp ${DTC_UPSTREAM_PATH}/$f ${f}_shipped 62c8a3e6a8SGrant Likely git add ${f}_shipped 63c8a3e6a8SGrant Likelydone 64695e9fddSGaurav Minochafor f in $LIBFDT_SOURCE; do 65695e9fddSGaurav Minocha cp ${DTC_UPSTREAM_PATH}/libfdt/${f} libfdt/${f} 66695e9fddSGaurav Minocha git add libfdt/${f} 67695e9fddSGaurav Minochadone 68695e9fddSGaurav Minocha 69695e9fddSGaurav Minochased -i -- 's/#include <libfdt_env.h>/#include "libfdt_env.h"/g' ./libfdt/libfdt.h 70695e9fddSGaurav Minochased -i -- 's/#include <fdt.h>/#include "fdt.h"/g' ./libfdt/libfdt.h 71695e9fddSGaurav Minochagit add ./libfdt/libfdt.h 72c8a3e6a8SGrant Likely 7386cef614SRob Herringcommit_msg=$(cat << EOF 7486cef614SRob Herringscripts/dtc: Update to upstream version ${dtc_version} 7586cef614SRob Herring 7686cef614SRob HerringThis adds the following commits from upstream: 7786cef614SRob Herring 7886cef614SRob Herring${dtc_log} 7986cef614SRob HerringEOF 8086cef614SRob Herring) 818654cb8dSRob Herring 8286cef614SRob Herringgit commit -e -v -s -m "${commit_msg}" 83