update for rootfs_usable

This commit is contained in:
wt
2024-12-05 16:56:58 +07:00
parent 156e149ecb
commit eb538f5ff4
19 changed files with 1536 additions and 25 deletions
+3
View File
@@ -17,3 +17,6 @@ distclean:
if [ -d downloads ]; then \
rm -rv downloads; \
fi
dropbear:
./scripts/build_image.sh dropbear
+1211
View File
File diff suppressed because it is too large Load Diff
+20
View File
@@ -0,0 +1,20 @@
awk
blkid
cat
fdisk
find
findfs
grep
hdparm
ls
mkdir
mount
mountpoint
pivot_root
printf
sed
sh
sleep
switch_root
umount
vi
+5
View File
@@ -0,0 +1,5 @@
LABEL default
kernel /boot/zImage
initrd /boot/initramfs.img
devicetreedir /boot/dtbs
append root=UUID=ROOTUUID rw rootwait console=${console} rootfstype=ext4 panic=10
+109
View File
@@ -0,0 +1,109 @@
#!/bin/sh
problem()
{
printf "Encountered a problem!\n\nDropping you to a shell.\n\n"
sh
}
no_device()
{
printf "The device %s, which is supposed to contain the\n" $1
printf "root file system, does not exist.\n"
printf "Please fix this problem and exit this shell.\n\n"
}
no_mount()
{
printf "Could not mount device %s\n" $1
printf "Sleeping forever. Please reboot and fix the kernel command line.\n\n"
printf "Maybe the device is formatted with an unsupported file system?\n\n"
printf "Or maybe filesystem type autodetection went wrong, in which case\n"
printf "you should add the rootfstype=... parameter to the kernel command line.\n\n"
printf "Available partitions:\n"
}
do_mount_root()
{
mkdir /.root
[ -n "$rootflags" ] && rootflags="$rootflags,"
rootflags="$rootflags$ro"
case "$root" in
/dev/* ) device=$root ;;
UUID=* ) eval $root; device="$(findfs UUID=$UUID)" ;;
PARTUUID=*) eval $root; device="/dev/disk/by-partuuid/$PARTUUID" ;;
LABEL=* ) eval $root; device="/dev/disk/by-label/$LABEL" ;;
"" ) echo "No root device specified." ; problem ;;
esac
while [ ! -b "$device" ] ; do
no_device $device
problem
done
if ! mount -n -t "$rootfstype" -o "$rootflags" "$device" /.root ; then
no_mount $device
cat /proc/partitions
while true ; do sleep 10000 ; done
else
echo "Successfully mounted device $root"
fi
}
init=/sbin/init
root=
rootdelay=
rootfstype=auto
ro="ro"
rootflags=
device=
resume=
noresume=false
mount -n -t devtmpfs devtmpfs /dev
mount -n -t proc proc /proc
mount -n -t sysfs sys /sys
mount -n -t tmpfs run /run
mkdir -p /dev/pts
#mountpoint -q proc || mount -t proc proc proc
#mountpoint -q sys || mount -t sysfs sys sys
#mknod /dev/null c 1 3
#if ! mountpoint -q dev
#then
# mount -t tmpfs -o size=64k,mode=0755 tmpfs dev
#mount -t tmpfs -o mode=1777 tmpfs tmp
#mkdir -p dev/pts
#mdev -s
#fi
read -r cmdline < /proc/cmdline
for param in $cmdline ; do
case $param in
init=* ) init=${param#init=} ;;
root=* ) root=${param#root=} ;;
rootdelay=* ) rootdelay=${param#rootdelay=} ;;
rootfstype=*) rootfstype=${param#rootfstype=} ;;
rootflags=* ) rootflags=${param#rootflags=} ;;
resume=* ) resume=${param#resume=} ;;
noresume ) noresume=true ;;
ro ) ro="ro" ;;
rw ) ro="rw" ;;
esac
done
if [ -n "$rootdelay" ]; then sleep "$rootdelay"; fi
do_mount_root
for i in dev proc sys; do
[ -d /.root/$i ] || mkdir /.root/$i
mount -o bind /$i /.root/$i
done
mount -t devpts none /.root/dev/pts
echo 0 > /proc/sys/kernel/printk
exec switch_root /.root "$init" "$@"
+6
View File
@@ -0,0 +1,6 @@
bin
dev
mnt
proc
root
sys
-1
View File
@@ -13,7 +13,6 @@ mnt
opt
proc
root
run
srv
sys
usr
+9 -2
View File
@@ -9,16 +9,23 @@
. ./scripts/rootfs.sh
. ./scripts/uboot.sh
. ./scripts/sdroot.sh
. ./scripts/dropbear.sh
case $1 in
build)
rootfs
sdroot
# rootfs
if [ "$image_usable_enable" = "true" ]; then
sdroot_usable
fi
# sdroot
# kernel_with_rootfs
# uboot
# busybox_rootfs
# kernel
;;
dropbear)
dropbear
;;
download)
download_sources
;;
+23 -3
View File
@@ -18,10 +18,30 @@ busybox_rootfs() {
cd busybox-1.36.1
cp -v $root/busybox/busybox-rootfs-config .config # &>> $fulllogfile
printf "$UGREEN** Configuring busybox\n$RESET"
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE oldconfig # &>> $fulllogfile
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- oldconfig # &>> $fulllogfile
check $? "Configure busybox all logs in .log"
printf "$UGREEN** Building busybox\n$RESET"
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE $makeflags # &>> $fulllogfile
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- $makeflags # &>> $fulllogfile
check $? "Build busybox all logs in .log"
}
#--------------------------------------------------
#--------------------------------------------------
#------------------ Building busybox for initramfs ----------------
busybox_initramfs() {
printf "$UGREEN** Building busybox for initramfs\n$RESET"
rm -r $build/busybox # &>> $fulllogfile
mkdir -p $build/busybox
cd $build/busybox
tar -xjf $root/downloads/busybox-1.36.1.tar.bz2
check $? "Extract busybox"
cd busybox-1.36.1
cp $root/busybox/busybox-initramfs-config .config
# export PATH=$PATH:/opt/toolchains/x86_64-buildroot-linux-uclibc-gcc/bin
printf "$UGREEN** Configuring busybox\n$RESET"
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- oldconfig # &>> $fulllogfile
check $? "Configure busybox all logs in .log"
printf "$UGREEN** Building busybox\n$RESET"
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- $makeflags # &>> $fulllogfile
check $? "Build busybox all logs in .log"
}
#------------------------------------------------------------------
+6 -3
View File
@@ -12,13 +12,16 @@ export distro_codename="zero_zero_one" # distro codename
export out=$root/out # output directory
export build=$root/build # build directory
export sourcesfilename=sources.txt # sources file for downloading
# initramfsfile=$root/initramfs/initramfs.txt # file to created directories for initramfs
# initramfspath=$build/initramfs # initramfs build directory
export initramfsfile=$root/initramfs/initramfs.txt # file to created directories for initramfs
export initramfspath=$build/initramfs # initramfs build directory
export rootfsfile=$root/rootfs/rootfs.txt # file to created directories for rootfs
export rootfspath=$build/rootfs # rootfs build directory
export fulllogfile=$root/.log/fulllog.log # file for full build logs
export makeflags=-j$(nproc) # makeflags
export CROSS_COMPILE=arm-buildroot-linux-uclibcgnueabihf-
export CROSS_COMPILE=arm-buildroot-linux-uclibcgnueabihf
export ARCH=arm
export sdroot=$out/sdroot
export ZLIB_ENABLE="true"
export DROPBEAR_ENABLE="true"
export image_usable_enable="true"
#--------------------------------------
+32
View File
@@ -0,0 +1,32 @@
#!/bin/sh
. ./scripts/colors.sh
. ./scripts/funcs.sh
. ./scripts/config.sh
. ./scripts/zlib.sh
dropbear() {
if [ ! -d $build/zlib ]; then
zlib
fi
printf "$GREEN** Building and installing dropbear\n$RESET"
mkdir $build/dropbear
cd $build/dropbear
tar -xvf $root/downloads/DROPBEAR_2024.86.tar.gz
check $? "Extract dropbear"
cd dropbear-DROPBEAR_2024.86
./configure \
--prefix=/usr \
--host=$CROSS_COMPILE \
--with-zlib=$build/rootfs
# CC=${CROSS_COMPILE}gcc ./configure --prefix=/usr --shared
check $? "Configure dropbear"
make $makeflags
check $? "Build dropbear"
make DESTDIR=$rootfspath install
check $? "Installing to rootfs dropbear"
rm -rv $rootfspath/usr/include $rootfspath/usr/share/man $rootfspath/usr/lib/{pkgconfig,libz.a}
${CROSS_COMPILE}-strip $rootfspath/usr/bin/*
mkdir -pv $build/rootfs/etc/dropbear
# check $? "Installing to rootfs zlib"
}
+36
View File
@@ -0,0 +1,36 @@
#!/bin/sh
. ./scripts/colors.sh
. ./scripts/funcs.sh
. ./scripts/config.sh
. ./scripts/busybox.sh
#------------------ Building initramfs.img ------------------------
initramfs() {
printf "$UGREEN** Building initramfs\n$RESET"
#--------- Creating directories and files -------------------
rm -r $initramfspath # &>> $fulllogfile >> $(tty)
mkdir -p $initramfspath
cd $initramfspath
mkdir -p $(cat $initramfsfile)
cp $root/initramfs/init.in $initramfspath/init
chmod 755 $initramfspath/init
#------------------------------------------------------------
#------------ Building initramfs busybox and copy to initramfs directory --------------------
busybox_initramfs
cp $build/busybox/busybox-1.36.1/busybox $initramfspath/bin
cd $initramfspath/bin
for i in $(cat $root/busybox/busybox_initramfs_list); do ln -s busybox $i; done
cd ..
#--------------------------------------------------------------------------------------------
#--------------------- Creating initramfs.img image ------------
find . | cpio -H newc -o | gzip > ../initramfs.img
check $? "Build initramfs.img image"
cd $root
#---------------------------------------------------------------
} # initramfs
#------------------------------------------------------------------
+6 -6
View File
@@ -15,12 +15,12 @@ kernel() {
check $? "Extract Linux Kernel"
cd linux-6.1.91
printf "$UGREEN** Configuring Linux Kernel\n$RESET"
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE mrproper # &>> $fulllogfile
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- mrproper # &>> $fulllogfile
cp -v $root/kernel/config-6.1.91 .config # &>> $fulllogfile
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE oldconfig # &>> $fulllogfile
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- oldconfig # &>> $fulllogfile
check $? "Configure Linux Kernel"
printf "$UGREEN** Building Linux Kernel\n$RESET"
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE $makeflags # &>> $fulllogfile
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- $makeflags # &>> $fulllogfile
check $? "Build Linux Kernel"
ls -lh arch/$ARCH/boot/zImage
} # kernel
@@ -30,10 +30,10 @@ kernel() {
kernel_modules() {
printf "$UGREEN** Building Linux Kernel modules\n$RESET"
cd $build/kernel/linux-6.1.91
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE modules # &>> fulllogfile
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- modules # &>> fulllogfile
check $? "Build Linux Kernel modules"
printf "$UGREEN** Installing Linux Kernel modules into rootfs path\n$RESET"
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE INSTALL_MOD_PATH=$rootfspath modules_install # &>> $fulllogfile
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- INSTALL_MOD_PATH=$rootfspath modules_install # &>> $fulllogfile
rm -v $rootfspath/usr/lib/modules/6.1.91/{source,build}
check $? "Install Linux Kernel modules"
} # kernel_modules
@@ -46,7 +46,7 @@ kernel_with_rootfs() {
mkdir -pv $out
fi
cd $build/kernel/linux-6.1.91
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE CONFIG_INITRAMFS_SOURCE=$rootfspath $makeflags # &>> fulllogfile
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- CONFIG_INITRAMFS_SOURCE=$rootfspath $makeflags # &>> fulllogfile
check $? "Build Linux Kernel with rootfs"
printf "$UGREEN** Installing Linux Kernel into images path\n$RESET"
# make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE INSTALL_MOD_PATH=$rootfspath modules_install # &>> $fulllogfile
+8 -1
View File
@@ -7,6 +7,7 @@
. ./scripts/uclibc.sh
. ./scripts/kernel.sh
. ./scripts/zlib.sh
. ./scripts/dropbear.sh
#----------- Building rootfs ----------------------
rootfs() {
@@ -19,6 +20,7 @@ rootfs() {
ln -sv usr/lib lib32 # &>> $fulllogfile
ln -sv usr/bin bin # &>> $fulllogfile
ln -sv usr/bin sbin # &>> $fulllogfile
ln -sv var/run run
cd usr
ln -sv bin sbin # &>> $fulllogfile
ln -sv lib lib32 # &>> $fulllogfile
@@ -36,7 +38,12 @@ rootfs() {
uclibc
kernel
kernel_modules
zlib
if [ "$ZLIB_ENABLE" = "true" ]; then
zlib
fi
if [ "$DROPBEAR_ENABLE" = "true" ]; then
dropbear
fi
chmod 640 $rootfspath/etc/shadow $rootfspath/etc/inittab
chmod 755 $rootfspath/etc/init.d/* $rootfspath/usr/share/udhcpc/default.script $rootfspath/init
+52
View File
@@ -5,10 +5,12 @@
. ./scripts/config.sh
. ./scripts/kernel.sh
. ./scripts/uboot.sh
. ./scripts/initramfs.sh
#--- sdroot ---
sdroot() {
printf "$GREEN** Generating sdroot\n$RESET"
rm -rv $sdroot
if [ ! -d $sdroot ]; then
mkdir -pv $sdroot
fi
@@ -50,3 +52,53 @@ sdroot() {
check $? "Generating sdcard.img"
}
#--------------
sdroot_usable() {
printf "$GREEN** Generating sdroot usable\n$RESET"
rm -rv $sdroot
if [ ! -d $sdroot ]; then
mkdir -pv $sdroot
fi
printf "$GREEN** Creating dirs\n$RESET"
mkdir -pv $sdroot/boot/{dtbs,extlinux}
check $? "Creating dirs"
printf "$GREEN** Copy extlinux.conf\n$RESET"
cp -v $root/extlinux/extlinux_usable.conf $sdroot/boot/extlinux/extlinux.conf
check $? "Copy extlinux.conf"
# kernel_with_rootfs
cp -rv $build/rootfs/* $sdroot/
initramfs
cp -v $build/initramfs.img $sdroot/boot
cp -v $build/kernel/linux-6.1.91/arch/$ARCH/boot/zImage $sdroot/boot
uboot
printf "$GREEN** Creating rootfs.ext4\n$RESET"
cd $out
rawsdrootsize=$(du -sh $sdroot)
echo $rawsdrootsize
sdrootsize=(${rawsdrootsize//M/ })
echo $sdrootsize
echo $(($sdrootsize+2))
dd if=/dev/zero of=rootfs.ext4 bs=1M count=$(($sdrootsize+3))
check $? "Write zero rootfs.ext4"
mkfs.ext4 rootfs.ext4
check $? "Creating ext4 filesystem"
rawuuid=$(echo $(blkid rootfs.ext4 | echo $(awk '{print $2}')))
echo $rawuuid
uuidIN=(${rawuuid//=/ })
uuid=${uuidIN[1]}
echo $uuid
cp -v $root/genimage/genimage.cfg .
check $? "Copy genimage.cfg"
sed -i "s/FILEUUID/$uuid/g" genimage.cfg
sed -i "s/ROOTUUID/$uuid/g" $sdroot/boot/extlinux/extlinux.conf
sed -i "s/sdcard.img/sdcard_usable.img/g" genimage.cfg
mkdir -v rootmnt
sudo mount -v rootfs.ext4 rootmnt
sudo cp -rv $sdroot/* rootmnt/
sudo umount -v rootfs.ext4
rm -rv rootmnt
mkdir input
mv -v ./{rootfs.ext4,u-boot-sunxi-with-spl.bin} input
genimage --config genimage.cfg
check $? "Generating sdcard_usable.img"
}
+2 -2
View File
@@ -13,9 +13,9 @@ uboot() {
check $? "Extract uboot"
cd u-boot-2024.10
# cp -rv $root/uclibc/config-1.0.50 .config
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE orangepi_pc_defconfig
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- orangepi_pc_defconfig
check $? "Configure uboot"
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE $makeflags # &>> $fulllogfile
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- $makeflags # &>> $fulllogfile
check $? "Build uboot"
cp -v u-boot-sunxi-with-spl.bin $out
cp -v arch/arm/dts/sun8i-h3-orangepi-pc.dtb $sdroot/boot/dtbs
+4 -4
View File
@@ -13,17 +13,17 @@ uclibc() {
check $? "Extract uclibc"
cd uClibc-ng-1.0.50
cp -rv $root/uclibc/config-1.0.50 .config
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE oldconfig
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- oldconfig
check $? "Configure uclibc"
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE $makeflags # &>> $fulllogfile
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- $makeflags # &>> $fulllogfile
check $? "Build uclibc"
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE DESTDIR=$rootfspath install # &>> $fulllogfile
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE- DESTDIR=$rootfspath install # &>> $fulllogfile
check $? "Install uclibc to rootfs"
cd $rootfspath
find -name \*.a -delete # &>> $fulllogfile
find -name \*.o -delete
rm -v $rootfspath/usr/lib/libc.so
${CROSS_COMPILE}strip --strip-unneeded $rootfspath/usr/lib/* $rootfspath/usr/bin/* # &>> $fulllogfile
${CROSS_COMPILE}-strip --strip-unneeded $rootfspath/usr/lib/* $rootfspath/usr/bin/* # &>> $fulllogfile
rm -rv $rootfspath/usr/include
cd $root
check $? "Build and install uclibc"
+2 -2
View File
@@ -11,12 +11,12 @@ zlib() {
tar -xvf $root/downloads/zlib-1.3.1.tar.gz
check $? "Extract zlib"
cd zlib-1.3.1
CC=${CROSS_COMPILE}gcc ./configure --prefix=/usr --shared
CC=${CROSS_COMPILE}-gcc ./configure --prefix=/usr --shared
check $? "Configure zlib"
make $makeflags
check $? "Build zlib"
make DESTDIR=$rootfspath install
rm -rv $rootfspath/usr/include $rootfspath/usr/share/man $rootfspath/usr/lib/{pkgconfig,libz.a}
${CROSS_COMPILE}strip $rootfspath/usr/lib/libz.so.1.3.1
${CROSS_COMPILE}-strip $rootfspath/usr/lib/libz.so.1.3.1
check $? "Installing to rootfs zlib"
}
+2 -1
View File
@@ -3,4 +3,5 @@ https://busybox.net/downloads/busybox-1.36.1.tar.bz2
https://downloads.uclibc-ng.org/releases/1.0.50/uClibc-ng-1.0.50.tar.xz
https://github.com/TolaMironcenko/initscripts/archive/refs/tags/0.0.1-orangepi-pc/initscripts-0.0.1-orangepi-pc.tar.gz
https://github.com/u-boot/u-boot/archive/refs/tags/v2024.10/u-boot-v2024.10.tar.gz
https://www.zlib.net/zlib-1.3.1.tar.gz
https://www.zlib.net/zlib-1.3.1.tar.gz
https://github.com/mkj/dropbear/archive/refs/tags/DROPBEAR_2024.86.tar.gz