2 # SPDX-License-Identifier: GPL-2.0+
4 # Create an initrd directory if one does not already exist.
6 # Copyright (C) IBM Corporation, 2013
8 # Author: Connor Shu <Connor.Shu@ibm.com>
10 D
=tools
/testing
/selftests
/rcutorture
13 [ -z "$D" ] && echo >&2 "No argument supplied" && exit 1
14 if [ ! -d "$D" ]; then
15 echo >&2 "$D does not exist: Malformed kernel source tree?"
18 if [ -s "$D/initrd/init" ]; then
19 echo "$D/initrd/init already exists, no need to create it"
23 # Create a C-language initrd/init infinite-loop program and statically
24 # link it. This results in a very small initrd.
25 echo "Creating a statically linked C-language initrd"
29 cat > init.c
<< '___EOF___'
35 volatile unsigned long delaycount
;
37 int main
(int argc
, int argv
[])
45 /* Need some userspace
time.
*/
46 if (gettimeofday
(&tvb
, NULL
))
49 for (i
= 0; i
< 1000 * 100; i
++)
51 if (gettimeofday
(&tv
, NULL
))
53 tv.tv_sec
-= tvb.tv_sec
;
56 tv.tv_usec
+= tv.tv_sec
* 1000 * 1000;
57 tv.tv_usec
-= tvb.tv_usec
;
58 } while (tv.tv_usec
< 1000);
64 # build using nolibc on supported archs (smaller executable) and fall
65 # back to regular glibc on other ones.
66 if echo -e "#if __x86_64__||__i386__||__i486__||__i586__||__i686__" \
67 "||__ARM_EABI__||__aarch64__\nyes\n#endif" \
68 |
${CROSS_COMPILE}gcc
-E -nostdlib -xc - \
69 |
grep -q '^yes'; then
70 # architecture supported by nolibc
71 ${CROSS_COMPILE}gcc
-fno-asynchronous-unwind-tables -fno-ident \
72 -nostdlib -include ..
/..
/..
/..
/include
/nolibc
/nolibc.h \
73 -lgcc -s -static -Os -o init init.c
75 ${CROSS_COMPILE}gcc
-s -static -Os -o init init.c
79 echo "Done creating a statically linked C-language initrd"