#!/bin/sh #set -e echo "Setting up pramfs" # ensure the required binaries are present #[ -x /sbin/modprobe ] || exit 1 [ -x /bin/mount ] || exit 1 [ -x /bin/grep ] || exit 1 [ -x /bin/cat ] || exit 1 [ -x /bin/sed ] || exit 1 #modprobe pramfs mkdir -p /mnt/pram case "$1" in start) # Figure out RAM for pramfs # This requires a kernel cmdline resevation of PRAMFS physmem # in format memmap=16M$0x7000000 grep memmap /proc/cmdline > /dev/null if [ $? -eq 0 ]; then addr=$(sed 's/.*memmap=\([^ ]*\)\$\([^ ]*\).*/\2/' < /proc/cmdline) size=$(sed 's/.*memmap=\([^ ]*\)\$\([^ ]*\).*/\1/' < /proc/cmdline) if [ -d /seed ]; then echo "Init new pramfs" mount -t pramfs -o physaddr=$addr,init=$size,bs=1k none /mnt/pram > /dev/null 2>&1 cp /seed/* /mnt/pram echo "0" > /mnt/pram/kcount else echo "Mounting old pramfs" mount -t pramfs -o physaddr=$addr,bs=1k none /mnt/pram > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "Mounting old pramfs failed, zeroing" mount -t pramfs -o physaddr=$addr,init=$size,bs=1k none /mnt/pram > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "All attempts to mount pramfs has failed, exiting" rm -fr /mnt/pram exit 1 fi echo "0" > /mnt/pram/kcount fi fi # echo "* Setting up kexec" # kexec -l --reuse-cmdline --initrd=/mnt/pram/initramfs.cpio.gz /mnt/pram/vmlinuz # Calculate number of boots export KCOUNT=$(expr $(cat /mnt/pram/kcount) + 1) echo $KCOUNT > /mnt/pram/kcount else KCOUNT="no-mem" echo "Can't find memory area for pram fs" rm -fr /mnt/pram fi echo "PRAMFS boot count: $KCOUNT" # echo "kexec -e to kexec and keep persistent files in /mnt/pram" ;; stop) echo ;; restart) $0 stop $0 start ;; *) echo "usage: $0 { start | stop | restart }" >&2 exit 1 ;; esac exit 0