release.sh revision 264141
1#!/bin/sh
2#-
3# Copyright (c) 2013, 2014 The FreeBSD Foundation
4# All rights reserved.
5#
6# This software was developed by Glen Barber
7# under sponsorship from the FreeBSD Foundation.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28# SUCH DAMAGE.
29#
30# $FreeBSD: stable/9/release/arm/release.sh 262810 2014-03-05 23:17:53Z gjb $
31#
32
33# This script is intended to be called by release/release.sh to build ARM
34# images for release.  It is not intended to be run directly.  This sets up
35# the software needed within a build chroot, then runs crochet to provide
36# downloadable images for embedded devices.
37
38set -e
39
40before_build() {
41	WANT_UBOOT=
42	KNOWNHASH=
43	UBOOT_VERSION=
44	case ${KERNEL} in
45		BEAGLEBONE)
46			WANT_UBOOT=1
47			KNOWNHASH="4150e5a4480707c55a8d5b4570262e43af68d8ed3bdc0a433d8e7df47989a69e"
48			UBOOT_VERSION="u-boot-2013.04"
49			;;
50		PANDABOARD)
51			WANT_UBOOT=1
52			KNOWNHASH="e08e20a6979bfca6eebb9a2b0e42aa4416af3d796332fd63a3470495a089d496"
53			UBOOT_VERSION="u-boot-2012.07"
54			;;
55		WANDBOARD-QUAD)
56			WANT_UBOOT=1
57			KNOWNHASH="0d71e62beb952b41ebafb20a7ee4df2f960db64c31b054721ceb79ff14014c55"
58			UBOOT_VERSION="u-boot-2013.10"
59			;;
60		*)
61			# Fallthrough.
62			;;
63	esac
64	if [ ! -z ${WANT_UBOOT} ]; then
65		chroot ${CHROOTDIR} fetch -o /tmp/crochet/${UBOOT_VERSION}.tar.bz2 \
66			http://people.freebsd.org/~gjb/${UBOOT_VERSION}.tar.bz2
67		UBOOT_HASH="$(sha256 -q ${CHROOTDIR}/tmp/crochet/${UBOOT_VERSION}.tar.bz2)"
68		if [ "${UBOOT_HASH}" != "${KNOWNHASH}" ]; then
69			echo "Checksum mismatch!  Exiting now."
70			exit 1
71		fi
72		chroot ${CHROOTDIR} tar xf /tmp/crochet/${UBOOT_VERSION}.tar.bz2 \
73			-C /tmp/crochet/ 
74	fi
75}
76
77install_crochet() {
78	chroot ${CHROOTDIR} svn co -q ${CROCHETSRC}/${CROCHETBRANCH} \
79		/tmp/crochet
80}
81
82install_uboot() {
83	# Only fetch u-boot sources if UBOOTSRC is set; otherwise it is
84	# not needed.
85	if [ -n "${UBOOTSRC}" ]; then
86		continue
87	else
88		return 0
89	fi
90	chroot ${CHROOTDIR} svn co -q ${UBOOTSRC}/${UBOOTBRANCH} \
91		/${UBOOTDIR}
92}
93
94main() {
95	# Build gcc for use in the chroot for arm builds.
96	# This is not '-j'-safe, so force '-j1' to allow using
97	# additional, non-'-j' options specified in WORLD_FLAGS.
98	eval chroot ${CHROOTDIR} make -C /usr/src/gnu/usr.bin/cc \
99		WITH_GCC=1 ${WORLD_FLAGS} -j1 obj depend all install
100	# Build the 'xdev' target for crochet.
101	eval chroot ${CHROOTDIR} make -C /usr/src \
102		XDEV=${XDEV} XDEV_ARCH=${XDEV_ARCH} WITH_GCC=1 \
103		${WORLD_FLAGS} xdev
104
105	# Run the ldconfig(8) startup script so /var/run/ld-elf*.so.hints
106	# is created.
107	eval chroot ${CHROOTDIR} /etc/rc.d/ldconfig forcerestart
108	# Install security/ca_root_nss since we need to check the https
109	# certificate of github.
110	eval chroot ${CHROOTDIR} make -C /usr/ports/security/ca_root_nss \
111		OPTIONS_SET="ETCSYMLINK" BATCH=1 FORCE_PKG_REGISTER=1 \
112		install clean distclean
113	EMBEDDEDPORTS="${EMBEDDEDPORTS} devel/subversion"
114	for _PORT in ${EMBEDDEDPORTS}; do
115		eval chroot ${CHROOTDIR} make -C /usr/ports/${_PORT} \
116			BATCH=1 FORCE_PKG_REGISTER=1 install clean distclean
117	done
118
119	mkdir -p ${CHROOTDIR}/tmp/crochet/work
120	before_build
121	install_crochet
122	install_uboot
123	eval chroot ${CHROOTDIR} /bin/sh /tmp/crochet/crochet.sh \
124		-c /tmp/external/${XDEV}/crochet-${KERNEL}.conf
125	mkdir -p ${CHROOTDIR}/R/
126	cp -p ${CHROOTDIR}/usr/obj/*.img ${CHROOTDIR}/R/
127	bzip2 ${CHROOTDIR}/R/FreeBSD*.img
128	cd ${CHROOTDIR}/R/ && sha256 FreeBSD*.img.bz2 > CHECKSUM.SHA256
129	cd ${CHROOTDIR}/R/ && md5 FreeBSD*.img.bz2 > CHECKSUM.MD5
130}
131
132main "$@"
133exit 0
134