Add initramfs build. Some optimization.

This commit is contained in:
andreili 2025-06-21 11:28:43 +02:00
parent 4190142bcc
commit 4fc551298f
20 changed files with 4568 additions and 25 deletions

View File

@ -4,6 +4,7 @@ import argparse, json
from scripts import *
os = OS()
#os.umount_safe()
os_actions = ",".join(os.actions_list())
parser = argparse.ArgumentParser()
@ -24,6 +25,10 @@ os.set_board(target_board)
if (args.sync):
target_board.sync()
elif (args.target != ""):
if (args.target == "initramfs"):
init = Initramfs()
init.build(os)
else:
target_board.build(args.target)
if (args.os_act != ""):

1236
cfg/busybox_config Normal file

File diff suppressed because it is too large Load Diff

2230
cfg/opi_zero2/uboot_v2024.01 Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,90 @@
{
"build":
[
"initramfs", "uboot", "kernel"
],
"variables":
[
"CROSS_C:aarch64-linux-gnu-",
"ATF_PLATFORM:sun50i_h616",
"ARCH:aarch64"
],
"targets":
[
{
"parent": "atf",
"version": "lts-v2.12.1",
"version_type": "tag",
"patch_dir": "atf/sunxi64",
"target": [ "bl31" ],
"makeopts": "CROSS_COMPILE=%{CROSS_C}% PLAT=%{ATF_PLATFORM}% DEBUG=0",
"artifacts":
[
{
"file": "build/%{ATF_PLATFORM}%/release/bl31.bin",
"store_type": "temp"
}
]
},
{
"parent": "uboot",
"version": "v2024.01",
"version_type": "tag",
"patch_dir": "uboot/sunxi",
"deps":
[
"atf"
],
"artifacts":
[
{
"file": "u-boot-sunxi-with-spl.bin",
"store_type": "dd",
"img_offset": 8
}
],
"target": [ "" ],
"config_def": "orangepi_zero2_defconfig",
"makeopts": "CROSS_COMPILE=%{CROSS_C}% BL31=%{out_dir}%/bl31.bin"
},
{
"parent": "kernel",
"version": "v6.14-rc7",
"version_type": "tag",
"patch_dir": "kernel/sunxi-6.14",
"target": [ "Image", "modules", "dtbs" ],
"artifacts":
[
{
"file": "arch/arm64/boot/Image",
"store_type": "boot"
},
{
"file": "arch/arm64/boot/dts/allwinner/sun50i-h616-bigtreetech-cb1*.dtb",
"store_type": "boot",
"subdir": "dts/allwiner"
},
{
"file": "arch/arm64/boot/dts/allwinner/overlay/sun50i-h616*.dtbo",
"store_type": "boot",
"subdir": "dts/allwiner/overlay"
}
],
"makeopts": "CROSS_COMPILE=%{CROSS_C}% ARCH=arm64"
},
{
"parent": "buildroot",
"version": "@",
"version_type": "head",
"patch_dir": "buildroot/sunxi",
"target": [],
"artifacts": []
}
],
"install":
{
"target": "image",
"block_size": "1k",
"image_size": "2g"
}
}

View File

@ -29,5 +29,13 @@
"config": true,
"config_target": "menuconfig"
}
},
{
"busybox":
{
"url": "https://git.busybox.net/busybox",
"config": true,
"config_target": "menuconfig"
}
}
]

191
files/initramfs/init Normal file
View File

