11.1Sskrll#! /bin/sh
21.1Sskrll#
31.4Sskrll#	$NetBSD: dwctwo2netbsd,v 1.4 2015/08/30 13:03:00 skrll Exp $
41.1Sskrll#
51.1Sskrll# Copyright (c) 2013 The NetBSD Foundation, Inc.
61.1Sskrll# All rights reserved.
71.1Sskrll#
81.1Sskrll# Redistribution and use in source and binary forms, with or without
91.1Sskrll# modification, are permitted provided that the following conditions
101.1Sskrll# are met:
111.1Sskrll# 1. Redistributions of source code must retain the above copyright
121.1Sskrll#    notice, this list of conditions and the following disclaimer.
131.1Sskrll# 2. Redistributions in binary form must reproduce the above copyright
141.1Sskrll#    notice, this list of conditions and the following disclaimer in the
151.1Sskrll#    documentation and/or other materials provided with the distribution.
161.1Sskrll#
171.1Sskrll# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
181.1Sskrll# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
191.1Sskrll# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
201.1Sskrll# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
211.1Sskrll# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
221.1Sskrll# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
231.1Sskrll# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
241.1Sskrll# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
251.1Sskrll# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
261.1Sskrll# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
271.1Sskrll# POSSIBILITY OF SUCH DAMAGE.
281.1Sskrll#
291.1Sskrll# dwctwo2netbsd:  prepare the synopsys driver sources for import into the
301.1Sskrll# netbsd dwc2 source tree, under src/sys/external/bsd/dwc2/dist,
311.1Sskrll# based on the other *2netbsd scripts in the NetBSD source tree
321.1Sskrll#
331.1Sskrll# Instructions for importing new dwc2 release:
341.1Sskrll#
351.1Sskrll#	$ DATE=$(date +%F)
361.1Sskrll#	$ cd /some/where/temporary
371.4Sskrll#	$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
381.3Sskrll#	$ DWC2SRCS=$(pwd)/drivers/usb/dwc2
391.2Sskrll#	$ WRKDIR=/an/other/temporary
401.2Sskrll#	$ sh /usr/src/sys/external/bsd/dwc2/dwctwo2netbsd $DWC2SRCS $WRKDIR
411.2Sskrll#	$ cd $WRKDIR
421.1Sskrll#	$ cvs -d cvs.netbsd.org:/cvsroot import -m "Import dwc2 $DATE" src/sys/external/bsd/dwc2/dist SYNOPSYS dwc2-$DATE
431.1Sskrll#
441.1Sskrll
451.1Sskrllif [ $# -ne 2 ]; then echo "dwctwo2netbsd src dest"; exit 1; fi
461.1Sskrll
471.1Sskrllr=$1
481.1Sskrlld=$2
491.1Sskrll
501.1Sskrllcase "$d" in
511.1Sskrll	/*)
521.1Sskrll		;;
531.1Sskrll	*)
541.1Sskrll		d=`/bin/pwd`/$d
551.1Sskrll		;;
561.1Sskrllesac
571.1Sskrll
581.1Sskrllcase "$r" in
591.1Sskrll	/*)
601.1Sskrll		;;
611.1Sskrll	*)
621.1Sskrll		r=`/bin/pwd`/$r
631.1Sskrll		;;
641.1Sskrllesac
651.1Sskrll
661.1Sskrllecho preparing directory $d
671.1Sskrllrm -rf $d
681.1Sskrllmkdir -p $d
691.1Sskrll
701.1Sskrll### Copy the files and directories
711.1Sskrllecho copying $r to $d
721.1Sskrllcd $r
731.1Sskrll
741.1Sskrll# Not copied
751.1Sskrll# pci.c platform.c
761.1Sskrll#
771.1Sskrllfor f in \
781.1Sskrll    core.c core.h core_intr.c hcd.c hcd.h hcd_ddma.c hcd_intr.c hcd_queue.c \
791.1Sskrll    hw.h
801.1Sskrlldo
811.1Sskrll	n=$(echo $f | sed -e 's:_::')
821.1Sskrll	cp $r/$f $d/dwc2_$n
831.1Sskrlldone
841.1Sskrll
851.1Sskrll# cd to import directory
861.1Sskrllcd $d
871.1Sskrll
881.1Sskrll### dwc2 distribution doesn't have RCS/CVS tags, so add them.
891.1Sskrll
901.1Sskrll### Add our NetBSD RCS Id
911.1Sskrllfind $d -type f -name '*.[ch]' -print | while read c; do
921.1Sskrll	sed 1q < $c | grep -q '\$NetBSD' || (
931.1Sskrllecho "/*	\$NetBSD\$	*/" >/tmp/dwc2n$$
941.1Sskrllecho "" >>/tmp/dwc2n$$
951.1Sskrllcat $c  >> /tmp/dwc2n$$
961.1Sskrllmv /tmp/dwc2n$$ $c && echo added NetBSD RCS tag to $c
971.1Sskrll	)
981.1Sskrlldone
991.1Sskrll
1001.1Sskrllecho done
1011.1Sskrll
1021.1Sskrll### Clean up any CVS directories that might be around.
1031.1Sskrllecho "cleaning up CVS residue."
1041.1Sskrll(
1051.1Sskrll	cd $d
1061.1Sskrll	find . -type d -name "CVS" -print | xargs rm -r
1071.1Sskrll)
1081.1Sskrllecho done
1091.1Sskrll
1101.1Sskrll### Fixing file and directory permissions.
1111.1Sskrllecho "Fixing file/directory permissions."
1121.1Sskrll(
1131.1Sskrll	cd $d
1141.1Sskrll	find . -type f -print | xargs chmod u+rw,go+r
1151.1Sskrll	find . -type d -print | xargs chmod u+rwx,go+rx
1161.1Sskrll)
1171.1Sskrllecho done
1181.1Sskrll
1191.1Sskrllexit 0
120