diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3869831 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +Copyright (c) 2013 cubieplayer@github.com. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. diff --git a/README b/README index e69de29..ee24e66 100644 --- a/README +++ b/README @@ -0,0 +1,6 @@ +This script was made by drkbcn from http://www.cubieforums.com/ for Cubieez image. +It base on http://elinux.org/RPi_raspi-config +I added to cubie_config possibility to instal into Nand (Base on mmplayer/nandinstall script) +It should work on any image runs from SD card (berryboot can be problem). +Make sure that you have installed partprobe and proper script.bin & uImage ant /boot +(should be Any.. Cubian and Cubieez was tested if not work at your distro please give me notice) diff --git a/a10/bootloader/boot.axf b/a10/bootloader/boot.axf new file mode 100644 index 0000000..212d847 Binary files /dev/null and b/a10/bootloader/boot.axf differ diff --git a/a10/bootloader/boot.ini b/a10/bootloader/boot.ini new file mode 100644 index 0000000..e71070d --- /dev/null +++ b/a10/bootloader/boot.ini @@ -0,0 +1,10 @@ +[system] +start_os_name = linux +timeout = -1 +display_device= -1 +display_mode = 0 +erase_flash = 1 + + +[linux] + diff --git a/a10/bootloader/linux/linux.ini b/a10/bootloader/linux/linux.ini new file mode 100644 index 0000000..fc1c7d9 --- /dev/null +++ b/a10/bootloader/linux/linux.ini @@ -0,0 +1,8 @@ +[segment] +img_name = c:\u-boot.bin +img_size = 0x80000 +img_base = 0x4A000000 + +[script_info] +script_base = 0x43000000 +script_size = 0x10000 diff --git a/a10/bootloader/u-boot.bin b/a10/bootloader/u-boot.bin new file mode 100644 index 0000000..1cb1f35 Binary files /dev/null and b/a10/bootloader/u-boot.bin differ diff --git a/a10/cubie_nand.gz b/a10/cubie_nand.gz new file mode 100644 index 0000000..95e3386 Binary files /dev/null and b/a10/cubie_nand.gz differ diff --git a/a20/bootloader/boot.axf b/a20/bootloader/boot.axf new file mode 100644 index 0000000..a6f040a Binary files /dev/null and b/a20/bootloader/boot.axf differ diff --git a/a20/bootloader/boot.ini b/a20/bootloader/boot.ini new file mode 100644 index 0000000..ca8afeb --- /dev/null +++ b/a20/bootloader/boot.ini @@ -0,0 +1,5 @@ +[system] +start_os_name = linux +timeout = -1 +display_device= 0 +display_mode = 0 diff --git a/a20/bootloader/linux/linux.ini b/a20/bootloader/linux/linux.ini new file mode 100644 index 0000000..39706b0 --- /dev/null +++ b/a20/bootloader/linux/linux.ini @@ -0,0 +1,8 @@ +[segment] +img_name = c:\linux\u-boot.bin +img_size = 0x80000 +img_base = 0x4A000000 + +[script_info] +script_base = 0x43000000 +script_size = 0x10000 diff --git a/a20/cubie_nand.gz b/a20/cubie_nand.gz new file mode 100644 index 0000000..66cb889 Binary files /dev/null and b/a20/cubie_nand.gz differ diff --git a/a20/u-boot-0f35.bin b/a20/u-boot-0f35.bin new file mode 100644 index 0000000..05cf7e9 Binary files /dev/null and b/a20/u-boot-0f35.bin differ diff --git a/a20/u-boot-10bb.bin b/a20/u-boot-10bb.bin new file mode 100644 index 0000000..80ca694 Binary files /dev/null and b/a20/u-boot-10bb.bin differ diff --git a/cubie-config b/cubie-config new file mode 100755 index 0000000..a8ff783 --- /dev/null +++ b/cubie-config @@ -0,0 +1,553 @@ +#!/bin/sh +# Part of raspi-config http://github.com/asb/raspi-config +# +# See LICENSE file for copyright and license details + +INTERACTIVE=True +ASK_TO_REBOOT=0 + +calc_wt_size() { + # NOTE: it's tempting to redirect stderr to /dev/null, so supress error + # output from tput. However in this case, tput detects neither stdout or + # stderr is a tty and so only gives default 80, 24 values + WT_HEIGHT=17 + WT_WIDTH=$(tput cols) + + if [ -z "$WT_WIDTH" ] || [ "$WT_WIDTH" -lt 60 ]; then + WT_WIDTH=80 + fi + if [ "$WT_WIDTH" -gt 178 ]; then + WT_WIDTH=120 + fi + WT_MENU_HEIGHT=$(($WT_HEIGHT-8)) +} + +do_about() { + whiptail --msgbox "\ +This tool provides a straight-forward way of doing initial +configuration of the Cubieboard. Although it can be run +at any time, some of the options may have difficulties if +you have heavily customised your installation. +This is an adaptation of raspi-config for Cubieboard. +\ +" 20 70 1 +} + +do_expand_rootfs() { + if ! [ -h /dev/root ]; then + whiptail --msgbox "/dev/root does not exist or is not a symlink. Don't know how to expand" 20 60 2 + return 0 + fi + + ROOT_PART=$(readlink /dev/root) + PART_NUM=${ROOT_PART#mmcblk0p} + if [ "$PART_NUM" = "$ROOT_PART" ]; then + whiptail --msgbox "/dev/root is not an SD card. Don't know how to expand" 20 60 2 + return 0 + fi + + # NOTE: the NOOBS partition layout confuses parted. For now, let's only + # agree to work with a sufficiently simple partition layout + if [ "$PART_NUM" -ne 2 ]; then + whiptail --msgbox "Your partition layout is not currently supported by this tool. You are probably using NOOBS, in which case your root filesystem is already expanded anyway." 20 60 2 + return 0 + fi + + LAST_PART_NUM=$(parted /dev/mmcblk0 -ms unit s p | tail -n 1 | cut -f 1 -d:) + + if [ "$LAST_PART_NUM" != "$PART_NUM" ]; then + whiptail --msgbox "/dev/root is not the last partition. Don't know how to expand" 20 60 2 + return 0 + fi + + # Get the starting offset of the root partition + PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d:) + [ "$PART_START" ] || return 1 + # Return value will likely be error for fdisk as it fails to reload the + # partition table because the root fs is mounted + fdisk /dev/mmcblk0 < /etc/init.d/resize2fs_once && +#!/bin/sh +### BEGIN INIT INFO +# Provides: resize2fs_once +# Required-Start: +# Required-Stop: +# Default-Start: 2 3 4 5 S +# Default-Stop: +# Short-Description: Resize the root filesystem to fill partition +# Description: +### END INIT INFO + +. /lib/lsb/init-functions + +case "$1" in + start) + log_daemon_msg "Starting resize2fs_once" && + resize2fs /dev/root && + rm /etc/init.d/resize2fs_once && + update-rc.d resize2fs_once remove && + log_end_msg $? + ;; + *) + echo "Usage: $0 start" >&2 + exit 3 + ;; +esac +EOF + chmod +x /etc/init.d/resize2fs_once && + update-rc.d resize2fs_once defaults && + if [ "$INTERACTIVE" = True ]; then + whiptail --msgbox "Root partition has been resized.\nThe filesystem will be enlarged upon the next reboot" 20 60 2 + fi +} + +set_config_var() { + lua - "$1" "$2" "$3" < "$3.bak" +local key=assert(arg[1]) +local value=assert(arg[2]) +local fn=assert(arg[3]) +local file=assert(io.open(fn)) +local made_change=false +for line in file:lines() do + if line:match("^#?%s*"..key.."=.*$") then + line=key.."="..value + made_change=true + end + print(line) +end + +if not made_change then + print(key.."="..value) +end +EOF +mv "$3.bak" "$3" +} + +get_config_var() { + lua - "$1" "$2" <&1 1>&2 2>&3) + if [ $? -eq 0 ]; then + echo $NEW_HOSTNAME > /etc/hostname + sed -i "s/127.0.1.1.*$CURRENT_HOSTNAME/127.0.1.1\t$NEW_HOSTNAME/g" /etc/hosts + ASK_TO_REBOOT=1 + fi +} + +do_ssh() { + if [ -e /var/log/regen_ssh_keys.log ] && ! grep -q "^finished" /var/log/regen_ssh_keys.log; then + whiptail --msgbox "Initial ssh key generation still running. Please wait and try again." 20 60 2 + return 1 + fi + whiptail --yesno "Would you like the SSH server enabled or disabled?" 20 60 2 \ + --yes-button Enable --no-button Disable + RET=$? + if [ $RET -eq 0 ]; then + update-rc.d ssh enable && + invoke-rc.d ssh start && + whiptail --msgbox "SSH server enabled" 20 60 1 + elif [ $RET -eq 1 ]; then + update-rc.d ssh disable && + whiptail --msgbox "SSH server disabled" 20 60 1 + else + return $RET + fi +} + +do_boot_behaviour() { + if [ -e /etc/init.d/lightdm ]; then + whiptail --yesno "Should we boot straight to desktop?" 20 60 2 + RET=$? + if [ $RET -eq 0 ]; then # yes + update-rc.d lightdm enable 2 + sed /etc/lightdm/lightdm.conf -i -e "s/^#autologin-user=.*/autologin-user=pi/" + ASK_TO_REBOOT=1 + elif [ $RET -eq 1 ]; then # no + update-rc.d lightdm disable 2 + ASK_TO_REBOOT=1 + else # user hit escape + return 1 + fi + else + whiptail --msgbox "Do sudo apt-get install lightdm to allow configuration of boot to desktop" 20 60 2 + return 1 + fi +} + +do_finish() { + if [ -e /etc/profile.d/raspi-config.sh ]; then + rm -f /etc/profile.d/raspi-config.sh + sed -i /etc/inittab \ + -e "s/^#\(.*\)#\s*RPICFG_TO_ENABLE\s*/\1/" \ + -e "/#\s*RPICFG_TO_DISABLE/d" + telinit q + fi + if [ $ASK_TO_REBOOT -eq 1 ]; then + whiptail --yesno "Would you like to reboot now?" 20 60 2 + if [ $? -eq 0 ]; then # yes + sync + reboot + fi + fi + exit 0 +} + +# +# Command line options for non-interactive use +# +for i in $* +do + case $i in + --expand-rootfs) + INTERACTIVE=False + do_expand_rootfs + printf "Please reboot\n" + exit 0 + ;; + *) + # unknown option + ;; + esac +done + +# Everything else needs to be run as root +if [ $(id -u) -ne 0 ]; then + printf "Script must be run as root. Try 'sudo cubie-config'\n" + exit 1 +fi + +# for nand install +CWD=$(cd "$(dirname "$0")"; pwd) +CUBIE_PART= +BOOTLOADER= +MMC_DEVICE="/dev/mmcblk0" +NAND_DEVICE="/dev/nand" +NANDA_DEVICE="/dev/nanda" +NANDB_DEVICE="/dev/nandb" +NANDC_DEVICE="/dev/nandc" +NAND1_DEVICE="/dev/nand1" +NAND2_DEVICE="/dev/nand2" +NAND3_DEVICE="/dev/nand3" + +DEVICE_A10="a10" +DEVICE_A20="a20" + +CPU_INFO="/proc/cpuinfo" + +MNT_BOOT="/mnt/nanda" +MNT_ROOT="/mnt/nandb" + +CURRENT_PART_DUMP="${CWD}/nand.tmp" +EXCLUDE_FILE_LIST="${CWD}/exclude.txt" + +ERR_DETECT_DEVICE="error: failed to detect your device" + +NAND_BOOT_DEVICE= +NAND_ROOT_DEVICE= +NAND_MAGIC_DEVICE= + +DEVICE_TYPE= +MACH_ID= + +### determine device +if [ -f $CPU_INFO ];then + if cat $CPU_INFO | grep -q 'sun4i';then + DEVICE_TYPE="$DEVICE_A10" + elif cat $CPU_INFO | grep -q 'sun7i';then + DEVICE_TYPE="${DEVICE_A20}" + ### determine machid + uname -r | grep '3.3.0' > /dev/null 2>&1 + if [ $? -eq 0 ];then + MACH_ID='0f35' + else + MACH_ID='10bb' + fi + else + echoRed "$ERR_DETECT_DEVICE, must be sun4i or sun7i device" + exit 1 + fi +else + echoRed "$ERR_DETECT_DEVICE, ${CPU_INFO} is not exist" + exit 1 +fi + +set -e + +### determine partition table +CUBIE_PART="${CWD}/${DEVICE_TYPE}/cubie_nand.gz" + +### determine u-boot.bin on a20 +# use 0f35 for kernel 3.3.0 +# use 10bb for kernel 3.4.43 +# copy correct u-boot.bin +if [ "$DEVICE_TYPE" = "${DEVICE_A20}" ];then + rm -f ${CWD}/${DEVICE_TYPE}/bootloader/linux/u-boot*.bin + cp -f "${CWD}/${DEVICE_TYPE}/u-boot-${MACH_ID}.bin" \ + "${CWD}/${DEVICE_TYPE}/bootloader/linux/u-boot.bin" +fi + +### The bootloader is ready now +BOOTLOADER="${CWD}/${DEVICE_TYPE}/bootloader" + +### set nand device +if [ -b $NANDA_DEVICE ];then + NAND_BOOT_DEVICE="$NANDA_DEVICE" +elif [ -b $NAND1_DEVICE ];then + NAND_BOOT_DEVICE="$NAND1_DEVICE" +fi + +if [ "$DEVICE_TYPE" = "$DEVICE_A10" ];then + NAND_ROOT_DEVICE="$NANDB_DEVICE" +elif [ "$DEVICE_TYPE" = "${DEVICE_A20}" ];then + if [ -b "$NANDC_DEVICE" ];then + NAND_ROOT_DEVICE="$NANDC_DEVICE" + NAND_MAGIC_DEVICE="$NANDB_DEVICE" + elif [ -b "$NAND3_DEVICE" ];then + NAND_ROOT_DEVICE="$NAND3_DEVICE" + NAND_MAGIC_DEVICE="$NAND2_DEVICE" + fi +fi + +echoGreen(){ + echo "\033[32m${1}\033[0m" +} + +echoRed(){ + echo "\033[31m${1}\033[0m" +} + +umountNand() { +sync +for n in ${NAND_DEVICE}*;do + if [ "${NAND_DEVICE}" != "$n" ];then + if mount|grep ${n};then + echoGreen "umounting ${n}" + umount -l $n + fi + fi +done +} + +formatNand(){ + tar -xzOf $CUBIAN_PART | dd of=$NAND_DEVICE + sync +} + +mkFS(){ + mkfs.vfat $NAND_BOOT_DEVICE + mkfs.ext4 $NAND_ROOT_DEVICE + if [ -n "$NAND_MAGIC_DEVICE" ];then + echo -e 'ANDROID!\0\0\0\0\0\0\0\0\c' > $NAND_MAGIC_DEVICE + fi +} + +mountDevice(){ + if [ ! -d $MNT_BOOT ];then + mkdir $MNT_BOOT + fi + mount $NAND_BOOT_DEVICE $MNT_BOOT + + if [ ! -d $MNT_ROOT ];then + mkdir $MNT_ROOT + fi + mount $NAND_ROOT_DEVICE $MNT_ROOT +} + +installBootloader(){ + rm -rf $MNT_BOOT/* + rsync -avc $BOOTLOADER/* $MNT_BOOT + rsync -avc /boot/* $MNT_ROOT/boot/ +} + +installRootfs(){ + rsync -avc --exclude-from=$EXCLUDE_FILE_LIST / $MNT_ROOT + echoGreen "sync disk... please wait" + sync +} + +patchRootfs(){ + cat > ${MNT_ROOT}/etc/fstab < +$NAND_ROOT_DEVICE / ext4 defaults 0 1 +END +} + +do_nand_create() { + umountNand + echoGreen "Reading new partition table.." + formatNand + echoGreen "Reading new partition table.." + partprobe $NAND_DEVICE + echoGreen "Creating file system.." + mkFS + do_nandinstall_menu +} + +do_nand_boot() { + mountDevice + echoGreen "Installing bootloader.." + installBootloader + umountNand + do_nandinstall_menu +} + +do_nand_data() { + mountDevice + echoGreen "Installing rootfs.." + installRootfs + patchRootfs + umountNand + echoGreen "Success! Remember to REMOVE your SD card then reboot" + whiptail --yesno "Success!\nRemember to REMOVE your SD card before reboot\nWould you like to shutdown now?" 20 60 2 + if [ $? -eq 0 ]; then # yes + sync + shutdown -h now + fi +} + +do_nandinstall_menu() { + FUN=$(whiptail --title "Cubieboard Pi Software Configuration Tool (cubie-config)" --menu "Nand install options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + "N1 Create partiotions" "Create partition table and file system. This will destroy your data on $NAND_DEVICE" \ + "N2 Install bootloader" "Allows to boot from nand" \ + "N3 Move data" "Install yours rootfs" \ + 3>&1 1>&2 2>&3) + RET=$? + if [ $RET -eq 1 ]; then + return 0 + elif [ $RET -eq 0 ]; then + case "$FUN" in + N1\ *) do_nand_create ;; + N2\ *) do_nand_boot ;; + N3\ *) do_nand_data ;; + *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; + esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 + fi +} + + +do_internationalisation_menu() { + FUN=$(whiptail --title "Cubieboard Pi Software Configuration Tool (cubie-config)" --menu "Internationalisation Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + "I1 Change Locale" "Set up language and regional settings to match your location" \ + "I2 Change Timezone" "Set up timezone to match your location" \ + "I3 Change Keyboard Layout" "Set the keyboard layout to match your keyboard" \ + 3>&1 1>&2 2>&3) + RET=$? + if [ $RET -eq 1 ]; then + return 0 + elif [ $RET -eq 0 ]; then + case "$FUN" in + I1\ *) do_change_locale ;; + I2\ *) do_change_timezone ;; + I3\ *) do_configure_keyboard ;; + *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; + esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 + fi +} + +do_advanced_menu() { + FUN=$(whiptail --title "Cubieboard Software Configuration Tool (cubie-config)" --menu "Advanced Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + "A1 Hostname" "Set the visible name for this Cubie on a network" \ + "A2 SSH" "Enable/Disable remote command line access to your Pi using SSH" \ + 3>&1 1>&2 2>&3) + RET=$? + if [ $RET -eq 1 ]; then + return 0 + elif [ $RET -eq 0 ]; then + case "$FUN" in + A1\ *) do_change_hostname ;; + A2\ *) do_ssh ;; + *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; + esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 + fi +} + + +# +# Interactive use loop +# +calc_wt_size +while true; do + FUN=$(whiptail --title "Cubieboard Software Configuration Tool (cubie-config)" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \ + "1 Expand Filesystem" "Ensures that all of the SD card storage is available to the OS" \ + "2 Change User Password" "Change password for the default user (cubie)" \ + "3 Enable Boot to Desktop" "Choose whether to boot into a desktop environment or the command-line" \ + "4 Internationalisation Options" "Set up language and regional settings to match your location" \ + "5 Advanced Options" "Configure advanced settings" \ + "6 Install on nand" "This will move your system from SD card to nand" \ + "7 About cubie-config" "Information about this configuration tool" \ + 3>&1 1>&2 2>&3) + RET=$? + if [ $RET -eq 1 ]; then + do_finish + elif [ $RET -eq 0 ]; then + case "$FUN" in + 1\ *) do_expand_rootfs ;; + 2\ *) do_change_pass ;; + 3\ *) do_boot_behaviour ;; + 4\ *) do_internationalisation_menu ;; + 5\ *) do_advanced_menu ;; + 6\ *) do_nandinstall_menu;; + 7\ *) do_about ;; + *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; + esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 + else + exit 1 + fi +done + diff --git a/exclude.txt b/exclude.txt new file mode 100644 index 0000000..6f24071 --- /dev/null +++ b/exclude.txt @@ -0,0 +1,9 @@ +/home/cubie/* +/boot/* +/dev/* +/proc/* +/sys/* +/media/* +/mnt/* +/run/* +/tmp/*