final import from parazyd/arm-sdk

This commit is contained in:
parazyd 2016-04-14 16:50:58 +02:00
parent b71645d3a5
commit 9d9f3a1106
22 changed files with 17140 additions and 0 deletions

View File

@ -67,6 +67,11 @@ Once initialized, you will get further instructions.
For more info, please consult the `README` included in the `arm` subdirectory.
## Configuration
Edit the `config` file included in the root directory of arm-sdk to your liking.
If you are using a custom toolchain, add it to the PATH as described.
## Acknowledgments
The Devuan SDK was conceived during a period of residency at the

35
arm/README.md Normal file
View File

@ -0,0 +1,35 @@
# ARM image builds
## qemu-wrapper
For certain devices, you will want to pass arguments to qemu, such as the cpu
model. To enable this, you will have to modify and compile qemu-wrapper.c with:
```
gcc -static qemu-wraper.c -O2 -s -o qemu-wrapper
```
And after it's compiled, uncomment the entry in the settings section of your
build script.
### List of shellcodes for different architectures
Consult the RaspberryPi2 build script to see how to use these. You will need to
use the correct one, depending on the architecture you're building.
```
print ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-aarch64:' | sudo tee /proc/sys/fs/binfmt_misc/register
print ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/qemu-wrapper:' | sudo tee /proc/sys/fs/binfmt_misc/register
print ':armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-armeb:' | sudo tee /proc/sys/fs/binfmt_misc/register
print ':alpha:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-alpha:' | sudo tee /proc/sys/fs/binfmt_misc/register
print ':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-mips:' | sudo tee /proc/sys/fs/binfmt_misc/register
print ':mipsel:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-mipsel:' | sudo tee /proc/sys/fs/binfmt_misc/register
print ':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-ppc:' | sudo tee /proc/sys/fs/binfmt_misc/register
print ':sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff\xff:/usr/bin/qemu-sh4:' | sudo tee/proc/sys/fs/binfmt_misc/register
print ':sh4eb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-sh4eb:' | sudo tee/proc/sys/fs/binfmt_misc/register
print ':sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-sparc:' | sudo tee /proc/sys/fs/binfmt_misc/register
```

400
arm/common Normal file
View File

