diff --git a/raspi-hacks/README b/raspi-hacks/README index 91ed2c8..8aaaf2d 100644 --- a/raspi-hacks/README +++ b/raspi-hacks/README @@ -9,13 +9,22 @@ lines' entries s0, s1 and s2. The Rasberry Pi's UART is /dev/ttyAMA0, not * Clock - the Raspberry Pi has no hardware clock and boots with the date/time set to 1970-01-01, so /etc/rc.d/rc.local will be modified to -set the correct date/time from the network (using the 'sntp' command). -Also, to provide a pragmatic approximation for the correct date/time -during early boot and if the network is unavailable, /sbin/hwclock will be -replaced by a shellscript which saves the date/time to disk on shutdown -and restores it on startup. This prevents the error 'Cannot access the -Hardware Clock via any known method'. +set the correct date/time from the network (using the 'sntp' command). +Additionally, the file /etc/e2fsck.conf will be created to stop e2fsck +from erroring or requiring manual intervention when it encounters bad time +stamps. The fakeclock mechanism in a previous version of this package is +no longer used, and the original hwclock command will be restored when you +upgrade this package. This reinstates the error 'Cannot access the +Hardware Clock via any known method' :-) * Tuning - /etc/sysctl.conf will be created to tune vm.min_free_kbytes. This prevents the error 'smsc95xx 1-1.1:1.0: eth0: kevent 2 may have been dropped'. + +* libcofi_rpi - The library /usr/lib/libcofi_rpi.so contains teh_orph's +replacement memcpy and memset functions. These replacements have been +reported to improve application performance. They are disabled by default, +but if you want to enable them, use this command and then log out and log +in again: + + chmod ugo-x /etc/profile.d/libcofi_rpi.{sh,csh} diff --git a/raspi-hacks/doinst.sh b/raspi-hacks/doinst.sh new file mode 100644 index 0000000..21e47e3 --- /dev/null +++ b/raspi-hacks/doinst.sh @@ -0,0 +1,24 @@ +config() { + NEW="$1" + OLD="$(dirname $NEW)/$(basename $NEW .new)" + # If there's no config file by that name, mv it over: + if [ ! -r $OLD ]; then + mv $NEW $OLD + elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then + # toss the redundant copy + rm $NEW + fi + # Otherwise, we leave the .new copy for the admin to consider... +} + +preserve_perms() { + NEW="$1" + OLD="$(dirname $NEW)/$(basename $NEW .new)" + if [ -e $OLD ]; then + cp -a $OLD ${NEW}.incoming + cat $NEW > ${NEW}.incoming + mv ${NEW}.incoming $NEW + fi + config $NEW +} + diff --git a/raspi-hacks/e2fsck.conf.new b/raspi-hacks/e2fsck.conf.new new file mode 100644 index 0000000..f8b5b89 --- /dev/null +++ b/raspi-hacks/e2fsck.conf.new @@ -0,0 +1,3 @@ +[options] + accept_time_fudge = 1 + broken_system_clock =1 diff --git a/raspi-hacks/fakeclock.sh b/raspi-hacks/fakeclock.sh deleted file mode 100644 index d36bcc4..0000000 --- a/raspi-hacks/fakeclock.sh +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/sh - -# fakeclock.sh -# Script to save and restore system clock if there's no hardware clock -# -# Copyright 2012 David Spencer, Baildon, West Yorkshire, U.K. -# All rights reserved. -# -# Redistribution and use of this script, with or without modification, is -# permitted provided that the following conditions are met: -# -# 1. Redistributions of this script must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED -# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO -# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# NOTES: -# -# This script is a limited drop-in replacement of util-linux's hwclock, for use -# on systems that don't have a proper hardware clock. It is intended to be -# called from Slackware's rc scripts by moving /sbin/hwclock to hwclock.orig -# and replacing hwclock with a symlink to this script; the Slackware rc scripts -# do not need to be modified. -# -# The only control argument recognised is --hctosys. All other arguments -# are ignored. -# -# If --hctosys is present, the system clock is set from the last mount -# date/time of the root filesystem (if it's ext2/3/4), or the newest file in -# /var/log (if that exists), or the file /etc/fakeclock (if that exists). -# -# Otherwise, the system clock is saved by touching the file /etc/fakeclock. -# -# The script will only set the system clock when the system clock currently is -# before the year 1971. This permits the safe use of this script if an RTC is -# present but unreliable (e.g. a failing battery). - -action='save' -while [ "$#" != 0 ] -do - case "$1" - in - "--hctosys") action='restore' ;; - *) ;; - esac - shift -done - -if [ "$action" = 'restore' ]; then - - if [ $(date '+%Y') -lt '1971' ]; then - - # We'll work in big-endian numeric strings (i.e. +%Y%m%d%H%M%S) so they - # can be compared as integers. First, set a catch-all default: - mydate='197101010000' - - # Try the root filesystem. This is a good option because it prevents - # fsck complaining in the next bit of rc.S. - rtype=$(mount | fgrep '/dev/root' | cut -f5 -d' ') - if [ "$rtype" = 'ext4' -o "$rtype" = 'ext3' -o "$rtype" = 'ext2' ]; then - fsdate=$(date --date="$(dumpe2fs -h /dev/root 2>/dev/null | fgrep 'Last mount time' | cut -c27-50)" '+%Y%m%d%H%M%S') - [ "$fsdate" -gt "$mydate" ] && mydate="$fsdate" - fi - - # Try /var/log, but won't get anything if it's on a separate fs. - if [ -d /var/log ]; then - newest=$(ls -t /var/log 2>/dev/null | head -1) - if [ -n "$newest" ]; then - vldate=$(TZ=0 stat -c %y /var/log/"$newest" | cut -c '1-4,6-7,9-10,12-13,15-16,18-19') - [ "$vldate" -gt "$mydate" ] && mydate="$vldate" - fi - fi - - # If we were shutdown cleanly, this will exist: - if [ -f /etc/fakeclock ]; then - fkdate=$(TZ=0 stat -c %y /etc/fakeclock | cut -c '1-4,6-7,9-10,12-13,15-16,18-19') - [ "$fkdate" -gt "$mydate" ] && mydate="$fkdate" - fi - - echo 'fakeclock.sh: Setting fallback date/time.' - date --utc "${mydate:4:8}${mydate:0:4}.${mydate:12:2}" - - fi - - # We still need the original hwclock to set the system timezone. - /sbin/hwclock.orig --systz - -else - # save - touch /etc/fakeclock -fi - -exit 0 diff --git a/raspi-hacks/libcofi_rpi/Makefile b/raspi-hacks/libcofi_rpi/Makefile new file mode 100644 index 0000000..54753de --- /dev/null +++ b/raspi-hacks/libcofi_rpi/Makefile @@ -0,0 +1,6 @@ +libcofi_rpi.so: memcpy.o memset.o + $(CC) -o libcofi_rpi.so -shared memcpy.o memset.o -g +memset.o: memset.s + $(AS) memset.s -o memset.o -g +memcpy.o: memcpy.s + $(AS) memcpy.s -o memcpy.o -g diff --git a/raspi-hacks/libcofi_rpi/README.libcofi_rpi b/raspi-hacks/libcofi_rpi/README.libcofi_rpi new file mode 100644 index 0000000..ad4dc2c --- /dev/null +++ b/raspi-hacks/libcofi_rpi/README.libcofi_rpi @@ -0,0 +1,59 @@ +copies-and-fills + +SUMMARY + +Replacement memcpy and memset functionality for the Raspberry Pi with the intention of gaining greater performance. +Coding with an understanding of single-issue is important. + +Tested using a modified https://github.com/ssvb/ssvb-membench, from Siarhei Siamashka. +The testing involves lots of random numbers, iterating through sizes and source/destination alignments. +If you find a bug, please tell me! + +To use: define the environment variable, LD_PRELOAD=/full/path/to/libcofi_rpi.so, then run program. + +The inner loop of the misalignment path of memcpy is derived from the GNU libc ARM port. As a result "copies-and-fills" is licensed under the GNU Lesser General Public License version 2.1. See http://www.gnu.org/licenses/ for details. +To see the original memcpy, browse it here: http://sourceware.org/git/?p=glibc-ports.git;a=blob;f=sysdeps/arm/memcpy.S;hb=HEAD + +Simon Hall + +NOTES + +memcpy: +Can be found in memcpy.s. +Compared to the generic libc memcpy, this one reaches performance parity at around ~150 bytes copies with any source/destination alignment and eventually gains 2-3x throughput, especially when the source buffer is uncached. +When taking the libc source and enabling the pld path, it certainly does improve. However the source alignment option appears to do nothing for performance yet greatly increases the code complexity. +In initial testing, some facts were found: +- despite the increase in free registers, copies via VFP were slower at peak by ~25% +- copying 32 bytes at a time with a single store-multiple gives the highest performance +- getting the destination 32b aligned gives a much greater throughput versus 4b-alignment +- some memcpys are of a fixed size, eg 1/2/4/8 byte in size +- byte transfers have a much worse performance than expected +- for misaligned transfers, 32b-aligned stms are the way forward with mov/orr byte shuffling; byte copies give very poor performance + +The code deals with the special small sizes, then races to reach 32b alignment of the destination. +We then test for misalignment with the source. If the (source - dest alignment) & 3 != 0 then we use the misaligned path. +For the aligned path, we iterate through the data, 32 bytes at a time. We then handle a word at a time, then a byte. +For the misaligned path, we have to choose how misaligned we are - 1, 2, or 3 bytes. There is a custom path for each that does the appropriate shifts. + +The key to this is prefetch of the source array. Prefetch instructions must be far from the load instruction, as it appears the load/store pipe is busy for a while after a large load instruction is issued. + +Speeds of up to 680 MB/s have been achieved (effective 339 MB/s copy). + +memset: +Can by found in memset.s. +Compared to the generic libc memset, this quickly reaches performance parity at around 100 bytes with any alignment. +On testing, +- it appears 32-byte stores yield ~1000-1100 MB/s, by two sequential 16-byte stores can reach 1300-1400 MB/s +- again 32b aligned destinations are good + +The code 4-byte aligns the destination with a byte writer, then 32-byte aligns it with a word writer. +We then write two 2*16 bytes of data, then write words, then bytes. +No preload of destination data seems to be required. + +Speeds of up to 1390 MB/s have been achieved. This is ~7x faster than the libc version. + +VERSION HISTORY + +09/07/2012, minor updates +01/07/2012, initial release + diff --git a/raspi-hacks/libcofi_rpi/libcofi_rpi.csh.new b/raspi-hacks/libcofi_rpi/libcofi_rpi.csh.new new file mode 100644 index 0000000..de83aaf --- /dev/null +++ b/raspi-hacks/libcofi_rpi/libcofi_rpi.csh.new @@ -0,0 +1,3 @@ +#!/bin/csh + +setenv LD_PRELOAD /usr/lib/libcofi_rpi.so diff --git a/raspi-hacks/libcofi_rpi/libcofi_rpi.sh.new b/raspi-hacks/libcofi_rpi/libcofi_rpi.sh.new new file mode 100644 index 0000000..878d02f --- /dev/null +++ b/raspi-hacks/libcofi_rpi/libcofi_rpi.sh.new @@ -0,0 +1,3 @@ +#!/bin/sh + +export LD_PRELOAD=/usr/lib/libcofi_rpi.so diff --git a/raspi-hacks/libcofi_rpi/memcpy.s b/raspi-hacks/libcofi_rpi/memcpy.s new file mode 100644 index 0000000..6c2c503 --- /dev/null +++ b/raspi-hacks/libcofi_rpi/memcpy.s @@ -0,0 +1,332 @@ +/* + Part of the "copies and fills" library by Simon Hall + + The inner loop of the misaligned path is derived from the GNU libc ARM port. + The rest is my own work. + + This code is licensed under the GNU Lesser General Public License version 2.1 + + void memcpy(void *dest, + const void *source, + size_t count); +*/ + +.global memcpy +.func memcpy +memcpy: + cmp r2, #0 + pld [r1] + bxeq lr /* get straight out on zero, NB: count is unsigned */ + + cmp r2, #4 /* basic copy for four bytes */ + pld [r1, #32] + ldreq r3, [r1] /* we're relying on the cpu misalignment support here */ + streq r3, [r0] + bxeq lr + + cmp r2, #8 + pld [r1, #64] /* basic copy for eight bytes, with fall through for < 8 */ + ldreq r3, [r1] /* can't use ldrd without checking alignment...can't trust os alignment handling */ + streq r3, [r0] /* if we do trust the os then r2 is free for ldrd */ + ldreq r3, [r1, #4] + streq r3, [r0, #4] + bxeq lr + + cmp r2, #32 + pld [r1, #96] + blt byte_at_a_time_no_pld /* fast path for small sizes, no stack push */ + + push {r0, r4-r11} /* memcpy returns the original destination, hence push r0 */ + + /* compute the dest pointer alignment */ +.if 0 + and r3, r0, #3 /* slightly slower compared to conditional version below */ + + cmp r3, #3 /* three bytes misaligned, one to do */ + beq head_1 + + cmp r3, #2 + beq head_2 /* two bytes misaligned, two to do */ + + cmp r3, #1 + beq head_3 /* one byte misaligned, three to do */ +.else + ands r3, r0, #3 + beq skip_byte_realignment + + rsb r4, r3, #4 /* how many bytes need to be read */ + cmp r4, #2 + + ldrgtb r5, [r1], #1 /* three bytes */ + ldrgeb r6, [r1], #1 /* two+ bytes */ + ldrb r7, [r1], #1 /* one+ byte */ + + strgtb r5, [r0], #1 + strgeb r6, [r0], #1 + strb r7, [r0], #1 + + sub r2, r4 + +skip_byte_realignment: +.endif + +.if 0 + eor r3, r0, r1 /* check the 4b alignment of the two pointers */ + tst r3, #3 /* ideally the bottom two bits should line up */ + +.else + ands r3, r1, #3 +.endif + bne misaligned + + /* dest pointer now 4b aligned */ + /* let's try and 32b align the destination */ + tst r0, #31 + beq pre_fast_loop +align_up: +.if 1 + ldr r3, [r1], #4 + + add r0, #4 + sub r2, #4 + + tst r0, #31 /* do it early for the next run */ + str r3, [r0, #-4] + + bne align_up +.else + and r3, r0, #31 /* jump based on the amount of bytes to do - slower than loop above */ + add pc, pc, r3 + nop; nop + + ldr r4, [r1], #4 + ldr r5, [r1], #4 + ldr r6, [r1], #4 + ldr r7, [r1], #4 + ldr r8, [r1], #4 + ldr r9, [r1], #4 + ldr r10, [r1], #4 + + add pc, pc, r3 + nop; nop + + str r4, [r0], #4 + str r5, [r0], #4 + str r6, [r0], #4 + str r7, [r0], #4 + str r8, [r0], #4 + str r9, [r0], #4 + str r10, [r0], #4 + + rsb r3, #32 + sub r2, r3 +.endif + +pre_fast_loop: + /* round byte count down to nearest 32 */ + bics r3, r2, #31 + /* compute the spare */ + and r2, #31 + + beq post_fast_loop /* nothing to do in the main loop */ + + /* work through 32b at a time */ +fast_loop: +.if 0 + ldmia r1!, {r4-r11} /* original version */ + subs r3, #32 + stmia r0!, {r4-r11} + pld [r1, #128] + bne fast_loop +.else + ldmia r1!, {r4-r7} /* slightly fast version suggested by tufty */ + ldmia r1!, {r8-r11} + stmia r0!, {r4-r7} + pld [r1, #128] + subs r3, #32 + stmia r0!, {r8-r11} + bne fast_loop +.endif + + /* handle the spare bytes, up to 32 of them */ +post_fast_loop: + cmp r2, #0 /* there might be none */ + beq full_out + + bics r3, r2, #3 + and r2, #3 + beq tail_fast_loop_byte + +tail_fast_loop: + ldr r4, [r1], #4 + subs r3, #4 + str r4, [r0], #4 + bne tail_fast_loop + + cmp r2, #0 + beq full_out + +tail_fast_loop_byte: + subs r2, #1 + ldrb r3, [r1], #1 + strb r3, [r0], #1 + bne tail_fast_loop_byte + +full_out: + pop {r0, r4-r11} + bx lr + +byte_at_a_time_no_pld: + subs r2, #1 + ldrb r3, [r1, r2] /* one byte at a time, so we don't have to check for odd */ + strb r3, [r0, r2] /* sizes and alignments etc; also no stack push necessary */ + bne byte_at_a_time_no_pld + + bx lr /* leaving r0 intact */ + +/*head_3: + ldrb r3, [r1], #1 + strb r3, [r0], #1 + sub r2, #1 +head_2: + ldrb r3, [r1], #1 + strb r3, [r0], #1 + sub r2, #1 +head_1: + ldrb r3, [r1], #1 + strb r3, [r0], #1 + sub r2, #1 + b pre_fast_loop +*/ +misaligned: + bic r1, #3 /* align down r1, with r3 containing the r1 misalignment */ + cmp r3, #2 + ldr r11, [r1], #4 + + beq misaligned_2 + bgt misaligned_3 +misaligned_1: + cmp r2, #32 + blt post_misalignment_1 + +mis_1_loop: + lsr r3, r11, #8 /* we want the high three bytes of this */ + ldmia r1!, {r4-r11} + sub r2, #32 + cmp r2, #32 + + orr r3, r4, lsl #24 + lsr r4, #8; orr r4, r5, lsl #24 + lsr r5, #8; orr r5, r6, lsl #24 + lsr r6, #8; orr r6, r7, lsl #24 + lsr r7, #8; orr r7, r8, lsl #24 + lsr r8, #8; orr r8, r9, lsl #24 + lsr r9, #8; orr r9, r10, lsl #24 + lsr r10, #8; orr r10, r11, lsl #24 + + pld [r1, #128] + stmia r0!, {r3-r10} + + bge mis_1_loop + +post_misalignment_1: + cmp r2, #0 + beq full_out + lsr r11, #8 + mov r3, #3 +post_misalignment_1_loop: + cmp r3, #0 + ldreq r11, [r1], #4 + moveq r3, #4 + + strb r11, [r0], #1 + sub r3, #1 + subs r2, #1 + lsr r11, #8 + bne post_misalignment_1_loop + + b full_out + +misaligned_2: + cmp r2, #32 + blt post_misalignment_2 + +mis_2_loop: + lsr r3, r11, #16 /* we want the high two bytes of this */ + ldmia r1!, {r4-r11} + sub r2, #32 + cmp r2, #32 + + orr r3, r4, lsl #16 + lsr r4, #16; orr r4, r5, lsl #16 + lsr r5, #16; orr r5, r6, lsl #16 + lsr r6, #16; orr r6, r7, lsl #16 + lsr r7, #16; orr r7, r8, lsl #16 + lsr r8, #16; orr r8, r9, lsl #16 + lsr r9, #16; orr r9, r10, lsl #16 + lsr r10, #16; orr r10, r11, lsl #16 + + pld [r1, #128] + stmia r0!, {r3-r10} + + bge mis_2_loop + +post_misalignment_2: + cmp r2, #0 + beq full_out + lsr r11, #16 + mov r3, #2 +post_misalignment_2_loop: + cmp r3, #0 + ldreq r11, [r1], #4 + moveq r3, #4 + + strb r11, [r0], #1 + sub r3, #1 + subs r2, #1 + lsr r11, #8 + bne post_misalignment_2_loop + + b full_out +misaligned_3: + cmp r2, #32 + blt post_misalignment_3 + +mis_3_loop: + lsr r3, r11, #24 /* we want the high byte of this */ + ldmia r1!, {r4-r11} + sub r2, #32 + cmp r2, #32 + + orr r3, r4, lsl #8 + lsr r4, #24; orr r4, r5, lsl #8 + lsr r5, #24; orr r5, r6, lsl #8 + lsr r6, #24; orr r6, r7, lsl #8 + lsr r7, #24; orr r7, r8, lsl #8 + lsr r8, #24; orr r8, r9, lsl #8 + lsr r9, #24; orr r9, r10, lsl #8 + lsr r10, #24; orr r10, r11, lsl #8 + + pld [r1, #128] + stmia r0!, {r3-r10} + + bge mis_3_loop + +post_misalignment_3: + cmp r2, #0 + beq full_out + lsr r11, #24 + mov r3, #1 +post_misalignment_3_loop: + cmp r3, #0 + ldreq r11, [r1], #4 + moveq r3, #4 + + strb r11, [r0], #1 + sub r3, #1 + subs r2, #1 + lsr r11, #8 + bne post_misalignment_3_loop + + b full_out +.endfunc diff --git a/raspi-hacks/libcofi_rpi/memset.s b/raspi-hacks/libcofi_rpi/memset.s new file mode 100644 index 0000000..3af915a --- /dev/null +++ b/raspi-hacks/libcofi_rpi/memset.s @@ -0,0 +1,100 @@ +/* + This is part of the "copies and fills" library by Simon Hall + + This function is all my own work. + It is licensed under the GNU Lesser Public License version 2.1 + + void *memset(void *dest, int c, size_t count); +*/ +.global memset +.func memset +memset: + cmp r2, #0 /* get out on no work */ + and r1, #0xff + orr r1, r1, r1, lsl #8 /* fill out byte two */ + bxeq lr + + push {r0, lr} /* we have to return r0 */ + + /* align up the destination to 4b */ + tst r0, #3 + orr r1, r1, r1, lsl #16 /* and bytes three and four */ + beq skip_byte_alignment + +byte_alignment_loop: + subs r2, #1 + strb r1, [r0], #1 + popeq {r0, pc} /* get out if we're out of bytes */ + + tst r0, #3 + bne byte_alignment_loop + + /* we are now 4b aligned, and there is at least one byte of r2 to go */ +skip_byte_alignment: + tst r0, #31 + beq skip_word_alignment + +word_alignment_loop: + cmp r2, #4 + blt stray_bytes + + subs r2, #4 + str r1, [r0], #4 + popeq {r0, pc} /* if no work left */ + + tst r0, #31 + bne word_alignment_loop + + /* we are now 32b aligned */ +skip_word_alignment: + and r3, r2, #31 /* small work */ + bics r2, #31 /* bulk work */ + + push {r4-r6} + + bic r4, r3, #3 /* words of work to go */ + beq bytes_and_words + + /* fill out our bytes */ + mov r4, r1 + mov r5, r1 + mov r6, r1 +main_loop: + subs r2, #32 + + stmia r0!, {r1, r4, r5, r6} + stmia r0!, {r1, r4, r5, r6} + + bne main_loop + cmp r3, #0 + popeq {r4-r6} + popeq {r0, pc} + bic r4, r3, #3 /* redo this */ + +bytes_and_words: + cmp r4, #0 + beq bytes +words: + subs r4, #4 + str r1, [r0], #4 + bne words + + ands r3, #3 + popeq {r4-r6} + popeq {r0, pc} +bytes: + subs r3, #1 + strb r1, [r0], #1 + bne bytes + + pop {r4-r6} + pop {r0, pc} +stray_bytes: + cmp r2, #2 + + strgtb r1, [r0], #1 + strgeb r1, [r0], #1 + strb r1, [r0], #1 + + pop {r0, pc} +.endfunc diff --git a/raspi-hacks/raspi-hacks.SlackBuild b/raspi-hacks/raspi-hacks.SlackBuild index 77feee7..02fcfbb 100755 --- a/raspi-hacks/raspi-hacks.SlackBuild +++ b/raspi-hacks/raspi-hacks.SlackBuild @@ -24,7 +24,7 @@ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. PRGNAM="raspi-hacks" -VERSION=${VERSION:-1.0} +VERSION=${VERSION:-2.0} ARCH="arm" BUILD=${BUILD:-1} TAG=${TAG:-} @@ -34,62 +34,101 @@ TMP=${TMP:-/tmp} OUTPUT=${OUTPUT:-/tmp} PKG=$TMP/package-$PRGNAM -rm -rf $PKG -mkdir -p $TMP $PKG +mkdir -p $TMP +rm -rf $PKG +mkdir -p $PKG/etc +mkdir -p $PKG/usr/lib mkdir -p $PKG/install +cat $CWD/doinst.sh > $PKG/install/doinst.sh + +# Serial port fixup cat << EOF >> $PKG/install/doinst.sh -# /etc/inittab -- modify serial port entry 's0' -sed -i \ - -e 's;^s0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100\$;#s0:12345:respawn:/sbin/agetty -L ttyAMA0 9600 vt100;' \ - etc/inittab +# inittab -- modify serial port entry 's0' +if grep -q '^s0:.*ttyS0' etc/inittab ; then + sed -i \ + -e 's;^s0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100\$;#s0:12345:respawn:/sbin/agetty -L ttyAMA0 9600 vt100;' \ + etc/inittab +fi + EOF +# Hardware clock fixup (1) rc.local cat << EOF >> $PKG/install/doinst.sh -# /etc/rc.d/rc.local -- set time from network +# rc.local -- set time from network if ! grep -q sntp etc/rc.d/rc.local ; then echo '' >> etc/rc.d/rc.local echo "# Added by $PRGNAM-$VERSION-$ARCH-$BUILD$TAG" >> etc/rc.d/rc.local echo 'sntp -s pool.ntp.org >/dev/null &' >> etc/rc.d/rc.local fi + +EOF + +# Hardware clock fixup (2) e2fsck.conf +cp $CWD/e2fsck.conf.new \ + $PKG/etc +cat << EOF >> $PKG/install/doinst.sh +# e2fsck.conf -- hardware clock fix +config etc/e2fsck.conf.new + EOF -mkdir -p $PKG/sbin -cp -a $CWD/fakeclock.sh $PKG/sbin -chmod 755 $PKG/sbin/fakeclock.sh -( cd $PKG/sbin; ln -s fakeclock.sh hwclock ) +# Hardware clock de-fixup :-) cat << EOF >> $PKG/install/doinst.sh -# /sbin/hwclock -- save the original (from util-linux) -if [ -f sbin/hwclock -a ! -L sbin/hwclock ]; then - mv sbin/hwclock sbin/hwclock.orig +# hwclock -- reinstate the original if moved by previous raspi-hacks +if [ -f sbin/hwclock.orig ]; then + rm -f sbin/hwclock + mv sbin/hwclock.orig sbin/hwclock fi + EOF -mkdir -p $PKG/etc -echo "vm.min_free_kbytes = 32768" > $PKG/etc/sysctl.conf.new +# Tuning via /etc/sysctl.conf +cp $CWD/sysctl.conf.new \ + $PKG/etc cat << EOF >> $PKG/install/doinst.sh -# /etc/sysctl.conf -- set vm.min_free_kbytes -config() { - NEW="\$1" - OLD="\$(dirname \$NEW)/\$(basename \$NEW .new)" - # If there's no config file by that name, mv it over: - if [ ! -r \$OLD ]; then - mv \$NEW \$OLD - elif [ "\$(cat \$OLD | md5sum)" = "\$(cat \$NEW | md5sum)" ]; then # toss the redundant copy - rm \$NEW - fi - # Otherwise, we leave the .new copy for the admin to consider... -} +# sysctl.conf -- set vm.min_free_kbytes config etc/sysctl.conf.new + EOF +# Build and install libcofi_rpi +( + cd libcofi_rpi + rm -f *.o *.so + make libcofi_rpi.so +) + +mkdir -p $PKG/usr/lib +cp libcofi_rpi/libcofi_rpi.so \ + $PKG/usr/lib +chmod 644 $PKG/usr/lib/libcofi_rpi.so + +mkdir -p $PKG/etc/profile.d +cp \ + libcofi_rpi/libcofi_rpi.sh.new \ + libcofi_rpi/libcofi_rpi.csh.new \ + $PKG/etc/profile.d +chmod 644 \ + $PKG/etc/profile.d/libcofi_rpi.sh.new \ + $PKG/etc/profile.d/libcofi_rpi.csh.new + +cat << EOF >> $PKG/install/doinst.sh +# libcofi_rpi.sh -- activate replacement memcpy/memset +preserve_perms etc/profile.d/libcofi_rpi.sh.new +preserve_perms etc/profile.d/libcofi_rpi.csh.new + +EOF + +# Documentation mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION cp -a \ $CWD/README \ + $CWD/libcofi_rpi/README.libcofi_rpi \ $PKG/usr/doc/$PRGNAM-$VERSION +# Finish off cat $CWD/slack-desc > $PKG/install/slack-desc - cd $PKG /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz} diff --git a/raspi-hacks/sysctl.conf.new b/raspi-hacks/sysctl.conf.new new file mode 100644 index 0000000..7e7aba5 --- /dev/null +++ b/raspi-hacks/sysctl.conf.new @@ -0,0 +1 @@ +vm.min_free_kbytes = 32768