Skip to content

Commit 3384dee

Browse files
Benn Huangamery
Benn Huang
authored andcommitted
build: update build script to support externel modules
1 parent e0deefe commit 3384dee

File tree

4 files changed

+161
-90
lines changed

4 files changed

+161
-90
lines changed

modules/example/Makefile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
################################################################################
3+
#
4+
# Common Variables that already set:
5+
# LICHEE_KDIR
6+
# LICHEE_MOD_DIR
7+
# CROSS_COMPILE
8+
# ARCH
9+
#
10+
#################################################################################
11+
PWD=$(shell pwd)
12+
13+
obj-m+=example.o
14+
15+
install: build
16+
cp example.ko $(LICHEE_MOD_DIR)/
17+
18+
build:
19+
@echo $(LICHEE_KDIR)
20+
$(MAKE) -C $(LICHEE_KDIR) M=$(PWD)
21+
22+
clean:
23+
@rm -rf *.o *.ko .*.cmd *.mod.c *.order *.symvers .tmp_versions *~
24+

modules/example/example.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <linux/kernel.h>
2+
#include <linux/init.h>
3+
#include <linux/module.h>
4+
5+
static int __init example_init(void)
6+
{
7+
pr_info("example init\n");
8+
return 0;
9+
}
10+
module_init(example_init);
11+
12+
static void __exit example_exit(void)
13+
{
14+
pr_info("example exit\n");
15+
}
16+
module_exit(example_exit);
17+
18+
MODULE_LICENSE("GPL");
19+

scripts/build_sun4i-lite.sh

+59-45
Original file line numberDiff line numberDiff line change
@@ -27,65 +27,79 @@ CONFIG_CHIP_ID=1123
2727

2828
update_kern_ver()
2929
{
30-
if [ -r include/generated/utsrelease.h ]; then
31-
KERNEL_VERSION=`cat include/generated/utsrelease.h |awk -F\" '{print $2}'`
32-
fi
33-
LICHEE_MOD_DIR=${LICHEE_KDIR}/output/lib/modules/${KERNEL_VERSION}
30+
if [ -r include/generated/utsrelease.h ]; then
31+
KERNEL_VERSION=`cat include/generated/utsrelease.h |awk -F\" '{print $2}'`
32+
fi
33+
LICHEE_MOD_DIR=${LICHEE_KDIR}/output/lib/modules/${KERNEL_VERSION}
3434
}
3535

3636
show_help()
3737
{
38-
printf "Build script for Lichee system\n"
39-
printf " Invalid Option:\n"
40-
printf " help - show this help\n"
41-
printf " kernel - build kernel for sun4i\n"
42-
printf " modules - build external modules for sun4i\n"
43-
printf " clean - clean all\n"
44-
printf "\n"
38+
printf "
39+
Build script for Lichee platform
40+
41+
Invalid Options:
42+
43+
help - show this help
44+
kernel - build kernel
45+
modules - build kernel module in modules dir
46+
clean - clean kernel and modules
47+
48+
"
4549
}
4650

4751

4852
build_kernel()
4953
{
50-
if [ ! -e .config ]; then
51-
echo -e "\n\t\tUsing default config... ...!\n"
52-
cp arch/arm/configs/sun4i_defconfig .config
53-
54-
fi
54+
if [ ! -e .config ]; then
55+
echo -e "\n\t\tUsing default config... ...!\n"
56+
cp arch/arm/configs/sun4i_defconfig .config
57+
fi
5558

56-
make KALLSYMS_EXTRA_PASS=1 ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} -j8
57-
update_kern_ver
59+
make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} -j8
60+
update_kern_ver
5861

59-
if [ -d output ]; then
60-
rm -rf output
61-
fi
62-
mkdir -p $LICHEE_MOD_DIR
62+
if [ -d output ]; then
63+
rm -rf output
64+
fi
65+
mkdir -p $LICHEE_MOD_DIR
6366

