diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-05-21 09:10:50 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-05-21 09:10:50 +0200 |
commit | 3fe489609dabb0a0e1d4cdc4a57d9dd4bd8e553a (patch) | |
tree | 51c6ec469113dbdadab80ee5217119bd13082101 | |
parent | 307a6209a5dcbac88e83feee8a17a221fe0f2bee (diff) | |
parent | 3d37d661ed637cd92cb06465d9028f5c8ab35c31 (diff) | |
download | barebox-3fe489609dabb0a0e1d4cdc4a57d9dd4bd8e553a.tar.gz barebox-3fe489609dabb0a0e1d4cdc4a57d9dd4bd8e553a.tar.xz |
Merge branch 'pu/defenv-2' into next
43 files changed, 670 insertions, 76 deletions
diff --git a/arch/arm/boards/pcm038/env/boot/nand-ubi b/arch/arm/boards/pcm038/env/boot/nand-ubi new file mode 100644 index 000000000..a3f748e74 --- /dev/null +++ b/arch/arm/boards/pcm038/env/boot/nand-ubi @@ -0,0 +1,10 @@ +#!/bin/sh + +if [ "$1" = menu ]; then + boot-menu-add-entry "$0" "nand (UBI)" + exit +fi + +global.bootm.image="/dev/nand0.kernel.bb" +#global.bootm.oftree="/env/oftree" +bootargs-root-ubi -r root -m nand0.root diff --git a/arch/arm/boards/pcm038/env/config b/arch/arm/boards/pcm038/env/config deleted file mode 100644 index 32be5ec41..000000000 --- a/arch/arm/boards/pcm038/env/config +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/sh - -hostname=pcm038 -eth0.serverip= -user= - -# use 'dhcp' to do dhcp in barebox and in kernel -# use 'none' if you want to skip kernel ip autoconfiguration -ip=dhcp - -# or set your networking parameters here -#eth0.ipaddr=a.b.c.d -#eth0.netmask=a.b.c.d -#eth0.gateway=a.b.c.d -#eth0.serverip=a.b.c.d - -# can be either 'nfs', 'tftp', 'nor' or 'nand' -kernel_loc=tftp -# can be either 'net', 'nor', 'nand' or 'initrd' -rootfs_loc=net - -# can be either 'jffs2' or 'ubifs' -rootfs_type=ubifs -rootfsimage=root-$hostname.$rootfs_type - -kernelimage=zImage-$hostname -#kernelimage=uImage-$hostname -#kernelimage=Image-$hostname -#kernelimage=Image-$hostname.lzo - -if [ -n $user ]; then - kernelimage="$user"-"$kernelimage" - nfsroot="$eth0.serverip:/home/$user/nfsroot/$hostname" - rootfsimage="$user"-"$rootfsimage" -else - nfsroot="$eth0.serverip:/path/to/nfs/root" -fi - -autoboot_timeout=3 - -bootargs="console=ttymxc0,115200" - -nor_parts="512k(barebox)ro,128k(bareboxenv),2M(kernel),-(root)" -rootfs_mtdblock_nor=3 - -nand_parts="512k(barebox)ro,128k(bareboxenv),2M(kernel),-(root)" -rootfs_mtdblock_nand=7 -nand_device="mxc_nand" - -# set a fancy prompt (if support is compiled in) -PS1="\e[1;32mbarebox@\e[1;31m\h:\w\e[0m " - diff --git a/arch/arm/boards/pcm038/env/init/bootargs-base b/arch/arm/boards/pcm038/env/init/bootargs-base new file mode 100644 index 000000000..d86975406 --- /dev/null +++ b/arch/arm/boards/pcm038/env/init/bootargs-base @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ "$1" = menu ]; then + init-menu-add-entry "$0" "Base bootargs" + exit +fi + +global.linux.bootargs.base="console=ttymxc0,115200" diff --git a/arch/arm/boards/pcm038/env/init/hostname b/arch/arm/boards/pcm038/env/init/hostname new file mode 100644 index 000000000..09c2f08c3 --- /dev/null +++ b/arch/arm/boards/pcm038/env/init/hostname @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ "$1" = menu ]; then + init-menu-add-entry "$0" "hostname" + exit +fi + +global.hostname=pcm038 diff --git a/arch/arm/boards/pcm038/env/init/mtdparts-nand b/arch/arm/boards/pcm038/env/init/mtdparts-nand new file mode 100644 index 000000000..84220b77b --- /dev/null +++ b/arch/arm/boards/pcm038/env/init/mtdparts-nand @@ -0,0 +1,11 @@ +#!/bin/sh + +if [ "$1" = menu ]; then + init-menu-add-entry "$0" "NAND partitions" + exit +fi + +mtdparts="512k(nand0.barebox)ro,128k(nand0.bareboxenv),4M(nand0.kernel),-(nand0.root)" +kernelname="mxc_nand" + +mtdparts-add -b -d nand0 -k ${kernelname} -p ${mtdparts} diff --git a/arch/arm/boards/pcm038/env/init/mtdparts-nor b/arch/arm/boards/pcm038/env/init/mtdparts-nor new file mode 100644 index 000000000..c2c40655f --- /dev/null +++ b/arch/arm/boards/pcm038/env/init/mtdparts-nor @@ -0,0 +1,11 @@ +#!/bin/sh + +if [ "$1" = menu ]; then + init-menu-add-entry "$0" "NOR partitions" + exit +fi + +mtdparts="512k(nor0.barebox)ro,128k(nor0.bareboxenv),4M(nor0.kernel),-(nor0.root)" +kernelname="physmap-flash.0" + +mtdparts-add -d nor0 -k ${kernelname} -p ${mtdparts} diff --git a/arch/arm/configs/pcm038_defconfig b/arch/arm/configs/pcm038_defconfig index 4cb83e505..5ce4f7abc 100644 --- a/arch/arm/configs/pcm038_defconfig +++ b/arch/arm/configs/pcm038_defconfig @@ -12,21 +12,22 @@ CONFIG_MALLOC_SIZE=0x1000000 CONFIG_MALLOC_TLSF=y CONFIG_KALLSYMS=y CONFIG_LONGHELP=y -CONFIG_GLOB=y CONFIG_HUSH_FANCY_PROMPT=y CONFIG_CMDLINE_EDITING=y CONFIG_AUTO_COMPLETE=y +CONFIG_MENU=y CONFIG_PARTITION=y CONFIG_PARTITION_DISK=y -CONFIG_DEFAULT_ENVIRONMENT_GENERIC=y +CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y CONFIG_DEFAULT_ENVIRONMENT_PATH="arch/arm/boards/pcm038/env" CONFIG_CMD_EDIT=y CONFIG_CMD_SLEEP=y CONFIG_CMD_SAVEENV=y -CONFIG_CMD_LOADENV=y CONFIG_CMD_EXPORT=y CONFIG_CMD_PRINTENV=y CONFIG_CMD_READLINE=y +CONFIG_CMD_MENU=y +CONFIG_CMD_MENU_MANAGEMENT=y CONFIG_CMD_TIME=y CONFIG_CMD_ECHO_E=y CONFIG_CMD_MEMINFO=y @@ -54,9 +55,8 @@ CONFIG_CMD_UNCOMPRESS=y CONFIG_NET=y CONFIG_NET_DHCP=y CONFIG_NET_PING=y -CONFIG_NET_TFTP=y -CONFIG_NET_TFTP_PUSH=y CONFIG_NET_NETCONSOLE=y +CONFIG_NET_RESOLV=y CONFIG_DRIVER_NET_FEC_IMX=y CONFIG_NET_USB=y CONFIG_NET_USB_ASIX=y @@ -67,13 +67,13 @@ CONFIG_NAND=y # CONFIG_NAND_ECC_SOFT is not set # CONFIG_NAND_ECC_HW_SYNDROME is not set CONFIG_NAND_IMX=y -CONFIG_UBI=y CONFIG_USB=y CONFIG_USB_EHCI=y CONFIG_USB_ULPI=y CONFIG_VIDEO=y CONFIG_DRIVER_VIDEO_IMX=y CONFIG_IMXFB_DRIVER_VIDEO_IMX_OVERLAY=y +CONFIG_FS_TFTP=y +CONFIG_FS_NFS=y CONFIG_ZLIB=y CONFIG_LZO_DECOMPRESS=y -CONFIG_MFD_MC13XXX=y diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig index b402677d1..7905027b1 100644 --- a/arch/arm/mach-imx/Kconfig +++ b/arch/arm/mach-imx/Kconfig @@ -290,6 +290,7 @@ config MACH_PCM038 select SPI select DRIVER_SPI_IMX select MFD_MC13XXX + select HAVE_DEFAULT_ENVIRONMENT_NEW help Say Y here if you are using Phytec's phyCORE-i.MX27 (pcm038) equipped with a Freescale i.MX27 Processor diff --git a/commands/Kconfig b/commands/Kconfig index 1839538dd..52e1f171b 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -329,6 +329,7 @@ config CMD_BOOTM select CRC32 select UNCOMPRESS select FILETYPE + select GLOBALVAR prompt "bootm" config CMD_BOOTM_SHOW_TYPE diff --git a/commands/bootm.c b/commands/bootm.c index 0c0e56a61..2989d3931 100644 --- a/commands/bootm.c +++ b/commands/bootm.c @@ -47,6 +47,8 @@ #include <memory.h> #include <filetype.h> #include <binfmt.h> +#include <globalvar.h> +#include <magicvar.h> #include <asm-generic/memory_layout.h> static LIST_HEAD(handler_list); @@ -136,7 +138,7 @@ static int bootm_open_initrd_uimage(struct image_data *data) } #ifdef CONFIG_OFTREE -static int bootm_open_oftree(struct image_data *data, char *oftree, int num) +static int bootm_open_oftree(struct image_data *data, const char *oftree, int num) { enum filetype ft; struct fdt_header *fdt, *fixfdt; @@ -231,19 +233,25 @@ static struct image_handler *bootm_find_handler(enum filetype filetype, return NULL; } -static void bootm_image_name_and_no(char *name, int *no) +static char *bootm_image_name_and_no(const char *name, int *no) { - char *at; + char *at, *ret; + + if (!name || !*name) + return NULL; *no = 0; - at = strchr(name, '@'); + ret = xstrdup(name); + at = strchr(ret, '@'); if (!at) - return; + return ret; *at++ = 0; *no = simple_strtoul(at, NULL, 10); + + return ret; } #define BOOTM_OPTS_COMMON "ca:e:vo:f" @@ -261,7 +269,7 @@ static int do_bootm(int argc, char *argv[]) struct image_data data; int ret = 1; enum filetype os_type, initrd_type = filetype_unknown; - char *oftree = NULL; + const char *oftree = NULL, *initrd_file = NULL, *os_file = NULL; int fallback = 0; memset(&data, 0, sizeof(struct image_data)); @@ -271,6 +279,11 @@ static int do_bootm(int argc, char *argv[]) data.verify = 0; data.verbose = 0; + oftree = getenv("global.bootm.oftree"); + os_file = getenv("global.bootm.image"); + if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD)) + initrd_file = getenv("global.bootm.initrd"); + while ((opt = getopt(argc, argv, BOOTM_OPTS)) > 0) { switch(opt) { case 'c': @@ -281,7 +294,7 @@ static int do_bootm(int argc, char *argv[]) data.initrd_address = simple_strtoul(optarg, NULL, 0); break; case 'r': - data.initrd_file = optarg; + initrd_file = optarg; break; #endif case 'a': @@ -304,12 +317,21 @@ static int do_bootm(int argc, char *argv[]) } } - if (optind == argc) - return COMMAND_ERROR_USAGE; + if (optind != argc) + os_file = argv[optind]; + + if (!os_file || !*os_file) { + printf("no boot image given\n"); + goto err_out; + } + + if (initrd_file && !*initrd_file) + initrd_file = NULL; - data.os_file = argv[optind]; + if (oftree && !*oftree) + oftree = NULL; - bootm_image_name_and_no(data.os_file, &data.os_num); + data.os_file = bootm_image_name_and_no(os_file, &data.os_num); os_type = file_name_detect_type(data.os_file); if ((int)os_type < 0) { @@ -332,8 +354,8 @@ static int do_bootm(int argc, char *argv[]) } } - if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD) && data.initrd_file) { - bootm_image_name_and_no(data.initrd_file, &data.initrd_num); + if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD) && initrd_file) { + data.initrd_file = bootm_image_name_and_no(initrd_file, &data.initrd_num); initrd_type = file_name_detect_type(data.initrd_file); if ((int)initrd_type < 0) { @@ -388,7 +410,7 @@ static int do_bootm(int argc, char *argv[]) if (oftree) { int oftree_num; - bootm_image_name_and_no(oftree, &oftree_num); + oftree = bootm_image_name_and_no(oftree, &oftree_num); ret = bootm_open_oftree(&data, oftree, oftree_num); if (ret) @@ -417,6 +439,8 @@ static int do_bootm(int argc, char *argv[]) printf("handler failed with %s\n", strerror(-ret)); err_out: + free(data.initrd_file); + free(data.os_file); if (data.os_res) release_sdram_region(data.os_res); if (data.initrd_res) @@ -428,6 +452,18 @@ err_out: return 1; } +static int bootm_init(void) +{ + + globalvar_add_simple("bootm.image"); + globalvar_add_simple("bootm.oftree"); + if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD)) + globalvar_add_simple("bootm.initrd"); + + return 0; +} +late_initcall(bootm_init); + BAREBOX_CMD_HELP_START(bootm) BAREBOX_CMD_HELP_USAGE("bootm [OPTIONS] image\n") BAREBOX_CMD_HELP_SHORT("Boot an application image.\n") @@ -453,6 +489,8 @@ BAREBOX_CMD_START(bootm) BAREBOX_CMD_END BAREBOX_MAGICVAR(bootargs, "Linux Kernel parameters"); +BAREBOX_MAGICVAR_NAMED(global_bootm_image, global.bootm.image, "bootm default boot image"); +BAREBOX_MAGICVAR_NAMED(global_bootm_initrd, global.bootm.initrd, "bootm default initrd"); static struct binfmt_hook binfmt_uimage_hook = { .type = filetype_uimage, diff --git a/common/Kconfig b/common/Kconfig index 9f0e0f86f..34a6ea70e 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -495,8 +495,24 @@ endchoice endif +config HAVE_DEFAULT_ENVIRONMENT_NEW + bool + +config DEFAULT_ENVIRONMENT_GENERIC_NEW + bool + depends on DEFAULT_ENVIRONMENT + depends on SHELL_HUSH + select HUSH_GETOPT + select GLOB + select GLOB_SORT + select CMD_GLOBAL + select CMD_AUTOMOUNT + select FLEXIBLE_BOOTARGS + prompt "Generic environment template" + config DEFAULT_ENVIRONMENT_GENERIC bool + depends on !HAVE_DEFAULT_ENVIRONMENT_NEW depends on DEFAULT_ENVIRONMENT depends on SHELL_HUSH select HUSH_GETOPT @@ -512,9 +528,6 @@ config DEFAULT_ENVIRONMENT_GENERIC at least contain a /env/config file. This will be able to overwrite the files from defaultenv. -config HAVE_DEFAULT_ENVIRONMENT_NEW - bool - config DEFAULT_ENVIRONMENT_PATH string depends on DEFAULT_ENVIRONMENT diff --git a/common/Makefile b/common/Makefile index b49e6e014..a1926d346 100644 --- a/common/Makefile +++ b/common/Makefile @@ -42,6 +42,13 @@ ifdef CONFIG_DEFAULT_ENVIRONMENT $(obj)/startup.o: include/generated/barebox_default_env.h $(obj)/env.o: include/generated/barebox_default_env.h +ifeq ($(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW),y) +DEFAULT_ENVIRONMENT_PATH = "defaultenv-2/base" +ifeq ($(CONFIG_CMD_MENU_MANAGEMENT),y) +DEFAULT_ENVIRONMENT_PATH += "defaultenv-2/menu" +endif +endif + ifeq ($(CONFIG_DEFAULT_ENVIRONMENT_GENERIC),y) DEFAULT_ENVIRONMENT_PATH = "defaultenv" endif diff --git a/defaultenv-2/base/bin/boot b/defaultenv-2/base/bin/boot new file mode 100644 index 000000000..c5ad73dde --- /dev/null +++ b/defaultenv-2/base/bin/boot @@ -0,0 +1,18 @@ +#!/bin/sh + +if [ $# = 0 ]; then + scr="$global.boot.default" +else + scr="$1" +fi + +if [ -n "$scr" ]; then + if [ ! -f /env/boot/$scr ]; then + echo -e "/env/boot/$scr does not exist.\nValid choices:" + ls /env/boot + exit + fi + /env/boot/$scr +fi + +bootm diff --git a/defaultenv-2/base/bin/bootargs-ip b/defaultenv-2/base/bin/bootargs-ip new file mode 100644 index 000000000..15041c635 --- /dev/null +++ b/defaultenv-2/base/bin/bootargs-ip @@ -0,0 +1,11 @@ +#!/bin/sh + +# pass either static ip or dhcp to kernel based on barebox settings + +. /env/network/eth0 + +if [ $ip = dhcp ]; then + global.linux.bootargs.ip="ip=dhcp" +else + global.linux.bootargs.ip="ip=$ipaddr:$serverip:$gateway:$netmask::eth0:" +fi diff --git a/defaultenv-2/base/bin/bootargs-ip-barebox b/defaultenv-2/base/bin/bootargs-ip-barebox new file mode 100644 index 000000000..986c14228 --- /dev/null +++ b/defaultenv-2/base/bin/bootargs-ip-barebox @@ -0,0 +1,7 @@ +#!/bin/sh + +# pass barebox ip settings for eth0 to Linux + +ifup eth0 + +global.linux.bootargs.ip="ip=$eth0.ipaddr:$eth0.serverip:$eth0.gateway:$eth0.netmask::eth0:" diff --git a/defaultenv-2/base/bin/bootargs-ip-dhcp b/defaultenv-2/base/bin/bootargs-ip-dhcp new file mode 100644 index 000000000..c542b248f --- /dev/null +++ b/defaultenv-2/base/bin/bootargs-ip-dhcp @@ -0,0 +1,5 @@ +#!/bin/sh + +# Do dhcp in Linux + +global.linux.bootargs.ip="ip=dhcp" diff --git a/defaultenv-2/base/bin/bootargs-ip-none b/defaultenv-2/base/bin/bootargs-ip-none new file mode 100644 index 000000000..c01015465 --- /dev/null +++ b/defaultenv-2/base/bin/bootargs-ip-none @@ -0,0 +1,5 @@ +#!/bin/sh + +# disable ip setup in Linux + +global.linux.bootargs.ip="ip=none" diff --git a/defaultenv-2/base/bin/bootargs-root-initrd b/defaultenv-2/base/bin/bootargs-root-initrd new file mode 100644 index 000000000..4c596252e --- /dev/null +++ b/defaultenv-2/base/bin/bootargs-root-initrd @@ -0,0 +1,11 @@ +#!/bin/sh + +rdinit="/sbin/init" + +while getopt "i:" opt; do + if [ ${opt} = i ]; then + rdinit=${OPTARG} + fi +done + +global.linux.bootargs.root="root=/dev/ram0 rdinit=${rdinit}" diff --git a/defaultenv-2/base/bin/bootargs-root-jffs2 b/defaultenv-2/base/bin/bootargs-root-jffs2 new file mode 100644 index 000000000..db036dac6 --- /dev/null +++ b/defaultenv-2/base/bin/bootargs-root-jffs2 @@ -0,0 +1,9 @@ +#!/bin/sh + +while getopt "m:" opt; do + if [ ${opt} = m ]; then + mtd=${OPTARG} + fi +done + +global.linux.bootargs.root="root=$mtd rootfstype=jffs2" diff --git a/defaultenv-2/base/bin/bootargs-root-nfs b/defaultenv-2/base/bin/bootargs-root-nfs new file mode 100644 index 000000000..bf97555f4 --- /dev/null +++ b/defaultenv-2/base/bin/bootargs-root-nfs @@ -0,0 +1,15 @@ +#!/bin/sh + +while getopt "n:s:" opt; do + if [ ${opt} = n ]; then + nfsroot=${OPTARG} + elif [ ${opt} = s ]; then + serverip=${OPTARG} + fi +done + +if [ -n ${serverip} ]; then + nfsroot="$serverip:$nfsroot" +fi + +global.linux.bootargs.root="root=/dev/nfs nfsroot=$nfsroot,v3,tcp" diff --git a/defaultenv-2/base/bin/bootargs-root-ubi b/defaultenv-2/base/bin/bootargs-root-ubi new file mode 100644 index 000000000..ef891041d --- /dev/null +++ b/defaultenv-2/base/bin/bootargs-root-ubi @@ -0,0 +1,13 @@ +#!/bin/sh + +ubiroot=root + +while getopt "m:r:" opt; do + if [ ${opt} = r ]; then + ubiroot=${OPTARG} + elif [ ${opt} = m ]; then + mtd=${OPTARG} + fi +done + +global.linux.bootargs.root="root=ubi0:$ubiroot ubi.mtd=$mtd rootfstype=ubifs" diff --git a/defaultenv-2/base/bin/ifup b/defaultenv-2/base/bin/ifup new file mode 100644 index 000000000..9f6fd6bc4 --- /dev/null +++ b/defaultenv-2/base/bin/ifup @@ -0,0 +1,59 @@ +#!/bin/sh + +mkdir -p /tmp/network + +if [ $# != 1 ]; then + echo "usage: ifup <interface>" + exit 1 +fi + +interface="$1" + +if [ -f /tmp/network/$interface ]; then + exit 0 +fi + +cmd=/env/network/$interface + +if [ ! -e $cmd ]; then + echo "$f: no such file" + exit 1 +fi + +ip= +ipaddr= +netmask= +gateway= +serverip= +ethaddr= + +. $cmd + +if [ $? != 0 ]; then + echo "failed to bring up $interface" + exit 1 +fi + +if [ -f /env/network/${interface}-discover ]; then + /env/network/${interface}-discover + if [ $? != 0 ]; then + echo "failed to discover eth0" + exit 1 + fi +fi + +if [ -n "$ethaddr" ]; then + ${interface}.ethaddr=$ethaddr +fi + +if [ "$ip" = static ]; then + ${interface}.ipaddr=$ipaddr + ${interface}.netmask=$netmask + ${interface}.serverip=$serverip + ${interface}.gateway=$gateway +elif [ "$ip" = dhcp ]; then + dhcp + exit $? +fi + +echo -o /tmp/network/$interface up diff --git a/defaultenv-2/base/bin/init b/defaultenv-2/base/bin/init new file mode 100644 index 000000000..e293c62b0 --- /dev/null +++ b/defaultenv-2/base/bin/init @@ -0,0 +1,46 @@ +#!/bin/sh + +export PATH=/env/bin + +global hostname=generic +global user=none +global tftp.server +global tftp.path=/mnt/tftp-dhcp +global autoboot_timeout=3 +global boot.default=net +global allow_color=true +global linux.bootargs.base +global linux.bootargs.ip +global linux.bootargs.root +global editcmd=sedit + +/env/init/general + +if [ -e /env/menu ]; then + echo -e -n "\nHit m for menu or any other key to stop autoboot: " +else + echo -e -n "\nHit any key to stop autoboot: " +fi + +timeout -a $global.autoboot_timeout -v key +autoboot="$?" + +if [ "${key}" = "q" ]; then + exit +fi + +for i in /env/init/*; do + . $i +done + +if [ "$autoboot" = 0 ]; then + boot +fi + +if [ -e /env/menu ]; then + if [ "${key}" != "m" ]; then + echo -e "\ntype exit to get to the menu" + sh + fi + /env/menu/mainmenu +fi diff --git a/defaultenv-2/base/bin/mtdparts-add b/defaultenv-2/base/bin/mtdparts-add new file mode 100644 index 000000000..58c9fa7a2 --- /dev/null +++ b/defaultenv-2/base/bin/mtdparts-add @@ -0,0 +1,49 @@ +#!/bin/sh + +mkdir -p /tmp/mtdparts + +parts= +device= +kernelname= +bbdev= + +while getopt "p:d:k:b" opt; do + if [ ${opt} = p ]; then + parts=${OPTARG} + elif [ ${opt} = d ]; then + device=${OPTARG} + elif [ ${opt} = k ]; then + kernelname=${OPTARG} + elif [ ${opt} = b ]; then + bbdev=true + fi +done + +if [ -z "${device}" ]; then + echo "$0: no device given" + exit +fi + +if [ -z "${parts}" ]; then + echo "$0: no partitions given" + exit +fi + +if [ -e /tmp/mtdparts/${device} ]; then + if [ -n "/dev/${device}.*.bb" ]; then + nand -d /dev/${device}.*.bb + fi + delpart /dev/${device}.* +fi + +addpart -n /dev/${device} "$parts" || exit +mkdir -p /tmp/mtdparts/${device} + +if [ -n "${bbdev}" ]; then + nand -a /dev/${device}.* +fi + +if [ -n ${kernelname} ]; then + global linux.mtdparts.${device} + global.linux.mtdparts.${device}="${kernelname}:${parts}" +fi diff --git a/defaultenv-2/base/boot/initrd b/defaultenv-2/base/boot/initrd new file mode 100644 index 000000000..1a1e629bc --- /dev/null +++ b/defaultenv-2/base/boot/initrd @@ -0,0 +1,16 @@ +#!/bin/sh + +if [ "$1" = menu ]; then + boot-menu-add-entry "$0" "kernel + initrd via tftp" + exit +fi + +global.bootm.image="${global.tftp.path}/${global.user}-linux-${global.hostname}" +global.bootm.initrd="${global.tftp.path}/initramfs" +bootargs-root-initrd +#global.bootm.oftree=<path to oftree> + +global.linux.bootargs.root="root=/dev/ram0" + +#bootargs-root-nfs -n "<path on server>" -s <serverip> +#bootargs-root-ubi -r <volume> -m <mtdname> diff --git a/defaultenv-2/base/boot/net b/defaultenv-2/base/boot/net new file mode 100644 index 000000000..2684c20a6 --- /dev/null +++ b/defaultenv-2/base/boot/net @@ -0,0 +1,12 @@ +#!/bin/sh + +if [ "$1" = menu ]; then + boot-menu-add-entry "$0" "network (tftp, nfs)" + exit +fi + +global.bootm.image="${global.tftp.path}/${global.user}-linux-${global.hostname}" +#global.bootm.oftree="${global.tftp.path}/${global.user}-oftree-${global.hostname}" +nfsroot="/home/${global.user}/nfsroot/${global.hostname}" +bootargs-ip +bootargs-root-nfs -n "$nfsroot" diff --git a/defaultenv-2/base/data/ansi-colors b/defaultenv-2/base/data/ansi-colors new file mode 100644 index 000000000..c71b6b799 --- /dev/null +++ b/defaultenv-2/base/data/ansi-colors @@ -0,0 +1,26 @@ +#!/bin/sh + +# Colors +export RED='\e[1;31m' +export BLUE='\e[1;34m' +export GREEN='\e[1;32m' +export CYAN='\e[1;36m' +export YELLOW='\e[1;33m' +export PINK='\e[1;35m' +export WHITE='\e[1;37m' + +export DARK_RED='\e[2;31m' +export DARK_BLUE='\e[2;34m' +export DARK_GREEN='\e[2;32m' +export DARK_CYAN='\e[2;36m' +export DARK_YELLOW='\e[2;33m' +export DARK_PINK='\e[2;35m' +export DARK_WHITE='\e[2;37m' + +export RED_INV='\e[1;41m' +export BLUE_INV='\e[1;44m' +export GREEN_INV='\e[1;42m' +export CYAN_INV='\e[1;46m' +export ORANGE_INV='\e[1;43m' +export PINK_INV='\e[1;45m' +export NC='\e[0m' # No Color diff --git a/defaultenv-2/base/data/boot-template b/defaultenv-2/base/data/boot-template new file mode 100644 index 000000000..1cacf18bf --- /dev/null +++ b/defaultenv-2/base/data/boot-template @@ -0,0 +1,16 @@ +#!/bin/sh + +if [ "$1" = menu ]; then + boot-menu-add-entry "$0" "<menu text here>" + exit +fi + +global.bootm.image=<path to image> +#global.bootm.oftree=<path to oftree> +#global.bootm.initrd=<path to initrd> + +#bootargs-ip + +#bootargs-root-nfs -n "<path on server>" -s <serverip> +#bootargs-root-jffs2 -m <mtdname> +#bootargs-root-ubi -r <volume> -m <mtdname> diff --git a/defaultenv-2/base/init/automount b/defaultenv-2/base/init/automount new file mode 100644 index 000000000..e02922217 --- /dev/null +++ b/defaultenv-2/base/init/automount @@ -0,0 +1,27 @@ +#!/bin/sh + +if [ "$1" = menu ]; then + init-menu-add-entry "$0" "Automountpoints" + exit +fi + +# automount server returned from dhcp server + +mkdir -p /mnt/tftp-dhcp +automount /mnt/tftp-dhcp 'ifup eth0; mount $eth0.serverip tftp /mnt/tftp-dhcp' + +# automount nfs server example + +#nfshost=somehost +#mkdir -p /mnt/${nfshost} +#automount /mnt/$nfshost "ifup eth0; mount ${nfshost}:/tftpboot nfs /mnt/${nfshost}" + +# static tftp server example + +#mkdir -p /mnt/tftp +#automount -d /mnt/tftp 'ifup eth0; mount $serverip tftp /mnt/tftp' + +# FAT on usb disk example + +#mkdir -p /mnt/fat +#automount -d /mnt/fat 'usb; mount /dev/usbdisk0.0 fat $automount_path' diff --git a/defaultenv-2/base/init/bootargs-base b/defaultenv-2/base/init/bootargs-base new file mode 100644 index 000000000..8e588ad43 --- /dev/null +++ b/defaultenv-2/base/init/bootargs-base @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ "$1" = menu ]; then + init-menu-add-entry "$0" "Base bootargs" + exit +fi + +global.linux.bootargs.base="console=ttyS0,115200" diff --git a/defaultenv-2/base/init/general b/defaultenv-2/base/init/general new file mode 100644 index 000000000..ad6c8600a --- /dev/null +++ b/defaultenv-2/base/init/general @@ -0,0 +1,18 @@ +#!/bin/sh + +if [ "$1" = menu ]; then + init-menu-add-entry "$0" "general config settings" + exit +fi + +# user (used for network filenames) +global.user=sha + +# timeout in seconds before the default boot entry is started +global.autoboot_timeout=3 + +# default boot entry (one of /env/boot/*) +global.boot.default=net + +# default tftp path +global.tftp.path=/mnt/tftp-dhcp diff --git a/defaultenv-2/base/init/hostname b/defaultenv-2/base/init/hostname new file mode 100644 index 000000000..57a2c9479 --- /dev/null +++ b/defaultenv-2/base/init/hostname @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ "$1" = menu ]; then + init-menu-add-entry "$0" "hostname" + exit +fi + +global.hostname=generic diff --git a/defaultenv-2/base/init/prompt b/defaultenv-2/base/init/prompt new file mode 100644 index 000000000..11dce9fe0 --- /dev/null +++ b/defaultenv-2/base/init/prompt @@ -0,0 +1,7 @@ +#!/bin/sh + +if [ ${global.allow_color} = "true" ]; then + export PS1="\e[1;32mbarebox@\e[1;36m\h:\w\e[0m " +else + export PS1="barebox@\h:\w " +fi diff --git a/defaultenv-2/base/network/eth0 b/defaultenv-2/base/network/eth0 new file mode 100644 index 000000000..048a28824 --- /dev/null +++ b/defaultenv-2/base/network/eth0 @@ -0,0 +1,15 @@ +#!/bin/sh + +# ip setting (static/dhcp) +ip=dhcp + +# static setup used if ip=static +ipaddr= +netmask= +gateway= +serverip= + +# MAC address if needed +#ethaddr=xx:xx:xx:xx:xx:xx + +# put code to discover eth0 (i.e. 'usb') to /env/network/eth0-discover diff --git a/defaultenv-2/menu/menu/boot-entries-collect b/defaultenv-2/menu/menu/boot-entries-collect new file mode 100644 index 000000000..c066c930a --- /dev/null +++ b/defaultenv-2/menu/menu/boot-entries-collect @@ -0,0 +1,13 @@ +#!/bin/sh + +cd /env/boot + +./$global.boot.default menu + +for i in *; do + if [ "$i" != "$global.boot.default" ]; then + ./$i menu + fi +done + +cd / diff --git a/defaultenv-2/menu/menu/boot-entries-edit b/defaultenv-2/menu/menu/boot-entries-edit new file mode 100644 index 000000000..c4e1c3d5f --- /dev/null +++ b/defaultenv-2/menu/menu/boot-entries-edit @@ -0,0 +1,20 @@ +#!/bin/sh + +export menu_exit=false + +while true; do + menu -a -m boot_entries_edit -d "\e[1;36mEdit boot entries\e[0m" + + boot-entries-collect + + menu -e -a -m boot_entries_edit -c "boot-menu-new-boot-entry" -d "Add a new entry" + menu -e -a -m boot_entries_edit -c "boot-entries-remove" -d "Remove an entry" + menu -e -a -m boot_entries_edit -c "menu_exit=true" -d "back" + + menu -s -m boot_entries_edit + menu -r -m boot_entries_edit + + if [ $menu_exit = true ]; then + exit + fi +done diff --git a/defaultenv-2/menu/menu/boot-entries-remove b/defaultenv-2/menu/menu/boot-entries-remove new file mode 100644 index 000000000..566be9dd6 --- /dev/null +++ b/defaultenv-2/menu/menu/boot-entries-remove @@ -0,0 +1,18 @@ +#!/bin/sh + +export menu_exit=false + +while true; do + menu -a -m boot_entries_remove -d "\e[1;36mRemove Boot entry\e[0m" + + boot-entries-collect + + menu -e -a -m boot_entries_remove -c "menu_exit=true" -d "back" + + menu -s -m boot_entries_remove + menu -r -m boot_entries_remove + + if [ $menu_exit = true ]; then + exit + fi +done diff --git a/defaultenv-2/menu/menu/boot-menu-add-entry b/defaultenv-2/menu/menu/boot-menu-add-entry new file mode 100644 index 000000000..7e1d9c6d5 --- /dev/null +++ b/defaultenv-2/menu/menu/boot-menu-add-entry @@ -0,0 +1,5 @@ +#!/bin/sh + +menu -e -a -m boot -c "boot $1" -d "Boot: ${GREEN}$2${NC}" +menu -e -a -m boot_entries_edit -c "$global.editcmd /env/boot/$1" -d "${GREEN}$2${NC}" +menu -e -a -m boot_entries_remove -c "rm /env/boot/$1" -d "${GREEN}$2${NC}" diff --git a/defaultenv-2/menu/menu/boot-menu-new-boot-entry b/defaultenv-2/menu/menu/boot-menu-new-boot-entry new file mode 100644 index 000000000..c5e982cdb --- /dev/null +++ b/defaultenv-2/menu/menu/boot-menu-new-boot-entry @@ -0,0 +1,21 @@ +#!/bin/sh + +name= + +readline "Name of the new entry: " name + +if [ -z "$name" ]; then + exit 1 +fi + +if [ -e "/env/boot/$name" ]; then + echo "entry $name already exists" + readline "<enter>" unused + exit 1 +fi + +cp /env/data/boot-template /env/boot/$name + +edit /env/boot/$name + +boot-menu-show rebuild diff --git a/defaultenv-2/menu/menu/init-entries-collect b/defaultenv-2/menu/menu/init-entries-collect new file mode 100644 index 000000000..dbb775779 --- /dev/null +++ b/defaultenv-2/menu/menu/init-entries-collect @@ -0,0 +1,9 @@ +#!/bin/sh + +cd /env/init + +for i in *; do + ./$i menu +done + +cd / diff --git a/defaultenv-2/menu/menu/init-entries-edit b/defaultenv-2/menu/menu/init-entries-edit new file mode 100644 index 000000000..fc02b327d --- /dev/null +++ b/defaultenv-2/menu/menu/init-entries-edit @@ -0,0 +1,20 @@ +#!/bin/sh + +export menu_exit=false + +while true; do + menu -a -m init_entries_edit -d "\e[1;36mEdit init entries\e[0m" + + menu -e -a -m init_entries_edit -R -c "true" -d ">> Reset board to let changes here take effect <<" + + init-entries-collect + + menu -e -a -m init_entries_edit -c "menu_exit=true" -d "back" + + menu -s -m init_entries_edit + menu -r -m init_entries_edit + + if [ $menu_exit = true ]; then + exit + fi +done diff --git a/defaultenv-2/menu/menu/init-menu-add-entry b/defaultenv-2/menu/menu/init-menu-add-entry new file mode 100644 index 000000000..7cb568640 --- /dev/null +++ b/defaultenv-2/menu/menu/init-menu-add-entry @@ -0,0 +1,3 @@ +#!/bin/sh + +menu -e -a -m init_entries_edit -c "$global.editcmd /env/init/$1" -d "\e[1;32m$2\e[0m" diff --git a/defaultenv-2/menu/menu/mainmenu b/defaultenv-2/menu/menu/mainmenu new file mode 100644 index 000000000..d7b003322 --- /dev/null +++ b/defaultenv-2/menu/menu/mainmenu @@ -0,0 +1,28 @@ +#!/bin/sh + +savepath=$PATH +export menupath=$PATH:/env/menu + +if [ ${global.allow_color} = "true" ]; then + . /env/data/ansi-colors +fi + +while true; do + export PATH=${menupath} + + echo $PATH + + menu -a -m boot -d "${CYAN}Welcome to Barebox${NC}" + + boot-entries-collect + + menu -e -a -R -m boot -c "$global.editcmd /env/network/eth0" -d "Network settings" + menu -e -a -m boot -c "boot-entries-edit" -d "Edit boot entries" + menu -e -a -m boot -c "init-entries-edit" -d "Edit init entries" + menu -e -a -R -m boot -c "saveenv || echo \"failed to save environment\" && sleep 2" -d "Save settings" + menu -e -a -m boot -c 'PATH=$savepath; echo "enter exit to return to menu"; sh' -d "${DARK_YELLOW}Shell${NC}" + menu -e -a -m boot -c reset -d "${RED}Reset${NC}" + + menu -s -m boot + menu -r -m boot +done |