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