-
Notifications
You must be signed in to change notification settings - Fork 1
/
init-kmod.sh
executable file
·87 lines (73 loc) · 2.91 KB
/
init-kmod.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# Create a new buildroot kernel module build
if [ "$#" -ne 2 ]; then
echo "usage: $0 <name> <buildroot-version>"
exit 1
fi
NAME=$1
BUILDROOT_VERSION=$2
BUILDROOT_NAME="buildroot-$BUILDROOT_VERSION"
BUILDROOT_PATH="/tmp/$BUILDROOT_NAME"
# buildroot output directory
BROUT="${PWD}/${NAME}/build"
# buildroot external tree directory
EXT_PATH="${PWD}/${NAME}/ext-tree"
# the base dir where actual code is stored
SRCBASE=$NAME/src
# the source directory for the new kmod
SRCMOD="$NAME/src/${NAME}_kmod"
# download the buildroot archive now if it's not in /tmp so we can bail early if that fails too
if [ ! -d $BUILDROOT_PATH ]; then
echo "buildroot path not found"
wget -c "https://buildroot.org/downloads/buildroot-${BUILDROOT_VERSION}.tar.gz" -O - | tar xz -C /tmp > /dev/null 2>&1
if [ ! -d $BUILDROOT_PATH ]; then
echo "failed to download buildroot version '$BUILDROOT_VERSION'"
exit 1
fi
fi
### SET UP THE BUILDROOT EXTERNAL TREE STRUCTURE
# create the base dirs for the build
mkdir -p $BROUT
mkdir -p $EXT_PATH
mkdir -p $SRCMOD
# copy over a modified version of the template makefile and hello_world module
sed "s/hello\.c/$NAME.c/g" template/kmod.Makefile > $SRCMOD/Makefile
cp template/hello_kmod/hello.c $SRCMOD/$NAME.c
# copy over the template ext-tree directory
cp -a template/ext-tree $NAME/.
# replace lowercase instances
sed -i "s/pkgname/${NAME}/g" $EXT_PATH/Config.in
sed -i "s/pkgname/${NAME}/g" $EXT_PATH/external.desc
sed -i "s/pkgname/${NAME}/g" $EXT_PATH/external.mk
# replace uppercase instances
sed -i "s/PKGNAME/${NAME^^}/g" $EXT_PATH/Config.in
sed -i "s/PKGNAME/${NAME^^}/g" $EXT_PATH/external.desc
sed -i "s/PKGNAME/${NAME^^}/g" $EXT_PATH/external.mk
# rename the package and pkg files in the ext-tree packages dir from the
# template values
PACKDIR="$EXT_PATH/package/$NAME"
mv $EXT_PATH/package/pkgname $PACKDIR
mv $PACKDIR/pkgname.mk $PACKDIR/$NAME.mk
# replace lowercase instances
sed -i "s/pkgname/${NAME}/g" $PACKDIR/$NAME.mk
sed -i "s/pkgname/${NAME}/g" $PACKDIR/Config.in
# replace uppercase instances
sed -i "s/PKGNAME/${NAME^^}/g" $PACKDIR/$NAME.mk
sed -i "s/PKGNAME/${NAME^^}/g" $PACKDIR/Config.in
# copy in the build script (just runs make in the build dir, assumes everything else has been set)
cp template/build.sh $NAME/.
cp template/qemu-run.sh $NAME/.
chmod +x $NAME/build.sh
chmod +x $NAME/qemu-run.sh
# copy config fragments and the buildroot tree into the project dir
cp configs/*FRAG $NAME/.
cp -a $BUILDROOT_PATH $NAME/$BUILDROOT_NAME
cd $NAME/$BUILDROOT_NAME
# stick to using relative paths so the project dir can be relocated without breaking builds (mostly)
make O=../build BR2_EXTERNAL=../ext-tree qemu_x86_64_defconfig
# move back out to the build dir to update the generated .config with the fragments
cd $BROUT
cat ../defconfig-FRAG >> .config
make olddefconfig
# kick off menuconfig to allow user to enable the building of the custom package
make menuconfig