@ -0,0 +1,400 @@
#!/usr/bin/env zsh
#
# Devuan SDK - build management
#
# Copyright (C) 2015-2016 Dyne.org Foundation
# Copyright (C) 2016 parazyd <parazyd@dyne.org>
#
# Devuan SDK is designed, written and maintained by Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This source code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer
# to the GNU Public License for more details.
#
# You should have received a copy of the GNU Public License along with
# this source code; if not, write to: Free Software Foundation, Inc.,
# 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Common functions for builds
writebase="$strapdir"
command -v dcfldd >/dev/null && DD=`command -v dcfldd`
DD=${DD:-/bin/dd}
write-hostname() {
fn write-hostname
print $os | sudo tee ${writebase}/etc/hostname
notice "Wrote $writebase/etc/hostname"
}
write-fstab() {
fn write-fstab
notice "Writing fstab"
cat <<EOF | sudo tee ${workdir}/root/etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0
/dev/mmcblk0p2 / ext4 errors=remount-ro 0 1
/dev/mmcblk0p1 /boot vfat noauto 0 0
EOF
}
write-hosts-file() {
fn write-hosts-file
cat <<EOF | sudo tee ${writebase}/etc/hosts
127.0.0.1 ${os} localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe02::1 ip6-allnodes
fe02::1 ip6-allrouters
EOF
notice "Wrote $writebase/etc/hosts"
}
write-network-ifaces() {
fn write-hosts-file
cat <<EOF | sudo tee ${writebase}/etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOF
notice "Wrote $writebase/etc/network/interfaces"
}
write-resolvconf() {
fn write-resolvconf
cat <<EOF | sudo tee ${writebase}/etc/resolv.conf
# foebud and ccc dns
nameserver 85.214.20.141
nameserver 213.73.91.35
EOF
notice "Wrote $writebase/etc/resolv.conf"
}
write-debconf() {
fn write-debconf
cat <<EOF | sudo tee ${writebase}/debconf.set
console-common console-data/keymap/policy select Select keymap from full list
console-common console-data/keymap/full select en-latin1-nodeadkeys
EOF
[[ $? = 0 ]] || error "Failed writing $writebase/debconf.set"
}
write-cleanup() {
fn write-cleanup
cat <<EOF | sudo tee ${writebase}/cleanup
#!/bin/bash
rm -rf /root/.bash_history
apt-get update
apt-get clean
rm -f /0
rm -f /hs_err*
rm -f cleanup
rm -f /usr/bin/qemu*
EOF
sudo chmod +x $writebase/cleanup
notice "Wrote $writebase/cleanup"
}
write-sources-list() {
fn write-sources-list
cat <<EOF | sudo tee ${writebase}/$1etc/apt/sources.list
deb ${mirror} ${release} ${section}
deb-src ${mirror} ${release} ${section}
EOF
notice "Wrote $writebase/etc/apt/sources.list"
}
write-third-stage() {
fn write-third-stage
cat <<EOF | sudo tee ${writebase}/third-stage
#!/bin/bash
dpkg-divert --add --local --divert /usr/sbin/invoke-rc.d.chroot --rename /usr/sbin/invoke-rc.d
cp /bin/true /usr/sbin/invoke-rc.d
echo -e "#!/bin/sh\nexit 101" > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d
apt-get update
apt-get --yes --force-yes install locales-all
debconf-set-selections /debconf.set
rm -f /debconf.set
apt-get update
apt-get -y install ${core_packages}
echo "root:toor" | chpasswd
sed -i -e 's/KERNEL\!=\"eth\*|/KERNEL\!=\"/' /lib/udev/rules.d/75-persistent-net-generator.rules
rm -fv /etc/udev/rules.d/70-persistent-net.rules
export DEBIAN_FRONTEND=noninteractive
apt-get --yes --force-yes install ${base_packages}
apt-get --yes --force-yes install ${system_packages}
apt-get --yes --force-yes install ${extra_packages}
apt-get --yes --force-yes dist-upgrade
apt-get --yes --force-yes autoremove
echo "Allowing SSH root login"
sed -i -e 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
update-rc.d ssh enable
rm -fv /usr/sbin/policy-rc.d
rm -fv /usr/sbin/invoke-rc.d
dpkg-divert --remove --rename /usr/sbin/invoke-rc.d
rm -fv /third-stage
EOF
sudo chmod +x $writebase/third-stage
notice "Wrote $writebase/third-stage"
}
${device_name}-bootstrap() {
fn ${device_name}-bootstrap
notice "Bootstrapping $os base"
mkdir -p ${workdir}
cd ${workdir}
sudo debootstrap --foreign --arch ${arch} ${release} ${strapdir} ${mirror}
[[ $? = 0 ]] || {
error "debootstrap failed"
return 1
}
# qemu-wrapper
[[ $enable_qemu_wrapper = 1 ]] && {
sudo cp $R/arm/qemu-wrapper ${strapdir}/usr/bin/ && notice "Copied qemu-wrapper"
print ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/qemu-wrapper:' \
| sudo tee /proc/sys/fs/binfmt_misc/register
}
sudo cp -rfv ${qemu_bin} ${strapdir}/usr/bin/ && notice "Success bootstrapping base"
[[ $? = 0 ]] || return 1
notice "Next step is "${device_name}-secondstage
}
${device_name}-secondstage() {
fn ${device_name}-secondstage
notice "Bootstrapping $os second-stage"
LANG=C sudo -E chroot ${strapdir} /debootstrap/debootstrap --second-stage
[[ $? = 0 ]] || {
error "debootstrap second-stage failed"
return 1
}
write-sources-list
write-hostname
write-hosts-file
write-network-ifaces
write-resolvconf
write-debconf
write-third-stage
notice "Finished second-stage"
notice "Next step is: ${device_name}-thirdstage"
}
${device_name}-thirdstage() {
fn ${device_name}-thirdstage
notice "Bootstrapping $os third-stage"
export LC_ALL=C
export DEBIAN_FRONTEND=noninteractive
sudo -E mount -t proc proc ${strapdir}/proc && notice "Mounted proc..."
sudo -E mount -o bind /dev/ ${strapdir}/dev/ && notice "Mounted dev..."
sudo -E mount -o bind /dev/pts ${strapdir}/dev/pts && notice "Mounted dev/pts..."
notice "Chrooting..."
LANG=C sudo -E chroot $strapdir /third-stage
[[ $? = 0 ]] || {
error "Failed at third-stage"
return 1
}
write-cleanup
notice "Executing cleanup..."
LANG=C sudo -E chroot ${strapdir} /cleanup
[[ $? = 0 ]] || {
error "Failed at cleanup"
return 1
}
copy-zram
sudo umount ${strapdir}/dev/pts && notice "Unmounted dev/pts"
sudo umount ${strapdir}/dev && notice "Unmounted dev"
sudo umount ${strapdir}/proc && notice "Unmounted proc"
notice "Finalized third-stage"
notice "Next step is: ${device_name}-prepimg"
}
${device_name}-prepimg() {
fn ${device_name}-prepimg
notice "Creating image file..."
$DD if=/dev/zero \
of=${image_name}.img \
bs=1M count=$size
notice "Partitioning..."
parted ${image_name}.img --script -- mklabel msdos
parted ${image_name}.img --script -- mkpart primary ${parted_boot}
parted ${image_name}.img --script -- mkpart primary ${parted_root}
loopdevice=`sudo losetup -f --show ${workdir}/${image_name}.img`
mappdevice=`sudo kpartx -va $loopdevice | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1`
notice "Loopdevice: $loopdevice"
notice "Mapper device: $mappdevice"
sleep 2
mappdevice="/dev/mapper/${mappdevice}"
bootpart=${mappdevice}p1
rootpart=${mappdevice}p2
notice "Formatting partitions..."
sudo mkfs.vfat $bootpart
sudo mkfs.ext4 $rootpart
mkdir -p ${workdir}/bootp ${workdir}/root
sudo mount $bootpart ${workdir}/bootp && notice "Mounted boot part"
sudo mount $rootpart ${workdir}/root && notice "Mounted root part"
print ${inittab} | sudo tee -a ${strapdir}/etc/inittab
for i in $custmodules; do print $i | sudo tee -a ${strapdir}/etc/modules ; done
notice "Finalized preparing image"
notice "Next step is ${device_name}-build-kernel"
}
${device_name}-pack-image() {
fn ${device_name}-pack-image
notice "Rechecking filesystem"
sudo e2fsck -f ${mappdevice}p2
sudo resize2fs ${mappdevice}p2
sudo kpartx -dv $loopdevice
[[ $? = 0 ]] || error "kpartx failed to remove $loopdevice"
sudo losetup -d $loopdevice
[[ $? = 0 ]] || error "losetup failed to remove $loopdevice"
notice "Compressing image to xz"
xz -zv ${image_name}.img
notice "Generating sha256 for ${image_name}.img.xz"
sha256sum ${image_name}.img.xz > ${image_name}.img.xz.sha
[[ -d $R/arm/finished ]] || mkdir -p $R/arm/finished
mv -v ${image_name}.img.xz $R/arm/finished/
mv -v ${image_name}.img.xz.sha $R/arm/finished/
cd $R
sudo rm -r ${strapdir}
sudo rm -r ${workdir}
notice "Finished building ${image_name}"
}
get-kernel-firmware() {
[[ -d $R/tmp/firmware ]] || git clone \
https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git $R/tmp/firmware
rm -rf $R/tmp/firmware/.git
}
clean-kernel-leftovers() {
notice "Cleaning up from kernel build..."
sudo rm -r ${strapdir}/usr/src/kernel
sudo rm ${strapdir}/usr/src/${device_name}.config
#sudo rm ${strapdir}/usr/src/kernel-at-commit
sudo chown root ${strapdir}/lib
sudo chown -R root ${strapdir}/lib/modules
sudo chown -R root ${strapdir}/lib/firmware
cd ${workdir}
}
copy-kernel-config() {
cd ${strapdir}/usr/src/kernel
cp -v ${workdir}/../kernel-configs/${device_name}.config .config
sudo cp -v ${workdir}/../kernel-configs/${device_name}.config ../${device_name}.config
export ARCH=arm
export CROSS_COMPILE=${compiler}
}
make-kernel-modules() {
[[ -d ${strapdir}/lib/modules ]] || sudo mkdir -p ${strapdir}/lib/modules
[[ -d ${strapdir}/lib/firmware ]] || sudo mkdir -p ${strapdir}/lib/firmware
sudo chown -R $USER ${strapdir}/lib/modules
sudo chown -R $USER ${strapdir}/lib/firmware
make modules_install INSTALL_MOD_PATH=${strapdir}
[[ $? = 0 ]] || {
error "Failed installing kernel modules"
return 1
}
}
copy-zram() {
notice "Installing zram init"
sudo cp ${workdir}/../extra/zram ${strapdir}/etc/init.d/zram
sudo chmod +x ${strapdir}/etc/init.d/zram
}
${device_name}-finalize() {
fn ${device_name}-finalize
clean-kernel-leftovers
notice "Making you wait for nothing..."
sudo rsync -HPavz -q ${strapdir}/* ${workdir}/root
writebase="${workdir}/root"
write-sources-list
write-fstab
cd ${workdir}
sudo umount ${bootpart} && notice "Unmounted boot part"
sudo umount ${rootpart} && notice "Unmounted root part"
notice "Finalized build..."
notice "Pack and finish with: ${device_name}-pack-image"
}
${device_name}-build-all() {
for i in bootstrap secondstage thirdstage prepimg build-kernel finalize pack-image; do
${device_name}-${i}
[[ $? = 0 ]] || {
error "Failed on ${device_name}-${i}"
return 1
}
done
}
[[ -f ${qemu_bin} ]] || warn "No ${qemu_bin}"
notice "Loaded build script for ${device_name}"
notice "Run '${device_name}-bootstrap' to build step by step"
notice "Run '${device_name}-build-all' to build image automatically"

150
arm/extra/rpi-conf/init_resize.sh Executable file
View File

@ -0,0 +1,150 @@
#!/bin/sh
reboot_pi () {
umount /boot
sync
echo b > /proc/sysrq-trigger
sleep 5
exit 0
}
check_commands () {
if ! command -v whiptail > /dev/null; then
echo ="whiptail not found"
sleep 5
return 1
fi
for COMMAND in grep cut sed parted fdisk; do
if ! command -v $COMMAND > /dev/null; then
FAIL_REASON="$COMMAND not found"
return 1
fi
done
return 0
}
check_noobs () {
if [ "$BOOT_PART_DEV" = "/dev/mmcblk0p1" ]; then
NOOBS=0
else
NOOBS=1
fi
}
get_variables () {
ROOT_PART_DEV=`grep -Eo 'root=[[:graph:]]+' /proc/cmdline | cut -d "=" -f 2-`
ROOT_PART_NAME=`echo $ROOT_PART_DEV | cut -d "/" -f 3`
ROOT_DEV_NAME=`echo /sys/block/*/${ROOT_PART_NAME} | cut -d "/" -f 4`
ROOT_DEV="/dev/${ROOT_DEV_NAME}"
ROOT_PART_NUM=`cat /sys/block/${ROOT_DEV_NAME}/${ROOT_PART_NAME}/partition`
BOOT_PART_DEV=`cat /proc/mounts | grep " /boot " | cut -d " " -f 1`
BOOT_PART_NAME=`echo $BOOT_PART_DEV | cut -d "/" -f 3`
BOOT_DEV_NAME=`echo /sys/block/*/${BOOT_PART_NAME} | cut -d "/" -f 4`
BOOT_PART_NUM=`cat /sys/block/${BOOT_DEV_NAME}/${BOOT_PART_NAME}/partition`
check_noobs
ROOT_DEV_SIZE=`cat /sys/block/${ROOT_DEV_NAME}/size`
TARGET_END=`expr $ROOT_DEV_SIZE - 1`
PARTITION_TABLE=`parted -m $ROOT_DEV unit s print | tr -d 's'`
LAST_PART_NUM=`echo "$PARTITION_TABLE" | tail -n 1 | cut -d ":" -f 1`
ROOT_PART_LINE=`echo "$PARTITION_TABLE" | grep -e "^${ROOT_PART_NUM}:"`
ROOT_PART_START=`echo $ROOT_PART_LINE | cut -d ":" -f 2`
ROOT_PART_END=`echo $ROOT_PART_LINE | cut -d ":" -f 3`
if [ "$NOOBS" = "1" ]; then
EXT_PART_LINE=`echo "$PARTITION_TABLE" | grep ":::;" | head -n 1`
EXT_PART_NUM=`echo $EXT_PART_LINE | cut -d ":" -f 1`
EXT_PART_START=`echo $EXT_PART_LINE | cut -d ":" -f 2`
EXT_PART_END=`echo $EXT_PART_LINE | cut -d ":" -f 3`
fi
}
check_variables () {
if [ "$NOOBS" = "1" ]; then
if [ $EXT_PART_NUM -gt 4 ] || \
[ $EXT_PART_START -gt $ROOT_PART_START ] || \
[ $EXT_PART_END -lt $ROOT_PART_END ]; then
FAIL_REASON="Unsupported extended partition"
return 1
fi
fi
if [ $ROOT_PART_NUM -ne $LAST_PART_NUM ]; then
FAIL_REASON="Root partition should be last partition"
return 1
fi
if [ $ROOT_PART_END -gt $TARGET_END ]; then
FAIL_REASON="Root partition runs past the end of device"
return 1
fi
if [ ! -b $ROOT_DEV ] || [ ! -b $ROOT_PART_DEV ] || [ ! -b $BOOT_PART_DEV ] ; then
FAIL_REASON="Could not determine partitions"
return 1
fi
}
main () {
get_variables
if ! check_variables; then
return 1
fi
if [ "$NOOBS" = "1" ]; then
BCM_MODULE=`cat /proc/cpuinfo | grep -e "^Hardware" | cut -d ":" -f 2 | tr -d " " | tr '[:upper:]' '[:lower:]'`
if ! modprobe $BCM_MODULE; then
FAIL_REASON="Couldn't load BCM module $BCM_MODULE"
return 1
fi
echo $BOOT_PART_NUM > /sys/module/${BCM_MODULE}/parameters/reboot_part
fi
if [ $ROOT_PART_END -eq $TARGET_END ]; then
reboot_pi
fi
if [ "$NOOBS" = "1" ]; then
if ! parted -m $ROOT_DEV u s resizepart $EXT_PART_NUM yes $TARGET_END; then
FAIL_REASON="Extended partition resize failed"
return 1
fi
fi
if ! parted -m $ROOT_DEV u s resizepart $ROOT_PART_NUM $TARGET_END; then
FAIL_REASON="Root partition resize failed"
return 1
fi
return 0
}
mount -t proc proc /proc
mount -t sysfs sys /sys
mount /boot
sed -i 's/ quiet init=.*$//' /boot/cmdline.txt
mount /boot -o remount,ro
sync
echo 1 > /proc/sys/kernel/sysrq
if ! check_commands; then
reboot_pi
fi
if main; then
whiptail --infobox "Resized root filesystem. Rebooting in 5 seconds..." 20 60
sleep 5
else
sleep 5
whiptail --msgbox "Could not expand filesystem, please try raspi-config or rc_gui.\n${FAIL_REASON}" 20 60
fi
reboot_pi

1382
arm/extra/rpi-conf/raspi-config Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,44 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: raspi-config
# Required-Start: udev mountkernfs $remote_fs
# Required-Stop:
# Default-Start: S
# Default-Stop:
# Short-Description: Switch to ondemand cpu governor (unless shift key is pressed)
# Description:
### END INIT INFO
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg "Checking if shift key is held down"
timeout 1 thd --dump /dev/input/event* | grep -q "LEFTSHIFT\|RIGHTSHIFT"
if [ $? -eq 0 ]; then
printf " Yes. Not enabling ondemand scaling governor"
log_end_msg 0
else
printf " No. Switching to ondemand scaling governor"
SYS_CPUFREQ_GOVERNOR=/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
if [ -e $SYS_CPUFREQ_GOVERNOR ]; then
echo "ondemand" > $SYS_CPUFREQ_GOVERNOR
echo 50 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
echo 100000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate
echo 50 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
echo 1 > /sys/devices/system/cpu/cpufreq/ondemand/io_is_busy
fi
log_end_msg 0
fi
;;
stop)
;;
restart)
;;
force-reload)
;;
*)
echo "Usage: $0 start" >&2
exit 3
;;
esac

Binary file not shown.

View File

@ -0,0 +1,66 @@
# NVRAM file for BCM943430WLPTH
# 2.4 GHz, 20 MHz BW mode
# The following parameter values are just placeholders, need to be updated.
manfid=0x2d0
prodid=0x0727
vendid=0x14e4
devid=0x43e2
boardtype=0x0727
boardrev=0x1101
boardnum=22
macaddr=00:90:4c:c5:12:38
sromrev=11
boardflags=0x00404201
boardflags3=0x08000000
xtalfreq=37400
nocrc=1
ag0=255
aa2g=1
ccode=ALL
pa0itssit=0x20
extpagain2g=0
#PA parameters for 2.4GHz, measured at CHIP OUTPUT
pa2ga0=-168,7161,-820
AvVmid_c0=0x0,0xc8
cckpwroffset0=5
# PPR params
maxp2ga0=84
txpwrbckof=6
cckbw202gpo=0
legofdmbw202gpo=0x66111111
mcsbw202gpo=0x77711111
propbw202gpo=0xdd
# OFDM IIR :
ofdmdigfilttype=18
ofdmdigfilttypebe=18
# PAPD mode:
papdmode=1
papdvalidtest=1
pacalidx2g=42
papdepsoffset=-22
papdendidx=58
# LTECX flags
ltecxmux=0
ltecxpadnum=0x0102
ltecxfnsel=0x44
ltecxgcigpio=0x01
il0macaddr=00:90:4c:c5:12:38
wl0id=0x431b
deadman_to=0xffffffff
# muxenab: 0x1 for UART enable, 0x2 for GPIOs, 0x8 for JTAG
muxenab=0x1
# CLDO PWM voltage settings - 0x4 - 1.1 volt
#cldo_pwm=0x4
#VCO freq 326.4MHz
spurconfig=0x3
edonthd20l=-75
edoffthd20ul=-80

45
arm/extra/zram Executable file
View File

@ -0,0 +1,45 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: zram
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: S
# Default-Stop: 0 1 6
# Short-Description: Use compressed RAM as in-memory swap
# Description: Use compressed RAM as in-memory swap
### END INIT INFO
# Author: Antonio Galea <antonio.galea@gmail.com>
# Thanks to Przemysław Tomczyk for suggesting swapoff parallelization
FRACTION=75
MEMORY=`perl -ne'/^MemTotal:\s+(\d+)/ && print $1*1024;' < /proc/meminfo`
CPUS=`grep -c processor /proc/cpuinfo`
SIZE=$(( MEMORY * FRACTION / 100 / CPUS ))
case "$1" in
"start")
param=`modinfo zram|grep num_devices|cut -f2 -d:|tr -d ' '`
modprobe zram $param=$CPUS
for n in `seq $CPUS`; do
i=$((n - 1))
echo $SIZE > /sys/block/zram$i/disksize
mkswap /dev/zram$i
swapon /dev/zram$i -p 10
done
;;
"stop")
for n in `seq $CPUS`; do
i=$((n - 1))
swapoff /dev/zram$i && echo "disabled disk $n of $CPUS" &
done
wait
sleep .5
modprobe -r zram
;;
*)
echo "Usage: `basename $0` (start | stop)"
exit 1
;;
esac

46
arm/init-arm Normal file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env zsh
#
# Devuan SDK - build management
#
# Copyright (C) 2015-2016 Dyne.org Foundation
# Copyright (C) 2016 parazyd <parazyd@dyne.org>
#
# Devuan SDK is designed, written and maintained by Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This source code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer
# to the GNU Public License for more details.
#
# You should have received a copy of the GNU Public License along with
# this source code; if not, write to: Free Software Foundation, Inc.,
# 675 Mass Ave, Cambridge, MA 02139, USA.
#
init-arm() {
fn init-arm $*
armdev="$1"
req=(armdev)
ckreq || {
error "No ARM device specified"
return 1
}
# Build scripts are mapped to a device name here
arm_map=(
"raspi2" "$R/arm/scripts/raspberry-pi-2.sh"
"bananapi" "$R/arm/scripts/bananapi.sh"
"cubieboard2" "$R/arm/scripts/cubieboard2.sh"
"chromeacer" "$R/arm/scripts/chromebook-acer.sh"
)
arm_build_device=${arm_map[$armdev]}
common="$R/arm/common"
source ${arm_build_device}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

20
arm/qemu-wrapper.c Normal file
View File

@ -0,0 +1,20 @@
/* qemu wrapper
* wrapper for executing qemu in build chroots
* pass arguments to qemu binary
*
* ~ parazyd */
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv, char **envp) {
char *newargv[argc + 3];
newargv[0] = argv[0];
newargv[1] = "-cpu";
newargv[2] = "cortex-a8"; /* here you can set the cpu you are building for */
memcpy(&newargv[3], &argv[1], sizeof(*argv) * (argc -1));
newargv[argc + 2] = NULL;
return execve("/usr/bin/qemu-arm", newargv, envp);
}

