@@ -23,32 +23,127 @@ PARALLEL="-j$(nproc)"
23
23
24
24
OUTPUT_DIR=./build/linux-image/
25
25
26
+ BR_PKG_DIR=./tests/system/br_pkgs
27
+
28
+ function create_br_pkg_config()
29
+ {
30
+ local pkg_name=$1
31
+ local output_path=$2
32
+
33
+ cat << EOF > "${output_path} "
34
+ config BR2_PACKAGE_${pkg_name^^}
35
+ bool "${pkg_name} "
36
+ help
37
+ ${pkg_name} package.
38
+ EOF
39
+ }
40
+
41
+ function create_br_pkg_makefile()
42
+ {
43
+ local pkg_name=$1
44
+ local output_path=$2
45
+
46
+ cat << EOF > "${output_path} "
47
+ ################################################################################
48
+ #
49
+ # ${pkg_name} package
50
+ #
51
+ ################################################################################
52
+
53
+ ${pkg_name^^} _VERSION = 1.0
54
+ ${pkg_name^^} _SITE = package/${pkg_name} /src
55
+ ${pkg_name^^} _SITE_METHOD = local
56
+
57
+ define ${pkg_name^^} _BUILD_CMDS
58
+ \$ (MAKE) CC="\$ (TARGET_CC)" LD="\$ (TARGET_LD)" -C \$ (@D)
59
+ endef
60
+
61
+ define ${pkg_name^^} _INSTALL_TARGET_CMDS
62
+ \$ (INSTALL) -D -m 0755 \$ (@D)/${pkg_name} \$ (TARGET_DIR)/usr/bin
63
+ endef
64
+
65
+ \$ (eval \$ (generic-package))
66
+ EOF
67
+ }
68
+
69
+ function create_br_pkg_src()
70
+ {
71
+ local pkg_name=$1
72
+ local src_c_file=$2
73
+ local output_path=$3
74
+ local mk_output_path=$3 /Makefile
75
+ local src_output_path=$3 /$pkg_name .c
76
+
77
+ # Create src directory
78
+ mkdir -p ${output_path}
79
+
80
+ # Create makefile
81
+ # the output binary is in lowercase
82
+ cat << EOF > "${mk_output_path} "
83
+ all:
84
+ \$ (CC) ${pkg_name} .c -o ${pkg_name}
85
+ EOF
86
+
87
+ # moving C source file
88
+ cp -f ${src_c_file} ${src_output_path}
89
+ }
90
+
91
+ function update_br_pkg_config()
92
+ {
93
+ local pkg_name=$1
94
+
95
+ cat << EOF >> "${SRC_DIR} /buildroot/package/Config.in"
96
+ menu "${pkg_name} "
97
+ source "package/${pkg_name} /Config.in"
98
+ endmenu
99
+
100
+ EOF
101
+ }
102
+
103
+ # This function patches the packages when building the rootfs.cpio from scratch
104
+ function do_patch_buildroot
105
+ {
106
+ for c in $( find ${BR_PKG_DIR} -type f) ; do
107
+ local basename=" $( basename ${c} ) "
108
+ local pkg_name=" ${basename% .* } "
109
+
110
+ mkdir -p ${SRC_DIR} /buildroot/package/${pkg_name}
111
+
112
+ create_br_pkg_config ${pkg_name} ${SRC_DIR} /buildroot/package/${pkg_name} /Config.in
113
+ create_br_pkg_makefile ${pkg_name} ${SRC_DIR} /buildroot/package/${pkg_name} /${pkg_name} .mk
114
+ create_br_pkg_src ${pkg_name} ${c} ${SRC_DIR} /buildroot/package/${pkg_name} /src
115
+
116
+ update_br_pkg_config ${pkg_name}
117
+ done
118
+ }
119
+
26
120
function do_buildroot
27
121
{
28
- cp -f assets/system/configs/buildroot.config $SRC_DIR /buildroot/.config
29
- cp -f assets/system/configs/busybox.config $SRC_DIR /buildroot/busybox.config
122
+ cp -f assets/system/configs/buildroot.config ${ SRC_DIR} /buildroot/.config
123
+ cp -f assets/system/configs/busybox.config ${ SRC_DIR} /buildroot/busybox.config
30
124
# Otherwise, the error below raises:
31
125
# You seem to have the current working directory in your
32
126
# LD_LIBRARY_PATH environment variable. This doesn't work.
33
127
unset LD_LIBRARY_PATH
34
- pushd $SRC_DIR /buildroot
128
+ do_patch_buildroot
129
+ pushd ${SRC_DIR} /buildroot
35
130
ASSERT make olddefconfig
36
- ASSERT make $PARALLEL
131
+ ASSERT make ${ PARALLEL}
37
132
popd
38
- cp -f $SRC_DIR /buildroot/output/images/rootfs.cpio $OUTPUT_DIR
133
+ cp -f ${ SRC_DIR} /buildroot/output/images/rootfs.cpio ${ OUTPUT_DIR}
39
134
}
40
135
41
136
function do_linux
42
137
{
43
- cp -f assets/system/configs/linux.config $SRC_DIR /linux/.config
44
- export PATH=" $SRC_DIR /buildroot/output/host/bin:$PATH "
138
+ cp -f assets/system/configs/linux.config ${ SRC_DIR} /linux/.config
139
+ export PATH=" ${ SRC_DIR} /buildroot/output/host/bin:${ PATH} "
45
140
export CROSS_COMPILE=riscv32-buildroot-linux-gnu-
46
141
export ARCH=riscv
47
- pushd $SRC_DIR /linux
142
+ pushd ${ SRC_DIR} /linux
48
143
ASSERT make olddefconfig
49
- ASSERT make $PARALLEL
144
+ ASSERT make ${ PARALLEL}
50
145
popd
51
- cp -f $SRC_DIR /linux/arch/riscv/boot/Image $OUTPUT_DIR
146
+ cp -f ${ SRC_DIR} /linux/arch/riscv/boot/Image ${ OUTPUT_DIR}
52
147
}
53
148
54
149
do_buildroot && OK
0 commit comments