64-
${OBJCOPY} -R .note.gnu.build-id -S -O binary vmlinux output/bImage
65-
cp -vf arch/arm/boot/[zu]Image output/
66-
cp .config output/
67+
${OBJCOPY} -R .note.gnu.build-id -S -O binary vmlinux output/bImage
68+
cp -vf arch/arm/boot/[zu]Image output/
69+
cp .config output/
6770

6871

69-
for file in $(find drivers sound crypto block fs security net -name "*.ko"); do
70-
cp $file ${LICHEE_MOD_DIR}
71-
done
72-
cp -f Module.symvers modules.* ${LICHEE_MOD_DIR}
72+
for file in $(find drivers sound crypto block fs security net -name "*.ko"); do
73+
cp $file ${LICHEE_MOD_DIR}
74+
done
75+
cp -f Module.symvers modules.* ${LICHEE_MOD_DIR}
7376
}
7477

7578
build_modules()
7679
{
77-
echo "Building modules"
80+
echo "Building modules"
81+
82+
if [ ! -f include/generated/utsrelease.h ]; then
83+
printf "Please build kernel first!\n"
84+
exit 1
85+
fi
86+
87+
update_kern_ver
88+
89+
make -C modules/example LICHEE_MOD_DIR=${LICHEE_MOD_DIR} LICHEE_KDIR=${LICHEE_KDIR} \
90+
CONFIG_CHIP_ID=${CONFIG_CHIP_ID} install
7891
}
7992