106
arm/scripts/bananapi.sh Executable file
View File

@ -0,0 +1,106 @@
#!/usr/bin/env zsh
#
# Devuan SDK - build management
#
# Copyright (C) 2015-2016 Dyne.org Foundation
# Copyright (C) 2016 parazyd <parazyd@dyne.org>
#
# Devuan SDK is designed, written and maintained by Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This source code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer
# to the GNU Public License for more details.
#
# You should have received a copy of the GNU Public License along with
# this source code; if not, write to: Free Software Foundation, Inc.,
# 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Devuan SDK build script for BananaPi devices (armhf)
# -- settings --
device_name="bananapi"
arch="armhf"
image_name="${os}-${release}-${version}-${arch}-${device_name}"
size=1337
extra_packages=()
# Ones below should not need changing
workdir="$R/arm/${device_name}-build"
strapdir="${workdir}/${os}-${arch}"
qemu_bin="/usr/bin/qemu-arm-static" # Devuan
#qemu_bin="/usr/bin/qemu-arm" # Gentoo
parted_boot=(fat32 2048s 264191s)
parted_root=(ext4 264192s 100%)
inittab="T1:12345:respawn:/sbin/agetty -L ttyS0 115200 vt100"
custmodules=(sunxi_emac)
# -- end settings --
# source common commands and add toolchain to PATH
source $common
${device_name}-build-kernel() {
fn ${device_name}-build-kernel
notice "Grabbing kernel sources"
cd ${workdir}
git clone --depth 1 https://github.com/LeMaker/u-boot-bananapi
git clone --depth 1 https://github.com/linux-sunxi/sunxi-tools
git clone --depth 1 https://github.com/LeMaker/sunxi-boards
sudo mkdir ${strapdir}/usr/src/kernel && sudo chown $USER ${strapdir}/usr/src/kernel
git clone --depth 1 https://github.com/LeMaker/linux-sunxi -b lemaker-3.4 ${strapdir}/usr/src/kernel
cd ${workdir}/sunxi-tools
make fex2bin
sudo ./fex2bin ${workdir}/sunxi-boards/sys_config/a20/BananaPi.fex ${workdir}/bootp/script.bin
copy-kernel-config
make -j `grep -c processor /proc/cpuinfo` uImage modules
make-kernel-modules
sudo rm -r ${strapdir}/lib/firmware
sudo chown $USER ${strapdir}/lib
get-kernel-firmware
cp -ra $R/tmp/firmware ${strapdir}/lib/firmware
cd $strapdir/usr/src/kernel
make INSTALL_MOD_PATH=${strapdir} firmware_install
sudo cp -v arch/arm/boot/uImage ${workdir}/bootp/
make mrproper
cp -v ../${device_name}.config .config
make modules_prepare
notice "Building u-boot..."
cd ${workdir}/u-boot-bananapi/
make distclean
make BananaPi_config
make -j $(grep -c processor /proc/cpuinfo)
notice "dd-ing to image..."
sudo $DD if=u-boot-sunxi-with-spl.bin of=$loopdevice bs=1024 seek=8
notice "Fixing up firmware..."
rm -rf ${strapdir}/lib/firmware
cp -ra $R/tmp/firmware ${strapdir}/lib/firmware
notice "Creating boot.cmd..."
cat <<EOF | sudo tee ${workdir}/bootp/boot.cmd
setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait panic=10 ${extra} rw rootfstype=ext4 net.ifnames=0
fatload mmc 0 0x43000000 script.bin
fatload mmc 0 0x48000000 uImage
fatload mmc 0 0x48000000 uImage
EOF
notice "Creating u-boot script image..."
sudo mkimage -A arm -T script -C none -d ${workdir}/bootp/boot.cmd ${workdir}/bootp/boot.scr
notice "Finished building kernel"
notice "Next step is: ${device_name}-finalize"
}