@ -0,0 +1,191 @@
#!/bin/busybox sh
. /etc/init.def
. /etc/init.script
run mount -t sysfs sysfs /sys -o noexec,nosuid,nodev >/dev/null
run mount -t devtmpfs -o exec,nosuid,mode=0755,size=10M udev /dev
run mkdir -m 0755 /dev/pts
run mount -t devpts -o gid=5,mode=0620 devpts /dev/pts
run mkdir -m 1777 /dev/shm
run mount -t tmpfs -o mode=1777,nosuid,nodev,strictatime tmpfs /dev/shm
mount -t proc -o noexec,nosuid,nodev proc /proc >/dev/null 2>&1
mount -o remount,rw / >/dev/null 2>&1
mount -t tmpfs -o rw,nosuid,nodev,relatime,mode=755 none /run 2>&1
mkdir /run/initramfs
if [ ! -s /etc/ld.so.cache ]
then
# Looks like we were unable to run ldconfig during initramfs generation
hash ldconfig >/dev/null 2>&1 && run ldconfig
fi
# Set up symlinks
run busybox --install -s
# Handle kernel command-line parameters
CMDLINE=$(cat /proc/cmdline 2>/dev/null)
for x in ${CMDLINE}
do
case "${x}" in
subdir=*)
SUBDIR=${x#*=}
;;
real_init=*)
REAL_INIT=${x#*=}
;;
init=*)
FAKE_INIT=${x#*=}
;;
quiet|quiet_genkernel)
QUIET=1
;;
# Scan delay options
scandelay=*)
SDELAY=${x#*=}
;;
scandelay)
SDELAY=3
;;
rootdelay=*|rootwait=*)
ROOTDELAY=${x#*=}
;;
rootdelay|rootwait)
ROOTDELAY=5
;;
esac
done
if ! is_quiet
then
# Prevent superfluous printks from being printed to the console
echo ${CONSOLE_LOGLEVEL} > /proc/sys/kernel/printk
fi
NEW_ROOT='/newroot'
CDROOT_PATH="/mnt/cdrom"
RW_MNT="/mnt/rw_part"
STATIC="/mnt/livecd"
OVERLAY="/mnt/overlay"
LOOP="/root.sqh"
LOOPTYPE="squashfs"
good_msg "Initial ramdisk script. Linux kernel ${KV}"
log_msg "COMMAND: 'echo "" > /proc/sys/kernel/hotplug'"
echo "" > /proc/sys/kernel/hotplug
#run mkdir -p "${NEW_ROOT}"
CHROOT="${NEW_ROOT}"
run mount -n -t tmpfs tmpfs ${NEW_ROOT}
DEVICES=$(devicelist)
run findmediamount "cdrom" "/livecd" "REAL_ROOT" "${CDROOT_PATH}" "${DEVICES}" || run_emergency_shell
run findmediamount "rw_part" "/rw_part" "RW_ROOT" "${RW_MNT}" "${DEVICES}" || run_emergency_shell
run mount -o remount,ro "${CDROOT_PATH}"
#sh
CHROOT=${NEW_ROOT}
run cd "${CHROOT}"
good_msg 'Mounting squashfs filesystem'
upperdir="${RW_MNT}/.upper"
workdir="${RW_MNT}/.work"
for i in "${RW_MNT}" "${STATIC}" "${OVERLAY}" "${upperdir}" "${workdir}"
do
[ ! -d "${i}" ] && run mkdir -p "${i}"
done
run mount -t squashfs -o loop,ro "${CDROOT_PATH}/${LOOP}" "${STATIC}"
#if [ -d ${CDROOT_PATH}/modules ]
#then
# warn_msg "Adding all modules in ${CDROOT_PATH}/modules"
# for module in "${CDROOT_PATH}/modules/"*.lzm; do
# mod=${module##*/}
# mod=${mod//-/_}
# mod=${mod%.*}
# if [ ! -d "${OVERLAY}/.${mod}" ]
# then
# run mkdir -p "${OVERLAY}/.${mod}" || return
# fi
# run mount -o loop,ro "${module}" "${OVERLAY}/.${mod}"
# mod_path="${mod_path}:${OVERLAY}/.${mod}"
# # Assign variable with paths to modules mount point
# # TODO: Stop using eval
# eval ${mod}="${OVERLAY}/.${mod}"
# mods="${mods} ${mod}"
# done
#fi
run mount -t overlay overlay -o lowerdir="${STATIC}${mod_path}",upperdir="${upperdir}",workdir="${workdir}" "${NEW_ROOT}"
#[ ! -d "${NEW_ROOT}${RW_MNT}" ] && mkdir -p "${NEW_ROOT}${RW_MNT}"
#[ ! -d "${NEW_ROOT}${STATIC}" ] && mkdir -p "${NEW_ROOT}${STATIC}"
#echo "overlay / overlay defaults 0 0" > "${NEW_ROOT}"/etc/fstab
#run mkdir -p "${NEW_ROOT}${OVERLAY}"
#run chmod 755 "${NEW_ROOT}${OVERLAY}"
#run mount --bind "${OVERLAY}" "${NEW_ROOT}${OVERLAY}"
#run mount --bind "${STATIC}" "${NEW_ROOT}${STATIC}"
#if [ -n "${mods}" ]
#then
# for i in ${mods}
# do
# run mount --bind "${OVERLAY}/.${i}" "${NEW_ROOT}/${OVERLAY}/.${i}"
# done
#fi
#[ ! -d "${NEW_ROOT}${CDROOT_PATH}" ] && mkdir -p "${NEW_ROOT}${CDROOT_PATH}"
#run mount --bind "${CDROOT_PATH}" "${NEW_ROOT}${CDROOT_PATH}"
#run mount --bind "${RW_MNT}" "${NEW_ROOT}${RW_MNT}"
run mount --move "${CDROOT_PATH}" "${NEW_ROOT}${CDROOT_PATH}"
run mount --move "${RW_MNT}" "${NEW_ROOT}${RW_MNT}"
run mount --move "${STATIC}" "${NEW_ROOT}${STATIC}"
#for m in ${MODULES}; do
# run insmod "${NEW_ROOT}${m}"
#done
# Let Init scripts know that we booted from CD
export CDBOOT
CDBOOT=1
run udevadm settle --timeout=120
run udevadm control --exit
init=${REAL_INIT:-/sbin/init}
# create a file for correct shutdown process
INIF="/run/initramfs"
SH_FILE="${INIF}/shutdown"
#run mkdir "${INIF}/bin"
#run mount --bind /bin ${INIF}/bin
run touch ${SH_FILE}
echo "#!/bin/sh" >> ${SH_FILE}
#echo "sh" >> ${SH_FILE}
#echo "umount ${NEW_ROOT}${INIF}/bin" >> ${SH_FILE}
#echo "umount ${NEW_ROOT}${INIF}" >> ${SH_FILE}
echo "mount -o remount,ro ${NEW_ROOT}${CDROOT_PATH}" >> ${SH_FILE}
echo "mount -o remount,ro ${NEW_ROOT}${RW_MNT}" >> ${SH_FILE}
echo "sync" >> ${SH_FILE}
echo "umount -l ${NEW_ROOT}${RW_MNT}" >> ${SH_FILE}
echo "umount -l ${NEW_ROOT}${CDROOT_PATH}" >> ${SH_FILE}
echo "umount -l ${NEW_ROOT}${STATIC}" >> ${SH_FILE}
echo "umount -l ${NEW_ROOT}" >> ${SH_FILE}
#run mkdir ${NEW_ROOT}${INIF}
#run mount --rbind ${INIF} ${NEW_ROOT}${INIF}
while true
do
if ! mountpoint "${CHROOT}" 1>/dev/null 2>&1
then
bad_msg "${CHROOT} is not a mountpoint; Was root device (${REAL_ROOT}) not mounted?"
elif ! chroot "${CHROOT}" /usr/bin/test -x /${init#/} 1>/dev/null 2>&1
then
mounted_root_device=$(mountpoint -n /newroot 2>/dev/null | awk '{ print $1 }')
bad_msg "init (${init}) not found in mounted root device (${mounted_root_device})!"
else
break
fi
run_emergency_shell
done
good_msg "Restoring console log level (${CONSOLE_LOGLEVEL}) ..."
echo ${CONSOLE_LOGLEVEL} > /proc/sys/kernel/printk && log_msg "COMMAND: 'echo \"${CONSOLE_LOGLEVEL}\" > /proc/sys/kernel/printk'"
good_msg "Switching to real root: switch_root ${CHROOT} ${init} ${init_opts}"
#sh
exec switch_root "${CHROOT}" "${init}" ${init_opts}
exit 1

36
files/initramfs/init.def Normal file
View File

@ -0,0 +1,36 @@
BACK_UP="\033[1K\033[0G"
WARN="\033[33;1m"
BAD="\033[31;1m"
BOLD="\033[1m"
GOOD="\033[32;1m"
# Reset fb color mode
RESET="]R"
# ANSI COLORS
# Erase to end of line
CRE="
"
# Clear and reset Screen
CLEAR="c"
# Normal color
NORMAL=""
# RED: Failure or error message
RED=""
# GREEN: Success message
GREEN=""
# YELLOW: Descriptions
YELLOW=""
# BLUE: System mesages
BLUE=""
# MAGENTA: Found devices or drivers
MAGENTA=""
# CYAN: Questions
CYAN=""
# BOLD WHITE: Hint
WHITE=""
QUIET=0
CONSOLE_LOGLEVEL=3
LOG_ENABLED=1
INIT_LOG="/run/initramfs/init.log"
KV=$(uname -r)

178
files/initramfs/init.script Normal file
View File

@ -0,0 +1,178 @@
is_quiet() {
return ${QUIET}
}
log_msg() {
if [ ! -f "${INIT_LOG}" ]
then
touch "${INIT_LOG}" 2>/dev/null || return
fi
local msg=${1}
LANG=C echo "] ${msg}" | sed \
-e "s,[^[:print:]],,g" \
-e 's,\(\\033\)\?\[[0-9;]\+m,,g' \
| ts '[ %Y-%m-%d %H:%M:%.S' >> "${INIT_LOG}"
}
is_true() {
case "${1}" in
1)
return 0
;;
[Tt][Rr][Uu][Ee])
return 0
;;
[Tt])
return 0
;;
[Yy][Ee][Ss])
return 0
;;
[Yy])
return 0
;;
esac
return 1
}
good_msg() {
local msg_string=${1}
msg_string="${msg_string:-...}"
log_msg "[OK] ${msg_string}"
is_true "${2-${QUIET}}" || printf "%b\n" "${GOOD}>>${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
}
good_msg_n() {
local msg_string=${1}
msg_string="${msg_string:-...}"
log_msg "[OK] ${msg_string}"
is_true "${2-${QUIET}}" || printf "%b" "${GOOD}>>${NORMAL}${BOLD} ${msg_string}"
}
bad_msg() {
local msg_string=${1}
msg_string="${msg_string:-...}"
log_msg "[!!] ${msg_string}"
splash 'verbose' >/dev/null &
printf "%b\n" "${BAD}!!${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
}
warn_msg() {
local msg_string=${1}
msg_string="${msg_string:-...}"
log_msg "[**] ${msg_string}"
is_true "${2-${QUIET}}" || printf "%b\n" "${WARN}**${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
}
warn_msg_n() {
local msg_string=${1}
msg_string="${msg_string:-...}"
log_msg "[**] ${msg_string}"
is_true "${2-${QUIET}}" || printf "%b" "${WARN}**${NORMAL}${BOLD} ${msg_string}"
}
str_starts() {
if [ "${1#"${2}"*}" != "${1}" ]
then
return 0
fi
return 1
}
run() {
local retval
if "$@"; then
retval=$?
log_msg "Executed: '$*'"
else
retval=$?
log_msg "Failed (${retval}): '$*'"
fi
return ${retval}
}
devicelist() {
# Locate the cdrom device with our media on it.
# USB Keychain/Storage
DEVICES="${DEVICES} /dev/sd*"
# IDE devices
DEVICES="${DEVICES} /dev/hd*"
# USB using the USB Block Driver
DEVICES="${DEVICES} /dev/ubd* /dev/ubd/*"
# iSeries devices
DEVICES="${DEVICES} /dev/iseries/vcd*"
# builtin mmc/sd card reader devices
DEVICES="${DEVICES} /dev/mmcblk* /dev/mmcblk*/*"
# fallback scanning, this might scan something twice, but it's better than
# failing to boot.
[ -e /proc/partitions ] && DEVICES="${DEVICES} $(awk '/([0-9]+[[:space:]]+)/{print "/dev/" $4}' /proc/partitions)"
echo ${DEVICES}
}
determine_fs() {
local _dev="${1}"
local _orig="${2:-auto}"
local _fs line
_fs=$(udevadm info --query=env --name="$_dev" 2>/dev/null | \
while read line || [ -n "${line}" ]
do
if str_starts ${line} "ID_FS_TYPE="
then
echo ${line#ID_FS_TYPE=}
break
fi
done
)
_fs=${_fs:-auto}
if [ "${_fs}" = "auto" ]
then
_fs="${_orig}"
fi
echo "${_fs}"
}
findmediamount() {
# $1 = mount dir name / media name
# $2 = recognition file
# $3 = variable to have the device path
# $4 = actual mount dir path (full path)
# args remaining are possible devices
local media=$1 recon=$2 vrbl=$3 mntdir=$4
shift 4
good_msg "Looking for the ${media}"
if [ "$#" -gt "0" ]
then
[ ! -d "${mntdir}" ] && mkdir -p ${mntdir} >/dev/null 2>&1
mntcddir="${mntdir}"
for x in $*
do
# Check for a block device to mount
if [ -b "${x}" ]
then
good_msg "Attempting to mount media: ${x}"
CDROOT_TYPE=$(determine_fs "${x}" "${CDROOT_TYPE}")
run mount -t ${CDROOT_TYPE} -o defaults ${x} ${mntcddir} >/dev/null 2>&1
if [ $? -eq 0 ]
then
# Check for the media
if [ -f "${mntdir}/${recon}" ]
then
#set REAL_ROOT, CRYPT_ROOT_KEYDEV or whatever ${vrbl} is
eval ${vrbl}'='"${x}"
good_msg "Run FS check on ${x}..."
run umount ${mntcddir}
run e2fsck -p ${x}
run mount -t ${CDROOT_TYPE} -o defaults ${x} ${mntcddir} >/dev/null 2>&1
good_msg "Media found on ${x}"
break
else
run umount ${mntcddir}
fi
fi
fi
done
fi
eval local result='$'${vrbl}
[ -n "${result}" ] || bad_msg "Media not found"
}

View File

@ -0,0 +1,67 @@
# directory structure
dir /proc 755 0 0
dir /usr 755 0 0
dir /bin 755 0 0
dir /sys 755 0 0
dir /var 755 0 0
dir /lib 755 0 0
dir /sbin 755 0 0
dir /mnt 755 0 0
dir /etc 755 0 0
dir /root 700 0 0
dir /dev 755 0 0
dir /run 755 0 0
dir /tmp 755 0 0
dir /dev/mapper 755 0 0
dir /etc/udev 755 0 0
dir /mnt/cdrom 755 0 0
dir /mnt/rw_part 755 0 0
dir /mnt/livecd 755 0 0
dir /mnt/overlay 755 0 0
dir /newroot 755 0 0
dir /newroot/mnt 755 0 0
dir /newroot/mnt/cdrom 755 0 0
dir /newroot/mnt/rw_part 755 0 0
dir /newroot/mnt/livecd 755 0 0
dir /newroot/mnt/overlay 755 0 0
dir /newroot/proc 755 0 0
dir /newroot/tmp 755 0 0
dir /newroot/dev 755 0 0
dir /newroot/run 755 0 0
dir /newroot/sys 755 0 0
nod /newroot/dev/null 666 0 0 c 1 3
nod /newroot/dev/zero 666 0 0 c 1 5
nod /newroot/dev/console 600 0 0 c 5 1
nod /newroot/dev/tty0 620 0 0 c 4 0
nod /newroot/dev/ttyS0 660 0 0 c 4 64
nod /newroot/dev/tty1 600 0 0 c 4 1
#symlinks to easy script starts
slink /bin/[ busybox 755 0 0
slink /bin/ash busybox 755 0 0
slink /bin/cat busybox 755 0 0
slink /bin/chmod busybox 755 0 0
slink /bin/cut busybox 755 0 0
slink /bin/echo busybox 755 0 0
slink /bin/mkdir busybox 755 0 0
slink /bin/mknod busybox 755 0 0
slink /bin/mount busybox 755 0 0
slink /bin/sh busybox 755 0 0
slink /bin/touch busybox 755 0 0
slink /bin/uname busybox 755 0 0
slink /bin/sed busybox 755 0 0
slink /bin/ts busybox 755 0 0
slink /lib64 /lib 755 0 0
slink /dev/stderr /proc/self/fd/2 777 0 0
slink /dev/stdin /proc/self/fd/0 777 0 0
slink /dev/std/out /proc/self/fd/1 777 0 0
file /bin/busybox build/common/busybox 755 0 0
file /bin/udevadm build/common/udevadm 755 0 0
file /bin/e2fsck build/common/e2fsck 755 0 0
file /bin/resize2fs build/common/resize2fs 755 0 0
file /etc/init.def files/initramfs/init.def 755 0 0
file /etc/init.script files/initramfs/init.script 755 0 0
file /init files/initramfs/init 755 0 0
#file /etc/udev/hwdb.bin ../CB1/root/boot/init_last/etc/udev/hwdb.bin 755 0 0

View File

@ -0,0 +1,53 @@
http://lists.busybox.net/pipermail/busybox/2024-March/090678.html
https://bugs.gentoo.org/926872
Linux v6.8-rc1 removed the definitions related to CBQ making tc fail to
build. Add some #ifdefs to handle this missing support.
--- a/networking/tc.c
+++ b/networking/tc.c
@@ -231,6 +231,13 @@ static int cbq_parse_opt(int argc, char **argv, struct nlmsghdr *n)
return 0;
}
#endif
+
+#ifndef TCA_CBQ_MAX
+/*
+ * Linux v6.8-rc1~131^2~60^2^2 removed the uapi definitions for CBQ.
+ * See <A HREF="https://git.kernel.org/linus/33241dca48626">https://git.kernel.org/linus/33241dca48626</A>
+ */
+#else
static int cbq_print_opt(struct rtattr *opt)
{
struct rtattr *tb[TCA_CBQ_MAX+1];
@@ -322,6 +329,7 @@ static int cbq_print_opt(struct rtattr *opt)
done:
return 0;
}
+#endif
static FAST_FUNC int print_qdisc(
const struct sockaddr_nl *who UNUSED_PARAM,
@@ -372,8 +380,10 @@ static FAST_FUNC int print_qdisc(
int qqq = index_in_strings(_q_, name);
if (qqq == 0) { /* pfifo_fast aka prio */
prio_print_opt(tb[TCA_OPTIONS]);
+#ifdef TCA_CBQ_MAX
} else if (qqq == 1) { /* class based queuing */
cbq_print_opt(tb[TCA_OPTIONS]);
+#endif
} else {
/* don't know how to print options for this qdisc */
printf(&quot;(options for %s)&quot;, name);
@@ -442,9 +452,11 @@ static FAST_FUNC int print_class(
int qqq = index_in_strings(_q_, name);
if (qqq == 0) { /* pfifo_fast aka prio */
/* nothing. */ /*prio_print_opt(tb[TCA_OPTIONS]);*/
+#ifdef TCA_CBQ_MAX
} else if (qqq == 1) { /* class based queuing */
/* cbq_print_copt() is identical to cbq_print_opt(). */
cbq_print_opt(tb[TCA_OPTIONS]);
+#endif
} else {
/* don't know how to print options for this class */
printf(&quot;(options for %s)&quot;, name);

View File

@ -0,0 +1,43 @@
https://git.alpinelinux.org/aports/plain/main/busybox/0025-Hackfix-to-disable-HW-acceleration-for-MD5-SHA1-on-x.patch
https://bugs.gentoo.org/933771
From 3ead51e53687e94a51beb793661363df27b00814 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
Date: Thu, 5 Jan 2023 15:47:55 +0100
Subject: [PATCH] Hackfix to disable HW acceleration for MD5/SHA1 on x86
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This causes a direct segfault with musl libc.
See: http://lists.busybox.net/pipermail/busybox/2023-January/090078.html
--- a/libbb/hash_md5_sha.c
+++ b/libbb/hash_md5_sha.c
@@ -14,7 +14,7 @@
#define NEED_SHA512 (ENABLE_SHA512SUM || ENABLE_USE_BB_CRYPT_SHA)
#if ENABLE_SHA1_HWACCEL || ENABLE_SHA256_HWACCEL
-# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+# if defined(__GNUC__) && defined(__x86_64__)
static void cpuid(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx)
{
asm ("cpuid"
@@ -1173,7 +1173,7 @@ void FAST_FUNC sha1_begin(sha1_ctx_t *ctx)
ctx->total64 = 0;
ctx->process_block = sha1_process_block64;
#if ENABLE_SHA1_HWACCEL
-# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+# if defined(__GNUC__) && defined(__x86_64__)
{
if (!shaNI) {
unsigned eax = 7, ebx = ebx, ecx = 0, edx = edx;
@@ -1227,7 +1227,7 @@ void FAST_FUNC sha256_begin(sha256_ctx_t *ctx)
/*ctx->total64 = 0; - done by prepending two 32-bit zeros to init256 */
ctx->process_block = sha256_process_block64;
#if ENABLE_SHA256_HWACCEL
-# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+# if defined(__GNUC__) && defined(__x86_64__)
{
if (!shaNI) {
unsigned eax = 7, ebx = ebx, ecx = 0, edx = edx;

259
patch/eudev/static.patch Normal file
View File

@ -0,0 +1,259 @@
diff --git a/Makefile.am b/Makefile.am
index 0d463798e..8e232f42b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,8 +5,7 @@ SUBDIRS = \
if ENABLE_PROGRAMS
SUBDIRS += \
- rules \
- test
+ rules
endif
if ENABLE_MANPAGES
diff --git a/configure.ac b/configure.ac
index 0d9a135bc..63bf800b5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -252,7 +252,7 @@ AC_ARG_ENABLE(kmod, AS_HELP_STRING([--disable-kmod], [disable loadable modules s
if test "x$enable_kmod" != "xno"; then
PKG_CHECK_EXISTS([ libkmod ], have_kmod=yes, have_kmod=no)
if test "x$have_kmod" = "xyes"; then
- PKG_CHECK_MODULES(KMOD, [ libkmod >= 15 ],
+ PKG_CHECK_MODULES_STATIC(KMOD, [ libkmod >= 15 ],
[AC_DEFINE(HAVE_KMOD, 1, [Define if kmod is available])],
AC_MSG_ERROR([*** kmod version >= 15 not found]))
fi
diff --git a/src/ata_id/Makefile.am b/src/ata_id/Makefile.am
index 01acbbafe..d84562549 100644
--- a/src/ata_id/Makefile.am
+++ b/src/ata_id/Makefile.am
@@ -11,6 +11,8 @@ udevlibexec_PROGRAMS = \
ata_id_SOURCES = \
ata_id.c
+ata_id_LDFLAGS = -all-static
+
ata_id_LDADD = \
$(top_builddir)/src/libudev/libudev-private.la \
$(top_builddir)/src/udev/libudev-core.la
diff --git a/src/cdrom_id/Makefile.am b/src/cdrom_id/Makefile.am
index 488edcadb..faf1d5665 100644
--- a/src/cdrom_id/Makefile.am
+++ b/src/cdrom_id/Makefile.am
@@ -10,6 +10,8 @@ udevlibexec_PROGRAMS = \
cdrom_id_SOURCES = \
cdrom_id.c
+cdrom_id_LDFLAGS = -all-static
+
cdrom_id_LDADD = \
$(top_builddir)/src/libudev/libudev-private.la \
$(top_builddir)/src/udev/libudev-core.la
diff --git a/src/collect/Makefile.am b/src/collect/Makefile.am
index a531a2d88..ccea1ff66 100644
--- a/src/collect/Makefile.am
+++ b/src/collect/Makefile.am
@@ -11,6 +11,8 @@ udevlibexec_PROGRAMS = \
collect_SOURCES = \
collect.c
+collect_LDFLAGS = -all-static
+
collect_LDADD = \
$(top_builddir)/src/libudev/libudev-private.la \
$(top_builddir)/src/udev/libudev-core.la
diff --git a/src/dmi_memory_id/Makefile.am b/src/dmi_memory_id/Makefile.am
index 69605cc6d..417887dd3 100644
--- a/src/dmi_memory_id/Makefile.am
+++ b/src/dmi_memory_id/Makefile.am
@@ -11,6 +11,8 @@ udevlibexec_PROGRAMS = \
dmi_memory_id_SOURCES = \
dmi_memory_id.c
+dmi_memory_id_LDFLAGS = -all-static
+
dmi_memory_id_LDADD = \
$(top_builddir)/src/libudev/libudev-private.la \
$(top_builddir)/src/udev/libudev-core.la
diff --git a/src/fido_id/Makefile.am b/src/fido_id/Makefile.am
index 255c8393b..c615121f1 100644
--- a/src/fido_id/Makefile.am
+++ b/src/fido_id/Makefile.am
@@ -13,6 +13,8 @@ fido_id_SOURCES =\
fido_id_desc.c \
fido_id_desc.h
+fido_id_LDFLAGS = -all-static
+
fido_id_LDADD = \
$(top_builddir)/src/libudev/libudev-private.la \
$(top_builddir)/src/udev/libudev-core.la
diff --git a/src/mtd_probe/Makefile.am b/src/mtd_probe/Makefile.am
index 2ee2f30dc..ea400283a 100644
--- a/src/mtd_probe/Makefile.am
+++ b/src/mtd_probe/Makefile.am
@@ -6,6 +6,8 @@ AM_CPPFLAGS = \
udevlibexec_PROGRAMS = \
mtd_probe
+mtd_probe_LDFLAGS = -all-static
+
mtd_probe_SOURCES = \
mtd_probe.c \
mtd_probe.h \
diff --git a/src/scsi_id/Makefile.am b/src/scsi_id/Makefile.am
index c4dad4736..398eac858 100644
--- a/src/scsi_id/Makefile.am
+++ b/src/scsi_id/Makefile.am
@@ -14,6 +14,8 @@ scsi_id_SOURCES =\
scsi.h \
scsi_id.h
+scsi_id_LDFLAGS = -all-static
+
scsi_id_LDADD = \
$(top_builddir)/src/libudev/libudev-private.la \
$(top_builddir)/src/udev/libudev-core.la
diff --git a/src/shared/path-util.c b/src/shared/path-util.c
index 63e3423f3..33bbc58f9 100644
--- a/src/shared/path-util.c
+++ b/src/shared/path-util.c
@@ -116,6 +116,10 @@ char *path_make_absolute_cwd(const char *p) {
return strjoin(cwd, "/", p, NULL);
}
+static char *_strappend(const char *s, const char *suffix) {
+ return strnappend(s, suffix, suffix ? strlen(suffix) : 0);
+}
+
char **path_strv_resolve(char **l, const char *prefix) {
char **s;
unsigned k = 0;
@@ -139,7 +143,7 @@ char **path_strv_resolve(char **l, const char *prefix) {
if (prefix) {
orig = *s;
- t = strappend(prefix, orig);
+ t = _strappend(prefix, orig);
if (!t) {
enomem = true;
continue;
diff --git a/src/shared/strv.c b/src/shared/strv.c
index 1f7313475..acc3fff65 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -26,6 +26,7 @@
#include "util.h"
#include "strv.h"
+#if 0
void strv_clear(char **l) {
char **k;
@@ -193,20 +194,9 @@ int strv_extend(char ***l, const char *value) {
return strv_consume(l, v);
}
+#endif
-char **strv_uniq(char **l) {
- char **i;
-
- /* Drops duplicate entries. The first identical string will be
- * kept, the others dropped */
-
- STRV_FOREACH(i, l)
- strv_remove(i+1, *i);
-
- return l;
-}
-
-char **strv_remove(char **l, const char *s) {
+static char ** _strv_remove(char **l, const char *s) {
char **f, **t;
if (!l)
@@ -226,3 +216,15 @@ char **strv_remove(char **l, const char *s) {
*t = NULL;
return l;
}
+
+char **strv_uniq(char **l) {
+ char **i;
+
+ /* Drops duplicate entries. The first identical string will be
+ * kept, the others dropped */
+
+ STRV_FOREACH(i, l)
+ _strv_remove(i+1, *i);
+
+ return l;
+}
diff --git a/src/shared/util.c b/src/shared/util.c
index 8b999f27d..1bffd949a 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -372,6 +372,7 @@ static size_t strcspn_escaped(const char *s, const char *reject) {
return n - escaped;
}
+#if 0
/* Split a string into words. */
const char* split(const char **state, size_t *l, const char *separator, bool quoted) {
const char *current;
@@ -415,6 +416,7 @@ const char* split(const char **state, size_t *l, const char *separator, bool quo
return current;
}
+#endif
char *truncate_nl(char *s) {
assert(s);
@@ -454,9 +456,11 @@ char *strnappend(const char *s, const char *suffix, size_t b) {
return r;
}
+#if 0
char *strappend(const char *s, const char *suffix) {
return strnappend(s, suffix, suffix ? strlen(suffix) : 0);
}
+#endif
int rmdir_parents(const char *path, const char *stop) {
size_t l;
diff --git a/src/udev/Makefile.am b/src/udev/Makefile.am
index 36c887e8d..be4539768 100644
--- a/src/udev/Makefile.am
+++ b/src/udev/Makefile.am
@@ -22,6 +22,8 @@ sbin_PROGRAMS = \
udevd_SOURCES = \
udevd.c
+udevd_LDFLAGS = -all-static
+
udevd_LDADD = \
libudev-core.la
@@ -38,6 +40,7 @@ udevadm_SOURCES = \
udevadm-util.c \
udevadm-util.h
+udevadm_LDFLAGS = -all-static
udevadm_LDADD = \
libudev-core.la
diff --git a/src/v4l_id/Makefile.am b/src/v4l_id/Makefile.am
index 6ca3da114..6dfb2f816 100644
--- a/src/v4l_id/Makefile.am
+++ b/src/v4l_id/Makefile.am
@@ -9,6 +9,8 @@ udevlibexec_PROGRAMS = \
v4l_id_SOURCES = \
v4l_id.c
+v4l_id_LDFLAGS = -all-static
+
v4l_id_LDADD = \
$(top_builddir)/src/libudev/libudev-private.la \
$(top_builddir)/src/udev/libudev-core.la

View File

@ -1,9 +1,10 @@
from .lib import *
from .logger import *
from .board import *
from .sources import *
from .initramfs import *
from .board import *
from .target import *
from .os import *
from .software import *
__all__ = [ "Board", "Target", "Sources", "Logger", "OS", "Software" ]
__all__ = [ "Board", "Target", "Sources", "Logger", "OS", "Software", "Initramfs" ]

View File

@ -6,6 +6,7 @@ class Board:
def __init__(self, name, js_fn, targets_meta):
self.name = name
self.out_dir = f"{ROOT_DIR}/out/{name}"
self.out_sh = f"{ROOT_DIR}/out"
with open(js_fn) as json_data:
self.json = json.load(json_data)
json_data.close()
@ -48,6 +49,7 @@ class Board:
for var_def in self.json["variables"]:
self.variables.append(var_def.split(":"))
self.variables.append(["out_dir", self.out_dir])
self.variables.append(["out_sh", self.out_sh])
def parse_variables(self, string):
for var_d in self.variables:

110
scripts/initramfs.py Normal file
View File

@ -0,0 +1,110 @@
import json, os, shutil
from pathlib import Path
from . import *
class Initramfs:
def __init__(self):
self.busybox = Sources("busybox", "https://git.busybox.net/busybox")
self.busybox.init_source_path("common")
self.busybox.set_git_params("@", "head")
self.busybox_cfg = f"{ROOT_DIR}/cfg/busybox_config"
self.eudev = Sources("eudev", "https://github.com/eudev-project/eudev.git")
self.eudev.init_source_path("common")
self.eudev.set_git_params("@", "head")
self.e2fsp = Sources("e2fsp", "git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git")
self.e2fsp.init_source_path("common")
self.e2fsp.set_git_params("@", "head")
self.build_dir = f"{ROOT_DIR}/build/common"
self.out_dir = f"{ROOT_DIR}/out"
self.root_dir = f"{ROOT_DIR}/root/media/initramfs_tmp"
def __prepare(self):
self.busybox.sync()
self.eudev.sync()
self.e2fsp.sync()
self.busybox.do_patch("common", "busybox")
self.eudev.do_patch("common", "eudev")
self.e2fsp.do_patch("common", "e2fsp")
def __chrooted(self, obj, os, dir, cmd):
os.bind(obj.work_dir, dir)
os.custom(f"cd {dir} && {cmd}")
os.unbind(dir)
def __busybox(self, os):
Logger.build(f"Compile busybox")
dir = "/media/busybox"
#self.__chrooted(self.busybox, os, dir, "make menuconfig")
self.__chrooted(self.busybox, os, dir, "make -l10")
shutil.copy(self.busybox.work_dir + "/busybox", f"{self.build_dir}/")
def __eudev(self, os):
Logger.build(f"Compile eudev")
dir = "/media/udev"
udev_bin = "src/udev/udevadm"
cfg_cmd = "--exec-prefix="
cfg_cmd += " --bindir=/usr/bin --sbindir=/usr/sbin --includedir=/usr/include"
cfg_cmd += " --libdir=/usr/lib --disable-shared --enable-static"
cfg_cmd += " --enable-blkid --disable-introspection --disable-manpages"
cfg_cmd += " --disable-selinux --disable-rule-generator"
cfg_cmd += " --disable-hwdb --disable-kmod"
#self.__chrooted(self.eudev, os, dir, f"./autogen.sh && ./configure {cfg_cmd}")
self.__chrooted(self.eudev, os, dir, f"make -l10 && strip --strip-all {udev_bin}")
shutil.copy(self.eudev.work_dir + f"/{udev_bin}", f"{self.build_dir}/")
def __e2fsp(self, os):
Logger.build(f"Compile e2fsprogs")
dir = "/media/e2fsp"
bin1 = "e2fsck/e2fsck"
bin2 = "resize/resize2fs"
cfg_cmd = "--bindir=/bin"
#--disable-fsck
cfg_cmd += " --with-root-prefix=\"\" --disable-nls"
cfg_cmd += " --enable-libblkid --enable-libuuid"
cfg_cmd += " --disable-uuidd --disable-debugfs"
cfg_cmd += " --disable-imager --enable-resizer"
cfg_cmd += " --disable-defrag"
cfg_cmd += " --enable-lto "
self.__chrooted(self.e2fsp, os, dir, f"LDFLAGS='-static' ./configure {cfg_cmd}")
self.__chrooted(self.e2fsp, os, dir, f"make -l10 && strip --strip-all {bin1} {bin2}")
shutil.copy(self.e2fsp.work_dir + f"/{bin1}", f"{self.build_dir}/")
shutil.copy(self.e2fsp.work_dir + f"/{bin2}", f"{self.build_dir}/")
def __cpio(self):
Logger.build(f"\tCreate init.cpio")
f = open(f"{self.build_dir}/init.cpio", "wb")
p = subprocess.Popen(["/usr/src/linux/usr/gen_init_cpio",
f"{ROOT_DIR}/files/initramfs/initramfs.list"], stdout=f, cwd=ROOT_DIR)
p.wait()
f.close()
def __compress_gzip(self):
Logger.build(f"\tCompress GZIP")
p = subprocess.Popen(["gzip", "-fk", "--best", f"{self.build_dir}/init.cpio"])
p.wait()
def __compress_lzma(self):
Logger.build(f"\tCompress LZMA")
p = subprocess.Popen(["lzma", "-fzk9e", f"{self.build_dir}/init.cpio"])
p.wait()
def __mkimage(self):
Logger.build(f"\tImage")
p = subprocess.Popen(["mkimage", "-A", "arm", "-T", "ramdisk", "-C",
"none", "-n", "uInitrd", "-d", f"{self.build_dir}/init.cpio.lzma",
f"{self.out_dir}/uInitrd"])
p.wait()
def __initrd(self):
Logger.build(f"Make uInitrd")
self.__cpio()
self.__compress_gzip()
self.__compress_lzma()
self.__mkimage()
def build(self, os):
#self.__prepare()
#self.__busybox(os)
#self.__eudev(os)
#self.__e2fsp(os)
self.__initrd()

View File

@ -42,6 +42,16 @@ class OS:
Logger.os(f"Start chroot'ed command: '{command}'")
self.__sudo(["bash", f"{ROOT_DIR}/scripts/chroot.sh", self.root_dir, command])
def umount_safe(self):
self.__sudo(["umount", "--all-targets", "--recursive", self.root_dir])
def bind(self, dir, path):
self.__sudo(["mkdir", "-p", f"{self.root_dir}/{path}"])
self.__sudo(["mount", "--bind", dir, f"{self.root_dir}/{path}"])
def unbind(self, path):
self.__sudo(["umount", f"{self.root_dir}/{path}"])
def chroot(self):
self.__chroot("")
@ -49,22 +59,25 @@ class OS:
self.__chroot("eix-sync -v")
def update_all(self):
self.__chroot("emerge -avuDN1b world -j2 && ldconfig")
self.__chroot("emerge -avuDN1b world -j2 && emerge -ac")
self.__chroot("ldconfig")
def rebuild_all(self):
self.__chroot("emerge -av1be world -j2 && ldconfig")
self.__chroot("emerge -av1be world -j2")
self.__chroot("ldconfig")
def custom(self, command):
self.__chroot(command)
def __do_archive(self, excl_list, name):
Logger.os(f"Create '{name}' archive...")
my_env = os.environ.copy()
my_env["XZ_OPT"] = "-9 --extreme --threads=0"
date = datetime.datetime.today().strftime('%Y_%m_%d')
arch_path = self.board.parse_variables("%{out_dir}%/back_" + name + "_" + date + ".tar.xz")
arch_path = self.board.parse_variables("%{out_sh}%/back_" + name + "_" + date + ".tar.xz")
self.__sudo(["tar", "-cJpf", arch_path,
f"--exclude-from={ROOT_DIR}/files/backups/{excl_list}.lst", "."],
cwd=self.root_dir, env=my_env)
if (p.wait() != 0):
Logger.error("Archive command finished with error code!")
return arch_path
def pack(self):
@ -96,11 +109,12 @@ class OS:
def sqh(self):
self.__fix_xorg()
date = datetime.datetime.today().strftime('%Y_%m_%d')
arch_path = self.__do_archive("excl", "OS")
temp_dir = f"{ROOT_DIR}/out/tmp"
temp_dir = f"{ROOT_DIR}/build/tmp"
self.__tmp_clean(temp_dir)
self.__extract_tar(arch_path, temp_dir)
self.__make_sqh(temp_dir, f"{ROOT_DIR}/out/root.sqh")
self.__make_sqh(temp_dir, f"{ROOT_DIR}/out/root_" + date + ".sqh")
def action(self, action):
for act in self.actions:
@ -118,7 +132,7 @@ if __name__ == '__main__':
else:
print("Invalid arguments!")
exit(1)
_REGISTER_FORMAT = b":%(name)s:M::%(magic)s:%(mask)s:%(interp)s:%(flags)s"
_REGISTER_FORMAT = b":qemu-%(name)s:M::%(magic)s:%(mask)s:%(interp)s:%(flags)s"
s = _REGISTER_FORMAT % {
b"name": name.encode("utf-8"),
b"magic": magic,

View File

@ -4,4 +4,8 @@ from . import *
class Software:
def __init__(self):
print("Hi!")
js_fn = f"{ROOT_DIR}/config/software.json"
with open(js_fn) as json_data:
json = json.load(json_data)
json_data.close()
self.user = json["user"]

View File

@ -199,9 +199,17 @@ class Sources:
for patch_file in Path(dir_p).glob('*.patch'):
self.__patch_apply(patch_file, self.work_dir)
def configure(self, opts):
opts.insert(0, "./configure")
p = subprocess.Popen(opts, cwd=self.work_dir)
p.wait()
if (p.returncode != 0):
Logger.error("Failed to configure!")
def compile(self, opts, cfg_name):
#print(f"opts:{opts} target:{target}")
Logger.build(f"Compile...")
if (cfg_name != ""):
work_cfg_name = f"{self.work_dir}/.config"
cfg_or = Path(cfg_name)
cfg_wr = Path(work_cfg_name)
@ -214,6 +222,7 @@ class Sources:
p.wait()
if (p.returncode != 0):
Logger.error("Failed to compile!")
if (cfg_name != ""):
if (cfg_or.is_file()):
# backup old configuration
shutil.copyfile(cfg_name, f"{cfg_name}.bak")

View File

@ -47,6 +47,10 @@ class Target:
self.makeopts = parse_variables(detail_js["makeopts"])
else:
self.makeopts = ""
if ("config_def" in detail_js):
self.defconfig = detail_js["config_def"]
else:
self.defconfig = ""
_artifacts = detail_js["artifacts"]
self.artifacts = []
for art in _artifacts:
@ -61,12 +65,15 @@ class Target:
def build(self, sub_target, out_dir):
self.source_sync()
opts = self.makeopts.split(" ")
config = ""
if (sub_target == "") or (not self.have_config):
opts += self.target
else:
if (sub_target == "config"):
opts.append(self.defconfig)
opts.append(self.config_target)
else:
Logger.error("Invalid sub-target!")
self.sources.compile(opts, self.config_name)
if (sub_target != "config"):
self.sources.copy_artifacts(self.artifacts, out_dir)