8093
clean_kernel()
8194
{
82-
make clean
83-
rm -rf output/*
95+
make clean
96+
rm -rf output/*
8497
}
8598

8699
clean_modules()
87100
{
88-
echo "Cleaning modules"
101+
echo "Cleaning modules"
102+
make -C modules/example LICHEE_MOD_DIR=${LICHEE_MOD_DIR} LICHEE_KDIR=${LICHEE_KDIR} clean
89103
}
90104

91105
#####################################################################
@@ -99,21 +113,21 @@ export PATH=${LICHEE_ROOT}/buildroot/output/external-toolchain/bin:$PATH
99113

100114
case "$1" in
101115
kernel)
102-
build_kernel
103-
;;
116+
build_kernel
117+
;;
104118
modules)
105-
build_modules
106-
;;
119+
build_modules
120+
;;
107121
clean)
108-
clean_kernel
109-
clean_modules
110-
;;
122+
clean_kernel
123+
clean_modules
124+
;;
111125
all)
112-
build_kernel
113-
build_modules
114-
;;
126+
build_kernel
127+
build_modules
128+
;;
115129
*)
116-
show_help
117-
;;
130+
show_help
131+
;;
118132
esac
119133

scripts/build_sun4i.sh

+59-45
Original file line numberDiff line numberDiff line change
@@ -27,65 +27,79 @@ CONFIG_CHIP_ID=1123
2727

2828
update_kern_ver()
2929
{
30-
if [ -r include/generated/utsrelease.h ]; then
31-
KERNEL_VERSION=`cat include/generated/utsrelease.h |awk -F\" '{print $2}'`
32-
fi
33-
LICHEE_MOD_DIR=${LICHEE_KDIR}/output/lib/modules/${KERNEL_VERSION}
30+
if [ -r include/generated/utsrelease.h ]; then
31+
KERNEL_VERSION=`cat include/generated/utsrelease.h |awk -F\" '{print $2}'`
32+
fi
33+
LICHEE_MOD_DIR=${LICHEE_KDIR}/output/lib/modules/${KERNEL_VERSION}
3434
}
3535

3636
show_help()
3737
{
38-
printf "Build script for Lichee system\n"
39-
printf " Invalid Option:\n"
40-
printf " help - show this help\n"
41-
printf " kernel - build kernel for sun4i\n"
42-
printf " modules - build external modules for sun4i\n"
43-
printf " clean - clean all\n"
44-
printf "\n"
38+
printf "
39+
Build script for Lichee platform
40+
41+
Invalid Options:
42+
43+
help - show this help
44+
kernel - build kernel
45+
modules - build kernel module in modules dir
46+
clean - clean kernel and modules
47+
48+
"
4549
}
4650

4751

4852
build_kernel()
4953
{
50-
if [ ! -e .config ]; then
51-
echo -e "\n\t\tUsing default config... ...!\n"
52-
cp arch/arm/configs/sun4i_defconfig .config
53-
54-
fi
54+
if [ ! -e .config ]; then
55+
echo -e "\n\t\tUsing default config... ...!\n"
56+
cp arch/arm/configs/sun4i_defconfig .config
57+
fi
5558

56-
make KALLSYMS_EXTRA_PASS=1 ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} -j8
57-
update_kern_ver
59+
make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} -j8
60+
update_kern_ver
5861

59-
if [ -d output ]; then
60-
rm -rf output
61-
fi
62-
mkdir -p $LICHEE_MOD_DIR
62+
if [ -d output ]; then
63+
rm -rf output
64+
fi
65+
mkdir -p $LICHEE_MOD_DIR
6366

64-
${OBJCOPY} -R .note.gnu.build-id -S -O binary vmlinux output/bImage
65-
cp -vf arch/arm/boot/[zu]Image output/
66-
cp .config output/
67+
${OBJCOPY} -R .note.gnu.build-id -S -O binary vmlinux output/bImage
68+
cp -vf arch/arm/boot/[zu]Image output/
69+
cp .config output/
6770

6871

69-
for file in $(find drivers sound crypto block fs security net -name "*.ko"); do
70-
cp $file ${LICHEE_MOD_DIR}
71-
done
72-
cp -f Module.symvers modules.* ${LICHEE_MOD_DIR}
72+
for file in $(find drivers sound crypto block fs security net -name "*.ko"); do
73+
cp $file ${LICHEE_MOD_DIR}
74+
done
75+
cp -f Module.symvers modules.* ${LICHEE_MOD_DIR}
7376
}
7477

7578
build_modules()
7679
{
77-
echo "Building modules"
80+
echo "Building modules"
81+
82+
if [ ! -f include/generated/utsrelease.h ]; then
83+
printf "Please build kernel first!\n"
84+
exit 1
85+
fi
86+
87+
update_kern_ver
88+
89+
make -C modules/example LICHEE_MOD_DIR=${LICHEE_MOD_DIR} LICHEE_KDIR=${LICHEE_KDIR} \
90+
CONFIG_CHIP_ID=${CONFIG_CHIP_ID} install
7891
}
7992

8093
clean_kernel()
8194
{
82-
make clean
83-
rm -rf output/*
95+
make clean
96+
rm -rf output/*
8497
}
8598

8699
clean_modules()
87100
{
88-
echo "Cleaning modules"
101+
echo "Cleaning modules"
102+
make -C modules/example LICHEE_MOD_DIR=${LICHEE_MOD_DIR} LICHEE_KDIR=${LICHEE_KDIR} clean
89103
}
90104

91105
#####################################################################
@@ -99,21 +113,21 @@ export PATH=${LICHEE_ROOT}/buildroot/output/external-toolchain/bin:$PATH
99113

100114
case "$1" in
101115
kernel)
102-
build_kernel
103-
;;
116+
build_kernel
117+
;;
104118
modules)
105-
build_modules
106-
;;
119+
build_modules
120+
;;
107121
clean)
108-
clean_kernel
109-
clean_modules
110-
;;
122+
clean_kernel
123+
clean_modules
124+
;;
111125
all)
112-
build_kernel
113-
build_modules
114-
;;
126+
build_kernel
127+
build_modules
128+
;;
115129
*)
116-
show_help
117-
;;
130+
show_help
131+
;;
118132
esac
119133

0 commit comments

Comments
 (0)