57
arm/scripts/chromebook-acer.sh Executable file
View File

@ -0,0 +1,57 @@
#!/usr/bin/env zsh
#
# Devuan SDK - build management
#
# Copyright (C) 2015-2016 Dyne.org Foundation
# Copyright (C) 2016 parazyd <parazyd@dyne.org>
#
# Devuan SDK is designed, written and maintained by Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This source code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer
# to the GNU Public License for more details.
#
# You should have received a copy of the GNU Public License along with
# this source code; if not, write to: Free Software Foundation, Inc.,
# 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Devuan SDK build script for BananaPi devices (armhf)
# -- settings --
device_name="bananapi"
arch="armhf"
image_name="${os}-${release}-${version}-${arch}-${device_name}"
size=1337
extra_packages=(wpasupplicant abootimg cgpt fake-hwclock u-boot-tools ntpdate)
extra_packages+=(vboot-tools vboot-utils vboot-kernel utils)
extra_packages+=(laptop-mode-tools usbutils dhcpcd5)
# Ones below should not need changing
workdir="$R/arm/${device_name}-build"
strapdir="${workdir}/${os}-${arch}"
qemu_bin="/usr/bin/qemu-arm-static" # Devuan
#qemu_bin="/usr/bin/qemu-arm" # Gentoo
parted_boot=(fat32 2048s 264191s)
parted_root=(ext4 264192s 100%)
inittab="T1:12345:respawn:/sbin/agetty -L ttyS0 115200 vt100"
custmodules=()
# -- end settings --
# source common commands and add toolchain to PATH
source $common
${device_name}-build-kernel() {
fn ${device_name}-build-kernel
notice "Grabbing kernel sources"
notice "Finished building kernel"
notice "Next step is: ${device_name}-finalize"
}

106
arm/scripts/cubieboard2.sh Executable file
View File

