@@ -19,11 +19,31 @@ function OK
19
19
20
20
PARALLEL=" -j$( nproc) "
21
21
22
+ function safe_copy {
23
+ local src=" $1 "
24
+ local dst=" $2 "
25
+
26
+ if [ ! -f " $dst " ]; then
27
+ echo " Copying $src -> $dst "
28
+ cp -f " $src " " $dst "
29
+ else
30
+ echo " $dst already exists, skipping copy"
31
+ fi
32
+ }
33
+
22
34
function do_buildroot
23
35
{
24
- ASSERT git clone https://github.com/buildroot/buildroot -b 2024.11.1 --depth=1
25
- cp -f configs/buildroot.config buildroot/.config
26
- cp -f configs/busybox.config buildroot/busybox.config
36
+ if [ ! -d buildroot ]; then
37
+ echo " Cloning Buildroot..."
38
+ ASSERT git clone https://github.com/buildroot/buildroot -b 2024.11.1 --depth=1
39
+ else
40
+ echo " buildroot/ already exists, skipping clone"
41
+ fi
42
+
43
+ safe_copy configs/buildroot.config buildroot/.config
44
+ safe_copy configs/busybox.config buildroot/busybox.config
45
+ cp -f target/init buildroot/fs/cpio/init
46
+
27
47
# Otherwise, the error below raises:
28
48
# You seem to have the current working directory in your
29
49
# LD_LIBRARY_PATH environment variable. This doesn't work.
@@ -32,13 +52,28 @@ function do_buildroot
32
52
ASSERT make olddefconfig
33
53
ASSERT make $PARALLEL
34
54
popd
35
- cp -f buildroot/output/images/rootfs.cpio ./
55
+
56
+ if [[ $EXTERNAL_ROOT -eq 1 ]]; then
57
+ echo " Copying rootfs.cpio to rootfs_full.cpio (external root mode)"
58
+ cp -f buildroot/output/images/rootfs.cpio ./rootfs_full.cpio
59
+ ASSERT ./scripts/rootfs_ext4.sh
60
+ else
61
+ echo " Copying rootfs.cpio to rootfs.cpio (initramfs mode)"
62
+ cp -f buildroot/output/images/rootfs.cpio ./rootfs.cpio
63
+ fi
36
64
}
37
65
38
66
function do_linux
39
67
{
40
- ASSERT git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git -b linux-6.12.y --depth=1
41
- cp -f configs/linux.config linux/.config
68
+ if [ ! -d linux ]; then
69
+ echo " Cloning Linux kernel..."
70
+ ASSERT git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git -b linux-6.12.y --depth=1
71
+ else
72
+ echo " linux/ already exists, skipping clone"
73
+ fi
74
+
75
+ safe_copy configs/linux.config linux/.config
76
+
42
77
export PATH=" $PWD /buildroot/output/host/bin:$PATH "
43
78
export CROSS_COMPILE=riscv32-buildroot-linux-gnu-
44
79
export ARCH=riscv
@@ -49,5 +84,74 @@ function do_linux
49
84
popd
50
85
}
51
86
52
- do_buildroot && OK
53
- do_linux && OK
87
+ function show_help {
88
+ cat << EOF
89
+ Usage: $0 [--buildroot] [--linux] [--all] [--external-root] [--clean-build] [--help]
90
+
91
+ Options:
92
+ --buildroot Build Buildroot rootfs
93
+ --linux Build Linux kernel
94
+ --all Build both Buildroot and Linux
95
+ --external-root Use external rootfs instead of initramfs
96
+ --clean-build Remove entire buildroot/ and/or linux/ directories before build
97
+ --help Show this message
98
+ EOF
99
+ exit 1
100
+ }
101
+
102
+ BUILD_BUILDROOT=0
103
+ BUILD_LINUX=0
104
+ EXTERNAL_ROOT=0
105
+ CLEAN_BUILD=0
106
+
107
+ while [[ $# -gt 0 ]]; do
108
+ case " $1 " in
109
+ --buildroot)
110
+ BUILD_BUILDROOT=1
111
+ ;;
112
+ --linux)
113
+ BUILD_LINUX=1
114
+ ;;
115
+ --all)
116
+ BUILD_BUILDROOT=1
117
+ BUILD_LINUX=1
118
+ ;;
119
+ --external-root)
120
+ EXTERNAL_ROOT=1
121
+ ;;
122
+ --clean-build)
123
+ CLEAN_BUILD=1
124
+ ;;
125
+ --help|-h)
126
+ show_help
127
+ ;;
128
+ * )
129
+ echo " Unknown option: $1 "
130
+ show_help
131
+ ;;
132
+ esac
133
+ shift
134
+ done
135
+
136
+ if [[ $BUILD_BUILDROOT -eq 0 && $BUILD_LINUX -eq 0 ]]; then
137
+ echo " Error: No build target specified. Use --buildroot, --linux, or --all."
138
+ show_help
139
+ fi
140
+
141
+ if [[ $CLEAN_BUILD -eq 1 && $BUILD_BUILDROOT -eq 1 && -d buildroot ]]; then
142
+ echo " Removing buildroot/ for clean build..."
143
+ rm -rf buildroot
144
+ fi
145
+
146
+ if [[ $CLEAN_BUILD -eq 1 && $BUILD_LINUX -eq 1 && -d linux ]]; then
147
+ echo " Removing linux/ for clean build..."
148
+ rm -rf linux
149
+ fi
150
+
151
+ if [[ $BUILD_BUILDROOT -eq 1 ]]; then
152
+ do_buildroot && OK
153
+ fi
154
+
155
+ if [[ $BUILD_LINUX -eq 1 ]]; then
156
+ do_linux && OK
157
+ fi
0 commit comments