/make (b2c0f6eb4eb95d640dba35e210d36f51732791ec) (9214 bytes) (mode 100755) (type blob)
#!/bin/sh
# this script is brutal and verbose, has no tricks and is quite linear, then
# quite easy to deal with
# for the moment, it's hardcoded for a gcc toolchain... BAD! Since now
# gcc is a c++ piece of shit
# stolen from ffmpeg configure like a pig
set -e
# prevent locale nonsense from breaking basic text processing
LC_ALL=C
export LC_ALL
init_file_name=init
init_ulinux_src_files='
ulinux/utils/ascii/string/vsprintf.c
ulinux/utils/mem.c
ulinux/utils/ascii/string/conv/decimal/decimal.c
'
init_src_files="
uevents.c
modules.c
uevent.c
init.c
ramfs.c
$init_ulinux_src_files
"
sep_start()
{
printf '###############################################################################\n'
}
sep_end()
{
printf '###############################################################################\n\n'
}
subsep_start()
{
printf '*******************************************************************************\n'
}
subsep_end()
{
printf '*******************************************************************************\n'
}
################################################################################
is_in()
{
value=$1
shift
for var in $*; do
[ $var = $value ] && return 0
done
return 1
}
die_unknown(){
echo "Unknown option \"$1\"."
echo "See $0 --help for available options."
exit 1
}
set_default(){
for opt; do
eval : \${$opt:=\$${opt}_default}
done
}
CMDLINE_SET='
linux_build_dir
kernel_modules_base_dir
init_cpp
init_cc
init_ccld
init_ulinux_arch
uevents_timeout
gen_init_cpio
kernel_release
extra_modules
pkg_config
elf_interpreter
'
# command line set defaults
# if the root is not around in less than 4s, something is really wrong
uevents_timeout_default=4000
gen_init_cpio_default='$linux_build_dir/usr/gen_init_cpio'
linux_build_dir_default=/usr/src/linux
#-------------------------------------------------------------------------------
# this defaults are for gcc, tested with version 4.7.3. You will need to
# override those for you compiler (tinycc/open64/pcc...). additionnally, source
# support for different toolchains is not done
# since we use standard C runtime libs, be nice with the C runtime
init_cpp_default='gcc -E -Wall -Wextra'
init_cc_default='gcc -Wall -Wextra -Wno-implicit-fallthrough -std=gnu99 -O2 -c'
init_ccld_default='gcc -Wl,-s -static'
#-------------------------------------------------------------------------------
kernel_modules_base_dir_default=/
kernel_release_default=$(uname -r)
init_ulinux_arch_default=$(uname -m | sed -e s/i.86/i386/ -e s/parisc64/parisc/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/sh.*/sh/)
extra_modules_default=
pkg_config_default=pkg-config
elf_interpreter_default=
set_default $CMDLINE_SET
show_help()
{
cat <<EOF
Usage: make [options] [operations]
default is to build the the initramfs xz compressed cpio archive:
Options: [defaults in brackets after descriptions]
Help options:
--help print this message
Standard options:
--lib-path-list=LIB_PATH_LIST colon separated paths to look for target libraries
--uevents-timeout=UEVENTS_TIMEOUT uevents timeout in ms looking up for root block device to go online [$uevents_timeout]
--quiet init will be silenced (output code compiled out)
--linux-build-dir=DIR where to find the target linux build tree [$linux_build_dir_default]
--kernel-release=RELEASE the linux releases version [$kernel_release]
--kernel-modules-base-dir=DIR the base dir for linux modules and support files [$kernel_modules_base_dir]
--extra-modules=EXTRA_MODULES coma separated list of extra module to probe
Advanced options:
--gen-init-cpio=GEN_INIT_CPIO_PATH use this linux host tool to build the linux cpio initramfs [$gen_init_cpio_default]
--pkg-config=PKG_CONFIG use PKG_CONFIG pkg-config command for target libraries [$pkg_config_default]
--init-cpp=CPP use CPP compiler command line CPP for target init process [$init_cpp_default]
--init-cc=CC use C compiler command line CC for target init process objects [$init_cc_default]
--init-ccld=CCLD use compiler driver linker command line CCLD for target init process [$init_ccld_default]
--init-ulinux-arch=ARCH use ulinux ARCH for target init process [$init_ulinux_arch]
EOF
exit 0
}
################################################################################
for opt do
optval="${opt#*=}"
case "$opt" in
--help|-h) show_help
;;
--quiet) CPPFLAGS="$CPPFLAGS -DQUIET"
;;
*)
optname=${opt%%=*}
optname=${optname#--}
optname=$(echo "$optname" | sed 's/-/_/g')
if is_in $optname $CMDLINE_SET; then
eval $optname='$optval'
else
die_unknown $opt
fi
;;
esac
done
################################################################################
sep_start;echo 'looking for source path:'
if test -f make; then
src_path=.
else
src_path=$(cd $(dirname "$0"); pwd)
echo "$src_path" | grep -q '[[:blank:]]' &&
die "out of tree builds are impossible with whitespace in source path."
fi
echo "source path is $src_path";sep_end
################################################################################
sep_start;echo 'checking libkmod and libblkid pkgconfig support:'
if $pkg_config --exists libkmod blkid; then
echo "found pkg-config files for libkmod and libblkid"
else
echo "missing pkg-config file for libkmod or libblkid"
exit 1
fi
sep_end
################################################################################
# define variable in source
CPPFLAGS="$CPPFLAGS -DUEVENTS_TIMEOUT=$uevents_timeout"
CPPFLAGS="$CPPFLAGS $($pkg_config --cflags-only-I libkmod blkid)"
CFLAGS="$CFLAGS $($pkg_config --cflags-only-other libkmod blkid)"
LIBS="$($pkg_config --libs --static libkmod blkid) $LIBS"
################################################################################
sep_start;echo 'configure ulinux src tree for target arch:'
rm -f $src_path/ulinux/arch
ln -s archs/$init_ulinux_arch $src_path/ulinux/arch
echo "init ulinux arch is $init_ulinux_arch"
sep_end
################################################################################
# generated some code/headers
sep_start
. $src_path/modules_revisions_all.sh
printf "$src_path/modules_revisions_all.sh was sourced:\n--------\n"
cat $src_path/modules_revisions_all.sh
echo '--------'
sep_end
sep_start
revision=$(echo "$kernel_release" | egrep -o '^[[:digit:]]+\.[[:digit:]]+')
if test -f $src_path/$revision; then
. $src_path/$revision
printf "linux revision is $revision, $src_path/$revision was sourced:\n--------\n"
cat $src_path/$revision
echo '--------'
else
echo 'no revision specific modules to source'
fi
sep_end
# those modules are all loaded before anything else
sep_start;echo 'generate static module list:'
$src_path/script/static_modules_h.sh $extra_modules $DISK_MODULES \
>./static_modules.h
cat ./static_modules.h
sep_end
################################################################################
sep_start;echo 'C preprocess init src files:'
for init_src_file in $init_src_files
do
init_pp_c_file=${init_src_file%.c}.pp.c
echo "INIT_CPP $init_src_file->$init_pp_c_file"
mkdir -p $(dirname $init_pp_c_file)
$init_cpp -o $init_pp_c_file \
$CPPFLAGS \
-I. \
-I$src_path \
$src_path/$init_src_file
init_pp_c_files="$init_pp_c_file $init_pp_c_files"
done
sep_end
################################################################################
sep_start;echo 'compile init preprocessed src files:'
for init_pp_c_file in $init_pp_c_files
do
init_obj_file=${init_pp_c_file%.pp.c}.o
echo "INIT_CC $init_pp_c_file-->$init_obj_file"
$init_cc $CFLAGS -o $init_obj_file $init_pp_c_file
init_obj_files="$init_obj_file $init_obj_files"
done
sep_end
################################################################################
sep_start;echo 'link the init objects to produce the init binary:'
echo "INIT_CCLD $init_file_name"
$init_ccld -o $init_file_name $init_obj_files $LIBS
sep_end
################################################################################
sep_start;echo 'generate the cpio source file:'
sed -e "s:@INIT_PATH@:$(readlink -f $init_file_name):" "$src_path/cpio.in" >cpio
echo "dir /lib/modules/$kernel_release 0755 0 0">>cpio
modules=$HW_MODULES,$DISK_MODULES,$FS_MODULES
if test -n "$extra_modules";then
modules=$modules,$extra_modules
fi
subsep_start
#add proper entries in the cpio definition file related to linux modules
$src_path/script/cpio_modules_add.sh $kernel_modules_base_dir $kernel_release \
$modules ./cpio
subsep_end
printf "cpio source file is:\n--------\n"
cat cpio
echo '--------'
sep_end
################################################################################
sep_start;echo 'generating and compressing the cpio archive'
e_gen_init_cpio=$(eval echo "$gen_init_cpio")
$e_gen_init_cpio cpio >${kernel_release}.cpio
xz --force --check=crc32 --extreme --stdout ${kernel_release}.cpio >${kernel_release}.cpio.xz
sep_end
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
567 |
6f604886a8e7f86f47ef6776f4efad3490fdf2c8 |
DEPENDENCIES |
100644 |
blob |
35147 |
94a9ed024d3859793618152ea559a168bbcbb5e2 |
LICENSE.md |
100644 |
blob |
767 |
99d41aa00f593125f0679473a533d2c817825b38 |
README |
100644 |
blob |
644 |
598bf35b742147b3cc2bc1da0fd6d41aa282e77e |
TODO |
100644 |
blob |
432 |
2516d063ca695699c1ec3d755ef782bad84f203f |
cpio.in |
100644 |
blob |
587 |
1890391057120a83a6714310987be3ca82de46cc |
globals.h |
100644 |
blob |
5195 |
7b620a42d6b31af69dc0cc714d95eceb240128d5 |
init.c |
100755 |
blob |
9214 |
b2c0f6eb4eb95d640dba35e210d36f51732791ec |
make |
100644 |
blob |
5877 |
e849ba428752ea61144fe879792c8c68a65e3160 |
modules.c |
100644 |
blob |
503 |
f478bdeefa4ae3259dedfe0b4f78036492295d27 |
modules.h |
100644 |
blob |
565 |
11793d4b637ec43ae74b21ed6d210bee27851fa5 |
modules_revisions_all.sh |
100644 |
blob |
674 |
7f272e25a25b4da12ad81f13b6eeff1bba4187af |
out.h |
100644 |
blob |
3180 |
6d142befdbc559aa3b6089443a2988b054bc71de |
ramfs.c |
100644 |
blob |
341 |
de9218a39777b8dd8feb5ee76cdf41af215ef473 |
ramfs.h |
040000 |
tree |
- |
f12c32d79aaa63e9f7f42bc53bddd179dde6fa2f |
script |
100644 |
blob |
3598 |
3ab8311a7c7e4e843cde3253fce88af8823bbfc2 |
uevent.c |
100644 |
blob |
348 |
cf07be71685703316f9522de37d466034d08e635 |
uevent.h |
100644 |
blob |
3970 |
cfe47059c2c26697fd02d2f18b0afe68dc7627fd |
uevents.c |
100644 |
blob |
413 |
896725abf8b5477eb7013e55429aa89a2bf97ed3 |
uevents.h |
040000 |
tree |
- |
d4827ce4a24093ddab0c73729c96a5c2c793e54c |
ulinux |
100644 |
blob |
4059 |
5055bad7b1ba64732700059921b0e4f3fdf672fc |
ulinux_namespace.h |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/sylware/cinitramfs
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/sylware/cinitramfs
Clone this repository using git:
git clone git://git.rocketgit.com/user/sylware/cinitramfs
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main