@ -0,0 +1,106 @@
#!/usr/bin/env zsh
#
# Devuan SDK - build management
#
# Copyright (C) 2015-2016 Dyne.org Foundation
# Copyright (C) 2016 parazyd <parazyd@dyne.org>
#
# Devuan SDK is designed, written and maintained by Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This source code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer
# to the GNU Public License for more details.
#
# You should have received a copy of the GNU Public License along with
# this source code; if not, write to: Free Software Foundation, Inc.,
# 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Devuan SDK build script for Cubieboard 2 devices (armhf)
# -- settings --
device_name="cubieboard2"
arch="armhf"
image_name="${os}-${release}-${version}-${arch}-${device_name}"
size=1337
extra_packages=()
# Ones below should not need changing
workdir="$R/arm/${device_name}-build"
strapdir="${workdir}/${os}-${arch}"
qemu_bin="/usr/bin/qemu-arm-static" # Devuan
#qemu_bin="/usr/bin/qemu-arm" # Gentoo
parted_boot=(fat32 2048s 264191s)
parted_root=(ext4 264192s 100%)
inittab="T1:12345:respawn:/sbin/agetty -L ttyS0 115200 vt100"
custmodules=(sunxi_emac)
# -- end settings --
# source common commands and add toolchain to PATH
source $common
${device_name}-build-kernel() {
fn ${device_name}-build-kernel
notice "Grabbing kernel sources"
cd ${workdir}
git clone --depth 1 https://github.com/linux-sunxi/u-boot-sunxi
git clone --depth 1 https://github.com/linux-sunxi/sunxi-tools
git clone --depth 1 https://github.com/linux-sunxi/sunxi-boards
sudo mkdir ${strapdir}/usr/src/kernel && sudo chown $USER ${strapdir}/usr/src/kernel
git clone --depth 1 https://github.com/linux-sunxi/linux-sunxi -b stage/sunxi-3.4 ${strapdir}/usr/src/kernel
cd ${workdir}/sunxi-tools
make fex2bin
sudo ./fex2bin ${workdir}/sunxi-boards/sys_config/a20/cubieboard2.fex ${workdir}/bootp/script.bin
copy-kernel-config
make -j `grep -c processor /proc/cpuinfo` uImage modules
make-kernel-modules
sudo rm -r ${strapdir}/lib/firmware
sudo chown $USER ${strapdir}/lib
get-kernel-firmware
cp -ra $R/tmp/firmware ${strapdir}/lib/firmware
cd $strapdir/usr/src/kernel
make INSTALL_MOD_PATH=${strapdir} firmware_install
sudo cp -v arch/arm/boot/uImage ${workdir}/bootp/
make mrproper
cp -v ../${device_name}.config .config
make modules_prepare
notice "Building u-boot..."
cd ${workdir}/u-boot-sunxi/
make distclean
make Cubieboard2_config
make -j $(grep -c processor /proc/cpuinfo)
notice "dd-ing to image..."
sudo $DD if=u-boot-sunxi-with-spl.bin of=$loopdevice bs=1024 seek=8
notice "Fixing up firmware..."
rm -rf ${strapdir}/lib/firmware
cp -ra $R/tmp/firmware ${strapdir}/lib/firmware
notice "Creating boot.cmd..."
cat <<EOF | sudo tee ${workdir}/bootp/boot.cmd
setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait panic=10 ${extra} rw rootfstype=ext4 net.ifnames=0
fatload mmc 0 0x43000000 script.bin
fatload mmc 0 0x48000000 uImage
fatload mmc 0 0x48000000 uImage
EOF
notice "Creating u-boot script image..."
sudo mkimage -A arm -T script -C none -d ${workdir}/bootp/boot.cmd ${workdir}/bootp/boot.scr
notice "Finished building kernel"
notice "Next step is: ${device_name}-finalize"
}

121
arm/scripts/raspberry-pi-2.sh Executable file
View File

@ -0,0 +1,121 @@
#!/usr/bin/env zsh
#
# Devuan SDK - build management
#
# Copyright (C) 2015-2016 Dyne.org Foundation
# Copyright (C) 2016 parazyd <parazyd@dyne.org>
#
# Devuan SDK is designed, written and maintained by Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This source code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer
# to the GNU Public License for more details.
#
# You should have received a copy of the GNU Public License along with
# this source code; if not, write to: Free Software Foundation, Inc.,
# 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Devuan SDK build script for Raspberry Pi 2 devices (armhf)
# -- settings --
device_name="raspi2"
arch="armhf"
image_name="${os}-${release}-${version}-${arch}-${device_name}"
size=1337
extra_packages=(wpasupplicant ntpdate)
# Ones below should not need changing
workdir="$R/arm/${armdev}-build"
strapdir="${workdir}/${os}-${arch}"
qemu_bin="/usr/bin/qemu-arm-static" # Devuan, install qemu-user-static
#qemu_bin="/usr/bin/qemu-arm" # Gentoo, compile with USE=static-user
#enable_qemu_wrapper=1 # Uncomment this to enable qemu-wrapper (consult the readme)
parted_boot=(fat32 0 64)
parted_root=(ext4 64 -1)
inittab="T0:23:respawn:/sbin/agetty -L ttyAMA0 115200 vt100"
custmodules=()
# -- end settings --
# source common commands and add toolchain to PATH
source $common
${device_name}-build-kernel() {
fn ${device_name}-build-kernel
notice "Grabbing kernel sources"
sudo mkdir ${strapdir}/usr/src/kernel && sudo chown $USER ${strapdir}/usr/src/kernel
cd ${strapdir}/usr/src
git clone --depth 1 \
https://github.com/raspberrypi/linux \
-b rpi-4.1.y \
${strapdir}/usr/src/kernel
cd ${strapdir}/usr/src/kernel
copy-kernel-config
make -j `grep -c processor /proc/cpuinfo`
make-kernel-modules
notice "Grabbing rpi-firmware..."
git clone --depth 1 \
https://github.com/raspberrypi/firmware.git \
rpi-firmware
sudo cp -rfv rpi-firmware/boot/* ${workdir}/bootp/
sudo perl scripts/mkknlimg --dtok arch/arm/boot/zImage ${workdir}/bootp/kernel7.img
sudo cp -v arch/arm/boot/dts/bcm*.dtb ${workdir}/bootp/
sudo cp -v arch/arm/boot/dts/overlays/*overlay*.dtb ${workdir}/bootp/overlays/
sudo rm -rfv ${strapdir}/lib/firmware
get-kernel-firmware
sudo chown $USER ${strapdir}/lib
cp -ra $R/tmp/firmware ${strapdir}/lib/firmware
cd $strapdir/usr/src/kernel
make INSTALL_MOD_PATH=${strapdir} firmware_install
make mrproper
cp -v ../${device_name}.config .config
make modules_prepare
notice "Creating cmdline.txt..."
cat <<EOF | sudo tee ${workdir}/bootp/cmdline.txt
dwc_otg.fiq_fix_enable=2 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait rootflags=noload net.ifnames=0
EOF
sudo rm -rf rpi-firmware && notice "Removed rpi-firmware leftovers"
cd ${workdir}
#notice "Cleaning up from kernel build..."
#sudo rm -r ${strapdir}/usr/src/kernel
#sudo rm ${strapdir}/usr/src/${device_name}.config
notice "Installing raspi-config..."
sudo cp ${workdir}/../extra/rpi-conf/raspi-config ${strapdir}/usr/bin/raspi-config \
&& notice "RPi-config: Installed script"
sudo mkdir ${strapdir}/usr/lib/raspi-config
sudo cp ${workdir}/../extra/rpi-conf/init_resize.sh ${strapdir}/usr/lib/raspi-config/init_resize.sh \
&& notice "RPi-config: Installed init_resize"
sudo cp ${workdir}/../extra/rpi-conf/raspi-config-init ${strapdir}/etc/init.d/raspi-config
pushd ${strapdir}/etc/rcS.d
sudo ln -s ../init.d/raspi-config S18raspi-config \
&& notice "RPi-config: Installed governor initscript"
popd
notice "Installing RaspberryPi3 firmware for bt/wifi"
sudo mkdir -p ${strapdir}/lib/firmware/brcm
sudo cp -v ${workdir}/../extra/rpi3/brcmfmac43430-sdio.txt ${strapdir}/lib/firmware/brcm/
sudo cp -v ${workdir}/../extra/rpi3/brcmfmac43430-sdio.bin ${strapdir}/lib/firmware/brcm/
notice "Finished building kernel."
notice "Next step is: ${device_name}-finalize"
}

857
arm/zuper Executable file
View File

@ -0,0 +1,857 @@
#!/usr/bin/env zsh
## -*- origami-fold-style: triple-braces -*-
#
# Zuper - Zsh Ultimate Programmer's Extensions Refurbished
#
# Copyright (C) 2015 Dyne.org Foundation
#
# Zuper is designed, written and maintained by Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This source code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# Please refer to the GNU Public License for more details.
#
# You should have received a copy of the GNU Public License along with
# this source code; if not, write to:
# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##########################
typeset -aU vars
typeset -aU arrs
typeset -aU maps
vars=(DEBUG QUIET LOG)
arrs=(req freq)
vars+=(zuper_version)
zuper_version=0.2
zmodload zsh/system
zmodload zsh/net/tcp
# {{{ Messaging
# Messaging function with pretty coloring
autoload colors
colors
vars+=(last_act last_func last_notice)
function _msg() {
local msg="$2"
command -v gettext 1>/dev/null 2>/dev/null && msg="$(gettext -s "$2")"
for i in $(seq 3 ${#});
do
msg=${(S)msg//::$(($i - 2))*::/$*[$i]}
done
local command="print -P"
local progname="$fg[magenta]${PROGRAM##*/}$reset_color"
local message="$fg_bold[normal]$fg_no_bold[normal]$msg$reset_color"
local -i returncode
case "$1" in
inline)
command+=" -n"; pchars=" > "; pcolor="yellow"
;;
message)
last_act="$msg"
pchars=" . "; pcolor="white"; message="$fg_no_bold[$pcolor]$msg$reset_color"
;;
verbose)
last_func="$msg"
pchars="[D]"; pcolor="blue"
;;
success)
last_notice="$msg"
pchars="(*)"; pcolor="green"; message="$fg_no_bold[$pcolor]$msg$reset_color"
;;
warning)
pchars="[W]"; pcolor="yellow"; message="$fg_no_bold[$pcolor]$msg$reset_color"
;;
failure)
pchars="[E]"; pcolor="red"; message="$fg_no_bold[$pcolor]$msg$reset_color"
returncode=1
;;
print)
progname=""
;;
*)
pchars="[F]"; pcolor="red"
message="Developer oops! Usage: _msg MESSAGE_TYPE \"MESSAGE_CONTENT\""
returncode=127
zerr
;;
esac
${=command} "${progname} $fg_bold[$pcolor]$pchars$reset_color ${message}$color[reset_color]" >&2
# write the log if its configured
[[ "$LOG" = "" ]] || {
touch $LOG || return $?
${=command} "${progname} $fg_bold[$pcolor]$pchars$reset_color ${message}$color[reset_color]" >> $LOG
}
return $returncode
}
function _message say act() {
local notice="message"
[[ "$1" = "-n" ]] && shift && notice="inline"
[[ $QUIET = 1 ]] || _msg "$notice" $@
return 0
}
function _verbose xxx func() {
[[ $DEBUG = 1 ]] && _msg verbose $@
return 0
}
function _success yes notice() {
[[ $QUIET = 1 ]] || _msg success $@
return 0
}
function _warning no warn warning() {
[[ $QUIET = 1 ]] || _msg warning $@
return 0
}
function _failure fatal die error() {
# typeset -i exitcode=${exitv:-1}
[[ $QUIET = 1 ]] || _msg failure $@
return 1
}
function _print() {
[[ $QUIET = 1 ]] || _msg print $@
return 0
}
# }}} Messaging
# {{{ Debugging
fn() {
fun="$@"
req=()
freq=()
func "$fun"
}
zerr() {
error "error in: ${fun:-$last_notice}"
[[ "$last_func" = "" ]] || warn "called in: $last_func"
[[ "$last_act" = "" ]] || warn "called in: $last_act"
[[ "$last_notice" = "" ]] || warn "called in: $last_notice"
# [[ "$fun" = "" ]] || warn "called in: $fun"
TRAPEXIT() {
error "error reported, operation aborted."
}
return 1
}
ckreq reqck() {
err=0
for v in $req; do
[[ "${(P)v}" = "" ]] && {
warn "${fun[(ws: :)1]}(): required setting is blank: $v"
err=1
}
done
[[ $err = 1 ]] && return $err
for f in $freq; do
# exists and has size greater than zero
[[ -s $f ]] || {
warn "required file empty: $f"
err=1
}
done
[[ $err == 1 ]] && zerr
return $err
}
zdump() {
fn zdump
[[ ${#vars} -gt 0 ]] && {
print "Global variables:"
for _v in $vars; do
print " $_v = \t ${(P)_v}"
done
}
[[ ${#arrs} -gt 0 ]] && {
print "Global arrays:"
for _a in $arrs; do
print " $_a \t ( ${(P)_a} )"
done
}
[[ ${#maps} -gt 0 ]] && {
print "Global maps:"
for _m in $maps; do
print " $_m [key] \t ( ${(Pk)_m} )"
print " $_m [val] \t ( ${(Pv)_m} )"
done
}
}
# handy wrappers for throw/catch execution of blocks where we need the
# program to exit on any error (non-zero) returned by any function
throw() { function TRAPZERR() { zerr; return 1 } }
catch() { function TRAPZERR() { } }
##########################
# Endgame handling
arrs+=(destruens)
destruens=()
# Trap functions for the endgame event
TRAPINT() { endgame INT; return $? }
# TRAPEXIT() { endgame EXIT; return $? }
TRAPHUP() { endgame HUP; return $? }
TRAPQUIT() { endgame QUIT; return $? }
TRAPABRT() { endgame ABORT; return $? }
TRAPKILL() { endgame KILL; return $? }
# TRAPPIPE() { endgame PIPE; return $? }
TRAPTERM() { endgame TERM; return $? }
TRAPSTOP() { endgame STOP; return $? }
# TRAPZERR() { func "function returns non-zero." }
endgame() {
fn "endgame $*"
# execute all no matter what
TRAPZERR() { }
# process registered destructors
for d in $destruens; do
fn "destructor: $d"
$d
done
return 0
}
# Register endgame() to be called at exit.
# unlike TRAPEXIT, the zshexit() hook is not called when functions exit.
zshexit() { endgame EXIT; return $? }
# }}} Debugging
# {{{ Tempfiles
##########################
# Temp file handling
vars+=(ztmpfile)
# ztmp() fills in $ztmpfile global. Caller must copy that variable as
# it will be overwritten at every call.
ztmp() {
fn ztmp
ztmpfile=`mktemp`
tmpfiles+=($ztmpfile)
}
# All tempfiles are freed in endgame()
_ztmp_destructor() {
fn _ztmp_destructor
for f in $tmpfiles; do
rm -f "$f"
done
tmpfiles=()
}
arrs+=(tmpfiles)
destruens+=(_ztmp_destructor)
# }}} Tempfiles
# {{{ Strings
# tokenizer, works only with one char length delimiters
# saves everything in global array tok=()
arrs+=(tok)
strtok() {
fn "strtok $*"
_string="$1"
_delim="$2"
req=(_string _delim)
ckreq || return $?
tok=()
f=0
c=0
for c in {1..${#_string}}; do
if [[ "${_string[(e)$c]}" == "$_delim" ]]; then
# check if not empty
t=${_string[(e)$(($f + 1)),$(($c - 1))]}
[[ "$t" == "" ]] || tok+=($t)
# save last found
f=$c
fi
done
# add last token
t=${_string[(e)$(($f + 1)),$c]}
[[ "$t" == "" ]] || tok+=($t)
}
# TODO: move in here some helpers
# }}} Strings
# {{{ Networking
# This is only tested on GNU/Linux and makes use of sysfs
# index of all network devices
arrs+=(net_devices)
# map of ipv4 assigned addresses: [dev addr]
maps+=(net_ip4_addr)
# map of ipv6 assigned addresses: [dev addr]
maps+=(net_ip6_addr)
# map of dhcp served ipv4
maps+=(ip4dhcps)
# map of dhcp served ipv6
maps+=(ip6dhcps)
# map of external ipv4 addresses
maps+=(net_ip4_exit)
# map of internal ipv6 addresses
# maps+=(ip6exits)
net.scan_devices() {
for i in `find /sys/devices/ -name net`; do
dev=`ls $i`
# skip the loopback device
[[ "$dev" = "lo" ]] && continue
net_devices+=($dev)
done
# return error if no device found
if [[ ${#net_devices} = 0 ]]; then return 1
else return 0; fi
}
net.scan_addresses() {
[[ ${#net_devices} = 0 ]] && {
error "No network device found."
func "Have you ran net.scan_devices() first?"
return 1
}
for dev in ${net_devices}; do
# check ipv4 connections
conn=`ip addr show $dev | awk '/inet / {print $2}'`
[[ "$conn" = "" ]] || {
net_ip4_addr+=($dev $conn) }
# check ipv6 connections
conn=`ip addr show $dev | awk '/inet6/ {print $2}'`
[[ "$conn" = "" ]] || {
net_ip6_addr+=($dev $conn) }
done
# list ipv4
notice "${#net_ip4_addr} ipv4 connected devices found"
for c in ${(k)net_ip4_addr}; do
act " $c ${net_ip4_addr[$c]}"
done
# list ipv6
notice "${#net_ip6_addr} ipv6 connected devices found"
for c in ${(k)net_ip6_addr}; do
act " $c ${net_ip6_addr[$c]}"
done
# find out network addresses
return 0
}
net.scan_exits() {
# just ipv4 for now, also we use curl to drive the call over the
# specific interface, but if that wouldn't matter then rest.get is
# better to avoid this dependency
for dev in ${(k)net_ip4_addr}; do
addr=`curl --silent --interface $dev https://api.ipify.org`
if [[ "$?" != "0" ]]; then
error "curl returns $?: $addr"
else
[[ "$addr" = "" ]] || {
notice "$dev external ip: $addr"
net_ip4_exit+=($dev $addr)
}
fi
done
for dev in ${(k)net_ip6_addr}; do
addr=`curl --silent --ipv6 --interface $dev https://api.ipify.org`
if [[ $? != 0 ]]; then
error "curl returns $?: $addr"
else
[[ "$addr" = "" ]] || {
notice "$dev external ip: $addr"
net_ip4_exit+=($dev $addr)
}
fi
done
}
# }}} Networking
# {{{ Key/Value filesave
# optional: define zkv=1 on source
[[ "$zkv" = "" ]] || {
##########################
# Key/Value file storage using ZSh associative maps
# load a map from a file
# map must be already instantiated with typeset -A by called
# name of map is defined inside the file
function zkv.load() {
fn "zkv-load $*"
file=$1
[[ "$file" = "" ]] && {
error "zkv-open() missing argument: file-path"
zerr
return 1 }
[[ -r "$file" ]] || {
error "zkv-open() file not found $file"
zerr
return 1 }
[[ -s "$file" ]] || {
error "zkv-open() file is empty"
zerr
return 1 }
source $file
}
# save a map in a file
# $1 = name of the map associative array
# $2 = full path to the file
function zkv.save() {
fn "zkv.save $*"
_map=$1
_path=$2
[[ "$_path" = "" ]] && {
error "zkv.save() missing argument: map-name path-to-file"
zerr
return 1
}
[[ -r $_path ]] && {
func "zkv.close() overwriting $_path"
func "backup turd left behind: ${_path}~"
mv $_path $_path~
}
touch $_path
# wondering about http://www.zsh.org/mla/users/2015/msg00286.html
# meanwhile solved using a double array, wasting a full map memcpy
_karr=(${(Pk)_map})
_varr=(${(Pv)_map})
_num="${#_karr}"
for c in {1..$_num}; do
# can also be cat here, however for speed we use builtins
# switch to cat if compatibility is an issue
sysread -o 1 <<EOF >> $_path
$_map+=("${_karr[$c]}" "${(v)_varr[$c]}")
EOF
done
func "$_num key/values stored in $_path"
}
}
# }}} Key/Value filesave
# {{{ Get/Set REST API
########
# Restful API client
# there is a clear zsh optimization here in get/set kv
# using zsh/tcp instead of spawning curl
# and perhaps querying with one call using ?recursive
vars+=(rest_reply_body rest_reply_header)
maps+=(rest_header)
function rest.put() {
fn "rest.put $*"
# $1 = hostname
# $2 = port
# $3 = path
# value from stdin |
# to check if the http service is running is up to the caller
_host=${1} # ip address
_port=${2}
_path=${3}
sysread _v
req=(_host)
ckreq || return $?
if ztcp $_host $_port; then
# TODO: work out various parsers, this one works with consul.io
_fd=$REPLY
# func "tcp open on fd $fd"
cat <<EOF >& $_fd
PUT ${_path} HTTP/1.1
User-Agent: Zuper/$zuper_version
Host: ${_host}:${_port}
Accept: */*
Content-Length: ${#_v}
Content-Type: application/x-www-form-urlencoded
EOF
print -n "$_v" >& $_fd
sysread -i $_fd _res
# close connection
ztcp -c $_fd
[[ "$_res" =~ "true" ]] || {
warn "failed PUT on restful key/value"
warn "host: ${_host}"
warn "port: ${_port}"
warn "path: ${_path}"
warn "value: $_v"
print - "$_res"
zerr
return 1
}
else
error "cannot connect to restful service: $_host:$_port"
zerr
return 1
fi
return 0
}
function rest.get() {
fn "rest.get $*"
_host=${1}
_port=${2}
_path=${3}
req=(_host _port)
ckreq || return $?
ztcp $_host $_port || {
zerr
return 1
}
_fd=$REPLY
# TODO: work out various parsers, this one works with consul.io
cat <<EOF >& $_fd
GET ${_path} HTTP/1.1
User-Agent: Zuper/$zuper_version
Host: $_host:$_port
Accept: */*
EOF
# read header response
rest_reply=`sysread -i $_fd -o 1`
for i in "${(f)rest_reply}"; do
print $i | hexdump -C
# first line is the response code
[[ "$i" -regex-match "\x0d\x0a$" ]] && {
func BLANK
break }
# # save other lines in map for fast retrieval
# _field=${i[(ws@:@)1]}
# func "$_field - header field parsed"
# rest_header[$_field]="${i[(ws@:@)2]}"
# c=$(( $c + 1 ))
done
# rest_reply_header="${(f)$(cat <&$_fd)}"
func "${#rest_reply_header} bytes response header stored in rest_reply_header"
# | awk -F: '
#/"Value":/ { gsub(/"|}]/,"",$7) ; print $7 }' | base64 -d
# TODO: read content-length and use it here
rest_reply_body="${(f)$(sysread -i $_fd -o 1)}"
func "${#rest_reply_body} bytes response body stored in rest_reply_body"
# close connection
ztcp -c $_fd
return 0
}
# }}} Get/Set REST API
# {{{ Helpers
[[ "$helpers" = "" ]] || {
function helper.isfound isfound() {
command -v $1 1>/dev/null 2>/dev/null
return $?
}
# remote leading and trailing spaces in a string taken from stdin
function helper.trim trim() {
sed -e 's/^[[:space:]]*//g ; s/[[:space:]]*\$//g'
}
zmodload zsh/mapfile
# faster substitute for cat
function helper.printfile printfile() {
print ${mapfile[$1]}
}
# extract all emails found in a text from stdin
# outputs them one per line
function helper.extract-emails extract_emails() {
awk '{ for (i=1;i<=NF;i++)
if ( $i ~ /[[:alnum:]]@[[:alnum:]]/ ) {
gsub(/<|>|,/ , "" , $i); print $i } }'
}
zmodload zsh/regex
# takes a string as argument, returns success if is an email
function helper.isemail isemail() {
[[ "$1" -regex-match "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" ]] && return 0
return 1
}
# takes a numeric argument and prints out a human readable size
function helper.human-size human_size() {
[[ $1 -gt 0 ]] || {
error "human_size() called with invalid argument"
return 1
}
# we use the binary operation for speed
# shift right 10 is divide by 1024
# gigabytes
[[ $1 -gt 1073741824 ]] && {
print -n "$(( $1 >> 30 )) GB"
return 0
}
# megabytes
[[ $1 -gt 1048576 ]] && {
print -n "$(( $1 >> 20 )) MB"
return 0
}
# kilobytes
[[ $1 -gt 1024 ]] && {
print -n "$(( $1 >> 10 )) KB"
return 0
}
# bytes
print -n "$1 Bytes"
return 0
}
# strips out all html/xml tags (everything between < >)
function helper.html-strip xml_strip html_strip() { sed 's/<[^>]\+>//g' }
# changes stdin string special chars to be shown in html
function helper.escape-html escape_html() {
sed -e '
s/\&/\&amp;/g
s/>/\&gt;/g
s/</\&lt;/g
s/"/\&quot;/g
'
}
# escapes special chars in urls
function helper.decode-url decode_url urldecode() {
sed -e '
s/%25/%/gi
s/%20/ /gi
s/%09/ /gi
s/%21/!/gi
s/%22/"/gi
s/%23/#/gi
s/%24/\$/gi
s/%26/\&/gi
s/%27/'\''/gi
s/%28/(/gi
s/%29/)/gi
s/%2a/\*/gi
s/%2b/+/gi
s/%2c/,/gi
s/%2d/-/gi
s/%2e/\./gi
s/%2f/\//gi
s/%3a/:/gi
s/%3b/;/gi
s/%3d/=/gi
s/%3e//gi
s/%3f/?/gi
s/%40/@/gi
s/%5b/\[/gi
s/%5c/\\/gi
s/%5d/\]/gi
s/%5e/\^/gi
s/%5f/_/gi
s/%60/`/gi
s/%7b/{/gi
s/%7c/|/gi
s/%7d/}/gi
s/%7e/~/gi
s/%09/ /gi
'
}
function helper.encode-url encode_url urlencode() {
sed -e '
s/%/%25/g
s/ /%20/g
s/ /%09/g
s/!/%21/g
s/"/%22/g
s/#/%23/g
s/\$/%24/g
s/\&/%26/g
s/'\''/%27/g
s/(/%28/g
s/)/%29/g
s/\*/%2a/g
s/+/%2b/g
s/,/%2c/g
s/-/%2d/g
s/\./%2e/g
s/\//%2f/g
s/:/%3a/g
s/;/%3b/g
s//%3e/g
s/?/%3f/g
s/@/%40/g
s/\[/%5b/g
s/\\/%5c/g
s/\]/%5d/g
s/\^/%5e/g
s/_/%5f/g
s/`/%60/g
s/{/%7b/g
s/|/%7c/g
s/}/%7d/g
s/~/%7e/g
s/ /%09/g
'
}
}
# }}} Helpers
# {{{ Config
# This is not a full config parser, but its a mechanism to read single
# sections of configuration files that are separated using various
# syntax methods. The only method supported is now org-mode whose
# sections start with #+ . It fills in the global array
# $config_section which can be read out to a file or interpreted in
# memory, whatever syntax it may contain.
vars+=(config_section_type)
arrs+=(config_section)
config_section_type=org-mode
config.section.type() {
fn config.section.type
_type=$1
req=(_type)
ckreq || return $?
case $_type in
org-mode)
config_section_type=org-mode
;;
*)
error "Unknown config type:$_type"
return 1
;;
esac
act "$_type config section parser initialized"
return 0
}
# fills in contents of section in array config_section
config.section.read() {
fn config.section.read
_file=$1
_section=$2
req=(_file _section)
freq=($_file)
ckreq || return $?
case $config_section_type in
org-mode)
_contents=`awk '
BEGIN { found=0 }
/^#\+ '"$_section"'/ { found=1; next }
/^#\+/ { if(found==1) exit 0 }
/^$/ { next }
{ if(found==1) print $0 }
' $_file`
;;
*)
error "Unknown config type:$_type"
;;
esac
config_section=()
for c in ${(f)_contents}; do
config_section+=("$c")
done
return 0
}
# }}} Config

35
arm/zuper.init Normal file
View File

@ -0,0 +1,35 @@
##########################
# Zuper Init
# initialize globals only after sourcing everything
# since zlibs may contain more variable declarations
for _v in $vars; do
typeset -h $_v
done
for _a in $arrs; do
typeset -aU $_a
done
for _m in $maps; do
typeset -A $_m
done
# reset defaults
DEBUG=${DEBUG:-0}
QUIET=${QUIET:-0}
LOG=${LOG:-""}
req=()
freq=()
last_act=()
last_func=()
last_notice=()
tmpfiles=()
config_section=()
config_section_type=${config_section_type:-org-mode}
func "Zuper $zuper_version initialized"
func "${#vars} global variables registered"
func "${#arrs} global arrays registered"
func "${#maps} global maps registered"

29
config Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env zsh
# Devuan SDK configuration
# safe to leave untouched
# syntax: variable=value
# (no spaces before and after the equal sign)
os=devuan
release=jessie
section=main
version=alpha4
mirror=http://packages.devuan.org/merged
# add here the info of the toolchain you are using
# custom toolchain
compiler="arm-linux-gnueabihf-"
export PATH="$PATH:/sbin:$R/toolchains/gcc-arm-linux-gnueabihf-4.7/bin"
# devuan default toolchain
#compiler="arm-none-eabi-"
#export PATH="$PATH:/sbin"
core_packages=(debian-keyring devuan-keyring)
core_packages+=(git-core binutils ca-certificates initramfs-tools u-boot-tools)
core_packages+=(locales console-common less nano git curl)
base_packages=(bzip2 dialog apt-utils fakeroot e2fsprogs parted)
system_packages=(sysvinit ssh)

73
sdk Executable file
View File

@ -0,0 +1,73 @@
#!/usr/bin/env zsh
# Devuan SDK
# Copyright (C) 2015-2016 Dyne.org Foundation
#
# Devuan SDK is written and maintained by Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This source code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer
# to the GNU Public License for more details.
#
# You should have received a copy of the GNU Public License along with
# this source code; if not, write to: Free Software Foundation, Inc.,
# 675 Mass Ave, Cambridge, MA 02139, USA.
# reqs: curl, gnupg2, sudo, debootstrap
# setup zsh options
setopt pushdsilent
# load zsh modules
zmodload zsh/system
zmodload zsh/regex
# adopts Zsh extension "Zuper"
zkv=1
helpers=1
source arm/zuper
## declare global variables
# config variables
vars+=(os mirror release section version)
#
# global variables
vars+=(R sdk_loaded)
# we assume source sdk is always run from the source dir
# which is the "root" of the program, $R, or env DEVUAN_SDK
R=${ARM:-`pwd`}
#
# global maps (TODO in zuper)
maps+=(arm_map)
source config
# load all zlibs
source arm/init-arm
# complete zuper initialization
source arm/zuper.init
# unset DEBUG_BEFORE_CMD
# exit on error of any function
TRAPZERR() { zerr; return $? }
if [[ $sdk_loaded = 1 ]]; then
act "ARM SDK reloaded"
else
notice "ARM SDK loaded"
typeset -h sdk_loaded
sdk_loaded=1
export RPROMPT=ARM SDK
fi