diff options
author | Wolfgang Denk <wd@denx.de> | 2011-10-21 23:35:12 +0200 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2011-10-21 23:35:12 +0200 |
commit | 1b81f017b04b5a176f5f9230ec979f0f3c55ba5b (patch) | |
tree | e13192c738bcb50238f6a60ef0448b1e2eec516a | |
parent | d639a8ccb0aa3c8c9d4ba0b642951f5534dcbdf1 (diff) | |
parent | 3a8653b3ac11b5ee56ce2b8f795826b8bf01eff2 (diff) |
Merge branch 'master' of /home/wd/git/u-boot/master
* 'master' of /home/wd/git/u-boot/master:
cosmetic: Fixup fixup_silent_linux() for checkpatch
Correct dependency rule to fix SPL build
Move timestamp and version files into 'generated' subdir
sandbox: Makefile changes to build sandbox architecture
Add generic gpio.h in asm-generic
Adjust dependency rules to permit per-file flags
sandbox: Use uintptr_t for 32/64-bit compatibility
sandbox: Add basic config file
sandbox: Add serial uart
sandbox: Add main program
sandbox: Add OS dependent layer
sandbox: Force command sections to be 4-byte aligned
sandbox: Disable standalone/API support
sandbox: Disable built-in malloc
sandbox: Add bootm support
sandbox: Add board info for architecture
sandbox: Add sandbox board
sandbox: Add architecture lib files
sandbox: Add cpu files
sandbox: Add compiler defines to support a 64-bit x86_64 platform
sandbox: Add architecture image support
Fix use of int as pointer in image.c
sandbox: Add architecture header files
arm: ca9x4_ct_vxp: enable PXE BOOTP options support
arm: ca9x4_ct_vxp: enable pxe command support
Convert ca9x4_ct_vxp to standard env variables
net: bootp: add PXE/RFC 4578 DHCP options support
Add pxe command
lib: add uuid_str_to_bin for use with bootp and PXE uuid
README: document standard image variables
Replace space and tab checks with isblank
cosmetic: remove unneeded curly braces
Add isblank
common: add run_command2 for running simple or hush commands
common, menu: use abortboot for menu timeout
Add generic, reusable menu code
DM9000:Add a byte swap macro for dm9000 io operation.
kw_gpio: fix error in kw_gpio_direction_input
Blackfin: bfin_spi: fix build error when DEBUG is defined
Blackfin: define CONFIG_SYS_CACHELINE_SIZE
video: Moving mx3fb.c to CONFIG_VIDEO
mx31: make HSP clock for mx3fb driver available
MX5: Make IPU display output and pixel format configurable
VIDEO: MX5: export pix format
VIDEO: MX5: Switch MX5 to CONFIG_VIDEO
video: update the Freescale DIU driver to use linux/fb.h
powerpc: cpm2 boards: update fcc register logic
98 files changed, 4369 insertions, 186 deletions
diff --git a/.gitignore b/.gitignore index 0a9dc0c75a..320d21e6c4 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,7 @@ # Generated files # -*.depend +*.depend* /LOG /errlog /reloc_off @@ -30,8 +30,8 @@ U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) else U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL)$(EXTRAVERSION) endif -TIMESTAMP_FILE = $(obj)include/timestamp_autogenerated.h -VERSION_FILE = $(obj)include/version_autogenerated.h +TIMESTAMP_FILE = $(obj)include/generated/timestamp_autogenerated.h +VERSION_FILE = $(obj)include/generated/version_autogenerated.h HOSTARCH := $(shell uname -m | \ sed -e s/i.86/x86/ \ @@ -137,9 +137,7 @@ unexport CDPATH # The "tools" are needed early, so put this first # Don't include stuff already done in $(LIBS) -SUBDIRS = tools \ - examples/standalone \ - examples/api +SUBDIRS = tools .PHONY : $(SUBDIRS) $(VERSION_FILE) $(TIMESTAMP_FILE) @@ -156,6 +154,11 @@ sinclude $(obj)include/autoconf.mk include $(obj)include/config.mk export ARCH CPU BOARD VENDOR SOC +ifndef CONFIG_SANDBOX +SUBDIRS += examples/standalone \ + examples/api +endif + # set default to nothing for native builds ifeq ($(HOSTARCH),$(ARCH)) CROSS_COMPILE ?= @@ -400,12 +403,20 @@ $(obj)u-boot.ubl: $(obj)u-boot-nand.bin $(obj)tools/mkimage -n $(UBL_CONFIG) -T ublimage \ -e $(CONFIG_SYS_TEXT_BASE) -d $< $@ +ifeq ($(CONFIG_SANDBOX),y) +GEN_UBOOT = \ + cd $(LNDIR) && $(CC) $(SYMS) -T $(obj)u-boot.lds \ + -Wl,--start-group $(__LIBS) -Wl,--end-group \ + $(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map -o u-boot +else GEN_UBOOT = \ UNDEF_SYM=`$(OBJDUMP) -x $(LIBBOARD) $(LIBS) | \ sed -n -e 's/.*\($(SYM_PREFIX)__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\ cd $(LNDIR) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) $$UNDEF_SYM $(__OBJS) \ --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \ -Map u-boot.map -o u-boot +endif + $(obj)u-boot: depend \ $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT) $(obj)u-boot.lds $(GEN_UBOOT) @@ -952,7 +963,7 @@ clean: | xargs rm -f clobber: clean - @find $(OBJTREE) -type f \( -name '*.depend' \ + @find $(OBJTREE) -type f \( -name '*.depend*' \ -o -name '*.srec' -o -name '*.bin' -o -name u-boot.img \) \ -print0 \ | xargs -0 rm -f @@ -3558,6 +3558,25 @@ List of environment variables (most likely not complete): Ethernet is encapsulated/received over 802.1q VLAN tagged frames. +The following image location variables contain the location of images +used in booting. The "Image" column gives the role of the image and is +not an environment variable name. The other columns are environment +variable names. "File Name" gives the name of the file on a TFTP +server, "RAM Address" gives the location in RAM the image will be +loaded to, and "Flash Location" gives the image's address in NOR +flash or offset in NAND flash. + +*Note* - these variables don't have to be defined for all boards, some +boards currenlty use other variables for these purposes, and some +boards use these variables for other purposes. + +Image File Name RAM Address Flash Location +----- --------- ----------- -------------- +u-boot u-boot u-boot_addr_r u-boot_addr +Linux kernel bootfile kernel_addr_r kernel_addr +device tree blob fdtfile fdt_addr_r fdt_addr +ramdisk ramdiskfile ramdisk_addr_r ramdisk_addr + The following environment variables may be used and automatically updated by the network boot commands ("bootp" and "rarpboot"), depending the information provided by your boot server: diff --git a/arch/arm/cpu/armv7/omap-common/spl.c b/arch/arm/cpu/armv7/omap-common/spl.c index c76fea6188..01fd58a354 100644 --- a/arch/arm/cpu/armv7/omap-common/spl.c +++ b/arch/arm/cpu/armv7/omap-common/spl.c @@ -29,8 +29,7 @@ #include <nand.h> #include <mmc.h> #include <fat.h> -#include <timestamp_autogenerated.h> -#include <version_autogenerated.h> +#include <version.h> #include <asm/omap_common.h> #include <asm/arch/mmc_host_def.h> #include <i2c.h> diff --git a/arch/arm/cpu/armv7/omap-common/spl_mmc.c b/arch/arm/cpu/armv7/omap-common/spl_mmc.c index 1d1e50c3c4..6f5b43e559 100644 --- a/arch/arm/cpu/armv7/omap-common/spl_mmc.c +++ b/arch/arm/cpu/armv7/omap-common/spl_mmc.c @@ -28,8 +28,7 @@ #include <asm/arch/sys_proto.h> #include <mmc.h> #include <fat.h> -#include <timestamp_autogenerated.h> -#include <version_autogenerated.h> +#include <version.h> #include <asm/omap_common.h> #include <asm/arch/mmc_host_def.h> diff --git a/arch/arm/cpu/armv7/omap-common/spl_nand.c b/arch/arm/cpu/armv7/omap-common/spl_nand.c index af02a59557..38d06b1ea8 100644 --- a/arch/arm/cpu/armv7/omap-common/spl_nand.c +++ b/arch/arm/cpu/armv7/omap-common/spl_nand.c @@ -25,8 +25,7 @@ #include <asm/utils.h> #include <asm/arch/sys_proto.h> #include <nand.h> -#include <timestamp_autogenerated.h> -#include <version_autogenerated.h> +#include <version.h> #include <asm/omap_common.h> diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk new file mode 100644 index 0000000000..ab330265e6 --- /dev/null +++ b/arch/sandbox/config.mk @@ -0,0 +1,20 @@ +# Copyright (c) 2011 The Chromium OS Authors. +# See file CREDITS for list of people who contributed to this +# project. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program 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. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA + +PLATFORM_CPPFLAGS += -DCONFIG_SANDBOX -D__SANDBOX__ diff --git a/arch/sandbox/cpu/Makefile b/arch/sandbox/cpu/Makefile new file mode 100644 index 0000000000..e5e860b715 --- /dev/null +++ b/arch/sandbox/cpu/Makefile @@ -0,0 +1,50 @@ +# +# Copyright (c) 2011 The Chromium OS Authors. +# +# (C) Copyright 2000-2003 +# Wolfgang Denk, DENX Software Engineering, wd@denx.de. +# +# See file CREDITS for list of people who contributed to this +# project. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program 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. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +# os.c is build in the system environment, so needs standard includes +CPPFLAGS_arch/sandbox/cpu/os.o += -I/usr/include + +include $(TOPDIR)/config.mk + +LIB = $(obj)lib$(CPU).o + +COBJS := cpu.o start.o os.o + +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS)) + +all: $(obj).depend $(LIB) + +$(LIB): $(OBJS) + $(call cmd_link_o_target, $(OBJS)) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c new file mode 100644 index 0000000000..c7bf8a9155 --- /dev/null +++ b/arch/sandbox/cpu/cpu.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <common.h> +#include <os.h> + +DECLARE_GLOBAL_DATA_PTR; + +int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + /* This is considered normal termination for now */ + os_exit(0); + return 0; +} + +/* delay x useconds */ +void __udelay(unsigned long usec) +{ + /* Ignore this for now */ +} + +unsigned long timer_get_us(void) +{ + return 0; +} + +int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images) +{ + return -1; +} + +int cleanup_before_linux(void) +{ + return 0; +} + +void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) +{ + return (void *)(gd->ram_buf + paddr); +} + +void flush_dcache_range(unsigned long start, unsigned long stop) +{ +} diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c new file mode 100644 index 0000000000..6c175d462a --- /dev/null +++ b/arch/sandbox/cpu/os.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include <os.h> + +/* Operating System Interface */ + +ssize_t os_read(int fd, void *buf, size_t count) +{ + return read(fd, buf, count); +} + +ssize_t os_write(int fd, const void *buf, size_t count) +{ + return write(fd, buf, count); +} + +int os_open(const char *pathname, int flags) +{ + return open(pathname, flags); +} + +int os_close(int fd) +{ + return close(fd); +} + +void os_exit(int exit_code) +{ + exit(exit_code); +} diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c new file mode 100644 index 0000000000..685793e91e --- /dev/null +++ b/arch/sandbox/cpu/start.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <common.h> + +int main(int argc, char *argv[]) +{ + /* + * Do pre- and post-relocation init, then start up U-Boot. This will + * never return. + */ + board_init_f(0); + + return 0; +} diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds new file mode 100644 index 0000000000..2d2e50fdbf --- /dev/null +++ b/arch/sandbox/cpu/u-boot.lds @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +SECTIONS +{ + __u_boot_cmd_start = .; + .u_boot_cmd : { *(.u_boot_cmd) } + __u_boot_cmd_end = .; + __bss_start = .; + +} + +INSERT BEFORE .data; diff --git a/arch/sandbox/include/asm/bitops.h b/arch/sandbox/include/asm/bitops.h new file mode 100644 index 0000000000..74219c56a7 --- /dev/null +++ b/arch/sandbox/include/asm/bitops.h @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * Copyright 1995, Russell King. + * Various bits and pieces copyrights include: + * Linus Torvalds (test_bit). + * + * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1). + * + * Please note that the code in this file should never be included + * from user space. Many of these are not implemented in assembler + * since they would be too costly. Also, they require priviledged + * instructions (which are not available from user mode) to ensure + * that they are atomic. + */ + +#ifndef __ASM_SANDBOX_BITOPS_H +#define __ASM_SANDBOX_BITOPS_H + +#include <asm/system.h> + +#ifdef __KERNEL__ + +#define smp_mb__before_clear_bit() do { } while (0) +#define smp_mb__after_clear_bit() do { } while (0) + +/* + * Function prototypes to keep gcc -Wall happy. + */ +extern void set_bit(int nr, void *addr); + +extern void clear_bit(int nr, void *addr); + +extern void change_bit(int nr, void *addr); + +static inline void __change_bit(int nr, void *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + + *p ^= mask; +} + +static inline int __test_and_set_bit(int nr, void *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + unsigned long old = *p; + + *p = old | mask; + return (old & mask) != 0; +} + +static inline int test_and_set_bit(int nr, void *addr) +{ + unsigned long flags; + int out; + + local_irq_save(flags); + out = __test_and_set_bit(nr, addr); + local_irq_restore(flags); + + return out; +} + +static inline int __test_and_clear_bit(int nr, void *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + unsigned long old = *p; + + *p = old & ~mask; + return (old & mask) != 0; +} + +static inline int test_and_clear_bit(int nr, void *addr) +{ + unsigned long flags; + int out; + + local_irq_save(flags); + out = __test_and_clear_bit(nr, addr); + local_irq_restore(flags); + + return out; +} + +extern int test_and_change_bit(int nr, void *addr); + +static inline int __test_and_change_bit(int nr, void *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + unsigned long old = *p; + + *p = old ^ mask; + return (old & mask) != 0; +} + +extern int find_first_zero_bit(void *addr, unsigned size); +extern int find_next_zero_bit(void *addr, int size, int offset); + +/* + * This routine doesn't need to be atomic. + */ +static inline int test_bit(int nr, const void *addr) +{ + return ((unsigned char *) addr)[nr >> 3] & (1U << (nr & 7)); +} + +/* + * ffz = Find First Zero in word. Undefined if no zero exists, + * so code should check against ~0UL first.. + */ +static inline unsigned long ffz(unsigned long word) +{ + int k; + + word = ~word; + k = 31; + if (word & 0x0000ffff) { + k -= 16; word <<= 16; + } + if (word & 0x00ff0000) { + k -= 8; word <<= 8; + } + if (word & 0x0f000000) { + k -= 4; word <<= 4; + } + if (word & 0x30000000) { + k -= 2; word <<= 2; + } + if (word & 0x40000000) + k -= 1; + return k; +} + +/* + * hweightN: returns the hamming weight (i.e. the number + * of bits set) of a N-bit word + */ + +#define hweight32(x) generic_hweight32(x) +#define hweight16(x) generic_hweight16(x) +#define hweight8(x) generic_hweight8(x) + +#define ext2_set_bit test_and_set_bit +#define ext2_clear_bit test_and_clear_bit +#define ext2_test_bit test_bit +#define ext2_find_first_zero_bit find_first_zero_bit +#define ext2_find_next_zero_bit find_next_zero_bit + +/* Bitmap functions for the minix filesystem. */ +#define minix_test_and_set_bit(nr, addr) test_and_set_bit(nr, addr) +#define minix_set_bit(nr, addr) set_bit(nr, addr) +#define minix_test_and_clear_bit(nr, addr) test_and_clear_bit(nr, addr) +#define minix_test_bit(nr, addr) test_bit(nr, addr) +#define minix_find_first_zero_bit(addr, size) find_first_zero_bit(addr, size) + +#endif /* __KERNEL__ */ + +#endif /* _ARM_BITOPS_H */ diff --git a/arch/sandbox/include/asm/byteorder.h b/arch/sandbox/include/asm/byteorder.h new file mode 100644 index 0000000000..ff87284e71 --- /dev/null +++ b/arch/sandbox/include/asm/byteorder.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#ifndef __ASM_SANDBOX_BYTEORDER_H +#define __ASM_SANDBOX_BYTEORDER_H + + +#include <asm/types.h> + +#if !defined(__STRICT_ANSI__) || defined(__KERNEL__) +# define __BYTEORDER_HAS_U64__ +# define __SWAB_64_THRU_32__ +#endif + +#ifdef CONFIG_SANDBOX_BIG_ENDIAN +#include <linux/byteorder/big_endian.h> +#else +#include <linux/byteorder/little_endian.h> +#endif + +#endif diff --git a/arch/sandbox/include/asm/config.h b/arch/sandbox/include/asm/config.h new file mode 100644 index 0000000000..2ef0564e3d --- /dev/null +++ b/arch/sandbox/include/asm/config.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ + +#ifndef _ASM_CONFIG_H_ +#define _ASM_CONFIG_H_ + +#define CONFIG_SANDBOX_ARCH + +#endif diff --git a/arch/sandbox/include/asm/global_data.h b/arch/sandbox/include/asm/global_data.h new file mode 100644 index 0000000000..8d47191f92 --- /dev/null +++ b/arch/sandbox/include/asm/global_data.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * (C) Copyright 2002-2010 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#ifndef __ASM_GBL_DATA_H +#define __ASM_GBL_DATA_H +/* + * The following data structure is placed in some memory wich is + * available very early after boot (like DPRAM on MPC8xx/MPC82xx, or + * some locked parts of the data cache) to allow for a minimum set of + * global variables during system initialization (until we have set + * up the memory controller so that we can use RAM). + * + * Keep it *SMALL* and remember to set GENERATED_GBL_DATA_SIZE > sizeof(gd_t) + */ + +typedef struct global_data { + bd_t *bd; + unsigned long flags; + unsigned long baudrate; + unsigned long have_console; /* serial_init() was called */ + unsigned long env_addr; /* Address of Environment struct */ + unsigned long env_valid; /* Checksum of Environment valid? */ + unsigned long fb_base; /* base address of frame buffer */ + u8 *ram_buf; /* emulated RAM buffer */ + phys_size_t ram_size; /* RAM size */ + void **jt; /* jump table */ + char env_buf[32]; /* buffer for getenv() before reloc. */ +} gd_t; + +/* + * Global Data Flags + */ +#define GD_FLG_RELOC 0x00001 /* Code was relocated to RAM */ +#define GD_FLG_DEVINIT 0x00002 /* Devices have been initialized */ +#define GD_FLG_SILENT 0x00004 /* Silent mode */ +#define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */ +#define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */ +#define GD_FLG_LOGINIT 0x00020 /* Log Buffer has been initialized */ +#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ +#define GD_FLG_ENV_READY 0x00080 /* Env. imported into hash table */ + +#define DECLARE_GLOBAL_DATA_PTR extern gd_t *gd + +#endif /* __ASM_GBL_DATA_H */ diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h new file mode 100644 index 0000000000..0392d218ec --- /dev/null +++ b/arch/sandbox/include/asm/io.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +/* + * Given a physical address and a length, return a virtual address + * that can be used to access the memory range with the caching + * properties specified by "flags". + */ +#define MAP_NOCACHE (0) +#define MAP_WRCOMBINE (0) +#define MAP_WRBACK (0) +#define MAP_WRTHROUGH (0) + +void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags); + +/* + * Take down a mapping set up by map_physmem(). + */ +static inline void unmap_physmem(void *vaddr, unsigned long flags) +{ + +} diff --git a/arch/sandbox/include/asm/posix_types.h b/arch/sandbox/include/asm/posix_types.h new file mode 100644 index 0000000000..ec18ed7e3c --- /dev/null +++ b/arch/sandbox/include/asm/posix_types.h @@ -0,0 +1,57 @@ +/* + * linux/include/asm-arm/posix_types.h + * + * Copyright (C) 1996-1998 Russell King. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Changelog: + * 27-06-1996 RMK Created + */ +#ifndef __ARCH_ARM_POSIX_TYPES_H +#define __ARCH_ARM_POSIX_TYPES_H + +/* + * This file is generally used by user-level software, so you need to + * be a little careful about namespace pollution etc. Also, we cannot + * assume GCC is being used. + */ + +typedef unsigned short __kernel_dev_t; +typedef unsigned long __kernel_ino_t; +typedef unsigned short __kernel_mode_t; +typedef unsigned short __kernel_nlink_t; +typedef long __kernel_off_t; +typedef int __kernel_pid_t; +typedef unsigned short __kernel_ipc_pid_t; +typedef unsigned short __kernel_uid_t; +typedef unsigned short __kernel_gid_t; +#if CONFIG_SANDBOX_BITS_PER_LONG == 32 +typedef unsigned int __kernel_size_t; +typedef int __kernel_ssize_t; +typedef int __kernel_ptrdiff_t; +#else +typedef unsigned long __kernel_size_t; +typedef long __kernel_ssize_t; +typedef long __kernel_ptrdiff_t; +#endif +typedef long __kernel_time_t; +typedef long __kernel_suseconds_t; +typedef long __kernel_clock_t; +typedef int __kernel_daddr_t; +typedef char *__kernel_caddr_t; +typedef unsigned short __kernel_uid16_t; +typedef unsigned short __kernel_gid16_t; +typedef unsigned int __kernel_uid32_t; +typedef unsigned int __kernel_gid32_t; + +typedef unsigned short __kernel_old_uid_t; +typedef unsigned short __kernel_old_gid_t; + +#ifdef __GNUC__ +typedef long long __kernel_loff_t; +#endif + +#endif diff --git a/arch/sandbox/include/asm/ptrace.h b/arch/sandbox/include/asm/ptrace.h new file mode 100644 index 0000000000..613d459ff2 --- /dev/null +++ b/arch/sandbox/include/asm/ptrace.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#ifndef __ASM_SANDBOX_PTRACE_H +#define __ASM_SANDBOX_PTRACE_H + +#ifndef __ASSEMBLY__ +/* This is not used in the sandbox architecture, but required by U-Boot */ +struct pt_regs { +}; + +#ifdef __KERNEL__ +extern void show_regs(struct pt_regs *); + +#endif + +#endif /* __ASSEMBLY__ */ + +#endif diff --git a/arch/sandbox/include/asm/string.h b/arch/sandbox/include/asm/string.h new file mode 100644 index 0000000000..89b7f065ea --- /dev/null +++ b/arch/sandbox/include/asm/string.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <linux/string.h> diff --git a/arch/sandbox/include/asm/system.h b/arch/sandbox/include/asm/system.h new file mode 100644 index 0000000000..78cdc9fa82 --- /dev/null +++ b/arch/sandbox/include/asm/system.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#ifndef __ASM_SANDBOX_SYSTEM_H +#define __ASM_SANDBOX_SYSTEM_H + +/* Define this as nops for sandbox architecture */ +static inline void local_irq_save(unsigned flags __attribute__((unused))) +{ +} + +#define local_irq_enable() +#define local_irq_disable() +#define local_save_flags(x) +#define local_irq_restore(x) + +#endif diff --git a/arch/sandbox/include/asm/types.h b/arch/sandbox/include/asm/types.h new file mode 100644 index 0000000000..2316c2d454 --- /dev/null +++ b/arch/sandbox/include/asm/types.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#ifndef __ASM_SANDBOX_TYPES_H +#define __ASM_SANDBOX_TYPES_H + +typedef unsigned short umode_t; + +/* + * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the + * header files exported to user space + */ + +typedef __signed__ char __s8; +typedef unsigned char __u8; + +typedef __signed__ short __s16; +typedef unsigned short __u16; + +typedef __signed__ int __s32; +typedef unsigned int __u32; + +#if defined(__GNUC__) +__extension__ typedef __signed__ long long __s64; +__extension__ typedef unsigned long long __u64; +#endif + +/* + * These aren't exported outside the kernel to avoid name space clashes + */ +#ifdef __KERNEL__ + +typedef signed char s8; +typedef unsigned char u8; + +typedef signed short s16; +typedef unsigned short u16; + +typedef signed int s32; +typedef unsigned int u32; + +typedef signed long long s64; +typedef unsigned long long u64; + +#define BITS_PER_LONG CONFIG_SANDBOX_BITS_PER_LONG + +typedef unsigned long dma_addr_t; +typedef unsigned long phys_addr_t; +typedef unsigned long phys_size_t; + +#endif /* __KERNEL__ */ + +#endif diff --git a/arch/sandbox/include/asm/u-boot-sandbox.h b/arch/sandbox/include/asm/u-boot-sandbox.h new file mode 100644 index 0000000000..236b4ee287 --- /dev/null +++ b/arch/sandbox/include/asm/u-boot-sandbox.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH <www.elinos.com> + * Marius Groeger <mgroeger@sysgo.de> + * + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH <www.elinos.com> + * Alex Zuepke <azu@sysgo.de> + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#ifndef _U_BOOT_SANDBOX_H_ +#define _U_BOOT_SANDBOX_H_ + +/* board/.../... */ +int board_init(void); +int dram_init(void); + +#endif /* _U_BOOT_SANDBOX_H_ */ diff --git a/arch/sandbox/include/asm/u-boot.h b/arch/sandbox/include/asm/u-boot.h new file mode 100644 index 0000000000..166ef14341 --- /dev/null +++ b/arch/sandbox/include/asm/u-boot.h @@ -0,0 +1,64 @@ +/* + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH <www.elinos.com> + * Marius Groeger <mgroeger@sysgo.de> + * + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH <www.elinos.com> + * Alex Zuepke <azu@sysgo.de> + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ******************************************************************** + * NOTE: This header file defines an interface to U-Boot. Including + * this (unmodified) header file in another file is considered normal + * use of U-Boot, and does *not* fall under the heading of "derived + * work". + ******************************************************************** + */ + +#ifndef _U_BOOT_H_ +#define _U_BOOT_H_ 1 + +typedef struct bd_info { + unsigned long bi_memstart; /* start of DRAM memory */ + phys_size_t bi_memsize; /* size of DRAM memory in bytes */ + unsigned long bi_flashstart; /* start of FLASH memory */ + unsigned long bi_flashsize; /* size of FLASH memory */ + unsigned long bi_flashoffset; /* reserved area for startup monitor */ + unsigned long bi_sramstart; /* start of SRAM memory */ + unsigned long bi_sramsize; /* size of SRAM memory */ + unsigned long bi_bootflags; /* boot / reboot flag (for LynxOS) */ + unsigned long bi_ip_addr; /* IP Address */ + unsigned short bi_ethspeed; /* Ethernet speed in Mbps */ + unsigned long bi_intfreq; /* Internal Freq, in MHz */ + unsigned long bi_busfreq; /* Bus Freq, in MHz */ + unsigned int bi_baudrate; /* Console Baudrate */ + unsigned long bi_boot_params; /* where this board expects params */ + struct /* RAM configuration */ + { + ulong start; + ulong size; + } bi_dram[CONFIG_NR_DRAM_BANKS]; +} bd_t; + +/* For image.h:image_check_target_arch() */ +#define IH_ARCH_DEFAULT IH_ARCH_SANDBOX + +#endif /* _U_BOOT_H_ */ diff --git a/arch/sandbox/include/asm/unaligned.h b/arch/sandbox/include/asm/unaligned.h new file mode 100644 index 0000000000..6cf9780305 --- /dev/null +++ b/arch/sandbox/include/asm/unaligned.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <asm-generic/unaligned.h> diff --git a/arch/sandbox/lib/Makefile b/arch/sandbox/lib/Makefile new file mode 100644 index 0000000000..fbe579b4ce --- /dev/null +++ b/arch/sandbox/lib/Makefile @@ -0,0 +1,51 @@ +# +# Copyright (c) 2011 The Chromium OS Authors. +# +# (C) Copyright 2002-2006 +# Wolfgang Denk, DENX Software Engineering, wd@denx.de. +# +# See file CREDITS for list of people who contributed to this +# project. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program 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. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +include $(TOPDIR)/config.mk + +LIB = $(obj)lib$(ARCH).o + +COBJS-y += board.o +COBJS-y += interrupts.o + +SRCS := $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS-y)) + +# Always build libsandbox.o +TARGETS := $(LIB) + +all: $(TARGETS) + +$(LIB): $(obj).depend $(OBJS) + $(call cmd_link_o_target, $(OBJS)) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/arch/sandbox/lib/board.c b/arch/sandbox/lib/board.c new file mode 100644 index 0000000000..1fd8fa651d --- /dev/null +++ b/arch/sandbox/lib/board.c @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * (C) Copyright 2002-2006 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH <www.elinos.com> + * Marius Groeger <mgroeger@sysgo.de> + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +/* + * This file was taken from ARM and changed to remove things we don't + * need. This is most of it, so have tried to avoid being over-zealous! + * For example, we want to have an emulation of the 'DRAM' used by + * U-Boot. + * + * has been talk upstream of unifying the architectures w.r.t board.c, + * so the less change here the better. + */ + +#include <common.h> +#include <command.h> +#include <malloc.h> +#include <stdio_dev.h> +#include <timestamp.h> +#include <version.h> +#include <serial.h> + +DECLARE_GLOBAL_DATA_PTR; + +/************************************************************************ + * Init Utilities * + ************************************************************************ + * Some of this code should be moved into the core functions, + * or dropped completely, + * but let's get it working (again) first... + */ + +static int display_banner(void) +{ + display_options(); + + return 0; +} + +/** + * Configure and report on the DRAM configuration, which in our case is + * fairly simple. + */ +static int display_dram_config(void) +{ + ulong size = 0; + int i; + + debug("RAM Configuration:\n"); + + for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { +#ifdef DEBUG + printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start); + print_size(gd->bd->bi_dram[i].size, "\n"); +#endif + size += gd->bd->bi_dram[i].size; + } + puts("DRAM: "); + print_size(size, "\n"); + return 0; +} + +/* + * Breathe some life into the board... + * + * Initialize a serial port as console, and carry out some hardware + * tests. + * + * The first part of initialization is running from Flash memory; + * its main purpose is to initialize the RAM so that we + * can relocate the monitor code to RAM. + */ + +/* + * All attempts to come up with a "common" initialization sequence + * that works for all boards and architectures failed: some of the + * requirements are just _too_ different. To get rid of the resulting + * mess of board dependent #ifdef'ed code we now make the whole + * initialization sequence configurable to the user. + * + * The requirements for any new initalization function is simple: it + * receives a pointer to the "global data" structure as it's only + * argument, and returns an integer return code, where 0 means + * "continue" and != 0 means "fatal error, hang the system". + */ +typedef int (init_fnc_t) (void); + +void __dram_init_banksize(void) +{ + gd->bd->bi_dram[0].start = 0; + gd->bd->bi_dram[0].size = gd->ram_size; +} + +void dram_init_banksize(void) + __attribute__((weak, alias("__dram_init_banksize"))); + +init_fnc_t *init_sequence[] = { +#if defined(CONFIG_ARCH_CPU_INIT) + arch_cpu_init, /* basic arch cpu dependent setup */ +#endif +#if defined(CONFIG_BOARD_EARLY_INIT_F) + board_early_init_f, +#endif + timer_init, /* initialize timer */ + env_init, /* initialize environment */ + serial_init, /* serial communications setup */ + console_init_f, /* stage 1 init of console */ + display_banner, /* say that we are here */ +#if defined(CONFIG_DISPLAY_CPUINFO) + print_cpuinfo, /* display cpu info (and speed) */ +#endif +#if defined(CONFIG_DISPLAY_BOARDINFO) + checkboard, /* display board info */ +#endif + dram_init, /* configure available RAM banks */ + NULL, +}; + +void board_init_f(ulong bootflag) +{ + init_fnc_t **init_fnc_ptr; + uchar *mem; + unsigned long addr_sp, addr, size; + + gd = malloc(sizeof(gd_t)); + assert(gd); + + memset((void *)gd, 0, sizeof(gd_t)); + + for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { + if ((*init_fnc_ptr)() != 0) + hang(); + } + + size = CONFIG_SYS_SDRAM_SIZE; + mem = malloc(size); + assert(mem); + gd->ram_buf = mem; + addr = (ulong)(mem + size); + + /* + * reserve memory for malloc() arena + */ + addr_sp = addr - TOTAL_MALLOC_LEN; + debug("Reserving %dk for malloc() at: %08lx\n", + TOTAL_MALLOC_LEN >> 10, addr_sp); + /* + * (permanently) allocate a Board Info struct + * and a permanent copy of the "global" data + */ + addr_sp -= sizeof(bd_t); + gd->bd = (bd_t *) addr_sp; + debug("Reserving %zu Bytes for Board Info at: %08lx\n", + sizeof(bd_t), addr_sp); + + /* Ram ist board specific, so move it to board code ... */ + dram_init_banksize(); + display_dram_config(); /* and display it */ + + /* We don't relocate, so just run the post-relocation code */ + board_init_r(NULL, 0); + + /* NOTREACHED - no way out of command loop except booting */ +} + +/************************************************************************ + * + * This is the next part if the initialization sequence: we are now + * running from RAM and have a "normal" C environment, i. e. global + * data can be written, BSS has been cleared, the stack size in not + * that critical any more, etc. + * + ************************************************************************ + */ + +void board_init_r(gd_t *id, ulong dest_addr) +{ + + if (id) + gd = id; + + gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ + +#ifdef CONFIG_SERIAL_MULTI + serial_initialize(); +#endif + +#ifdef CONFIG_POST + post_output_backlog(); +#endif + +#if 0 /* Sandbox uses system malloc for now */ + /* The Malloc area is immediately below the monitor copy in DRAM */ + malloc_start = dest_addr - TOTAL_MALLOC_LEN; + mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN); +#endif + + /* initialize environment */ + env_relocate(); + + /* IP Address */ + gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr"); + + stdio_init(); /* get the devices list going. */ + + jumptable_init(); + + console_init_r(); /* fully init console as a device */ + +#if defined(CONFIG_DISPLAY_BOARDINFO_LATE) + checkboard(); +#endif + +#if defined(CONFIG_ARCH_MISC_INIT) + /* miscellaneous arch dependent initialisations */ + arch_misc_init(); +#endif +#if defined(CONFIG_MISC_INIT_R) + /* miscellaneous platform dependent initialisations */ + misc_init_r(); +#endif + + /* set up exceptions */ + interrupt_init(); + /* enable exceptions */ + enable_interrupts(); + +#ifdef BOARD_LATE_INIT + board_late_init(); +#endif + +#ifdef CONFIG_POST + post_run(NULL, POST_RAM | post_bootmode_get(0)); +#endif + + /* + * For now, run the main loop. Later we might let this be done + * in the main program. + */ + while (1) + main_loop(); + + /* NOTREACHED - no way out of command loop except booting */ +} + +void hang(void) +{ + puts("### ERROR ### Please RESET the board ###\n"); + for (;;) + ; +} diff --git a/arch/sandbox/lib/interrupts.c b/arch/sandbox/lib/interrupts.c new file mode 100644 index 0000000000..d350108a2d --- /dev/null +++ b/arch/sandbox/lib/interrupts.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <common.h> + +int interrupt_init(void) +{ + return 0; +} + +void enable_interrupts(void) +{ + return; +} +int disable_interrupts(void) +{ + return 0; +} diff --git a/board/hymod/env.c b/board/hymod/env.c index c0e2cd5d68..fde428d979 100644 --- a/board/hymod/env.c +++ b/board/hymod/env.c @@ -22,6 +22,7 @@ */ #include <common.h> +#include <linux/ctype.h> DECLARE_GLOBAL_DATA_PTR; @@ -45,7 +46,7 @@ env_callback (uchar *name, uchar *value) nn++; } - while (*nn == ' ' || *nn == '\t') + while (isblank(*nn)) nn++; if ((nnl = strlen (nn)) == 0) { @@ -61,7 +62,7 @@ env_callback (uchar *name, uchar *value) nn[--nnl] = '\0'; } - while (nnl > 0 && ((c = nn[nnl - 1]) == ' ' || c == '\t')) + while (nnl > 0 && isblank(nn[nnl - 1])) nn[--nnl] = '\0'; if (nnl == 0) { printf ("Empty name in global env file\n"); @@ -71,11 +72,11 @@ env_callback (uchar *name, uchar *value) p = (char *)value; q = nv; - while ((c = *p) == ' ' || c == '\t') + while (isblank(*p)) p++; nvl = strlen (p); - while (nvl > 0 && ((c = p[nvl - 1]) == ' ' || c == '\t')) + while (nvl > 0 && isblank(p[nvl - 1])) p[--nvl] = '\0'; while ((*q = *p++) != '\0') { diff --git a/board/sandbox/sandbox/Makefile b/board/sandbox/sandbox/Makefile new file mode 100644 index 0000000000..6366a07445 --- /dev/null +++ b/board/sandbox/sandbox/Makefile @@ -0,0 +1,42 @@ +# +# Copyright (c) 2011 The Chromium OS Authors. +# +# See file CREDITS for list of people who contributed to this +# project. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundatio; either version 2 of +# the License, or (at your option) any later version. +# +# This program 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. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +include $(TOPDIR)/config.mk + +LIB = $(obj)lib$(BOARD).o + +COBJS := $(BOARD).o + +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS)) + +$(LIB): $(obj).depend $(OBJS) + $(AR) $(ARFLAGS) $@ $(OBJS) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/board/sandbox/sandbox/sandbox.c b/board/sandbox/sandbox/sandbox.c new file mode 100644 index 0000000000..95a5045975 --- /dev/null +++ b/board/sandbox/sandbox/sandbox.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <common.h> + +/* + * Pointer to initial global data area + * + * Here we initialize it. + */ +gd_t *gd; + +void flush_cache(unsigned long start, unsigned long size) +{ +} + +ulong get_timer(ulong base) +{ + return 0; +} + +int timer_init(void) +{ + return 0; +} + +int dram_init(void) +{ + gd->ram_size = CONFIG_DRAM_SIZE; + return 0; +} diff --git a/boards.cfg b/boards.cfg index bd70a66f5a..1e3bfdc056 100644 --- a/boards.cfg +++ b/boards.cfg @@ -264,6 +264,7 @@ tcm-bf518 blackfin blackfin tcm-bf537 blackfin blackfin eNET x86 x86 eNET - sc520 eNET:SYS_TEXT_BASE=0x38040000 eNET_SRAM x86 x86 eNET - sc520 eNET:SYS_TEXT_BASE=0x19000000 +sandbox sandbox sandbox sandbox sandbox - idmr m68k mcf52x2 TASREG m68k mcf52x2 tasreg esd M5208EVBE m68k mcf52x2 m5208evbe freescale diff --git a/common/Makefile b/common/Makefile index fdc4206853..ae795e0d55 100644 --- a/common/Makefile +++ b/common/Makefile @@ -29,7 +29,9 @@ LIB = $(obj)libcommon.o ifndef CONFIG_SPL_BUILD COBJS-y += main.o COBJS-y += command.o +ifndef CONFIG_SANDBOX COBJS-y += dlmalloc.o +endif COBJS-y += exports.o COBJS-$(CONFIG_SYS_HUSH_PARSER) += hush.o COBJS-y += image.o @@ -136,6 +138,7 @@ COBJS-$(CONFIG_CMD_PCI) += cmd_pci.o endif COBJS-y += cmd_pcmcia.o COBJS-$(CONFIG_CMD_PORTIO) += cmd_portio.o +COBJS-$(CONFIG_CMD_PXE) += cmd_pxe.o COBJS-$(CONFIG_CMD_REGINFO) += cmd_reginfo.o COBJS-$(CONFIG_CMD_REISER) += cmd_reiser.o COBJS-$(CONFIG_CMD_SATA) += cmd_sata.o @@ -177,6 +180,7 @@ COBJS-$(CONFIG_CMD_KGDB) += kgdb.o kgdb_stubs.o COBJS-$(CONFIG_KALLSYMS) += kallsyms.o COBJS-$(CONFIG_LCD) += lcd.o COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o +COBJS-$(CONFIG_MENU) += menu.o COBJS-$(CONFIG_MODEM_SUPPORT) += modem.o COBJS-$(CONFIG_UPDATE_TFTP) += update.o COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c index 605112083e..9c1d7d01f8 100644 --- a/common/cmd_bdinfo.c +++ b/common/cmd_bdinfo.c @@ -31,11 +31,14 @@ DECLARE_GLOBAL_DATA_PTR; static void print_num(const char *, ulong); -#if !(defined(CONFIG_ARM) || defined(CONFIG_M68K)) || defined(CONFIG_CMD_NET) +#if !(defined(CONFIG_ARM) || defined(CONFIG_M68K) || defined(CONFIG_SANDBOX)) \ + || defined(CONFIG_CMD_NET) +#define HAVE_PRINT_ETH static void print_eth(int idx); #endif -#if (!defined(CONFIG_ARM) && !defined(CONFIG_X86)) +#if (!defined(CONFIG_ARM) && !defined(CONFIG_X86) && !defined(CONFIG_SANDBOX)) +#define HAVE_PRINT_LNUM static void print_lnum(const char *, u64); #endif @@ -413,6 +416,29 @@ int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 0; } +#elif defined(CONFIG_SANDBOX) + +int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + int i; + bd_t *bd = gd->bd; + + print_num("boot_params", (ulong)bd->bi_boot_params); + + for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { + print_num("DRAM bank", i); + print_num("-> start", bd->bi_dram[i].start); + print_num("-> size", bd->bi_dram[i].size); + } + +#if defined(CONFIG_CMD_NET) + print_eth(0); + printf("ip_addr = %pI4\n", &bd->bi_ip_addr); +#endif + print_num("FB base ", gd->fb_base); + return 0; +} + #else #error "a case for this architecture does not exist!" #endif @@ -422,7 +448,7 @@ static void print_num(const char *name, ulong value) printf("%-12s= 0x%08lX\n", name, value); } -#if !(defined(CONFIG_ARM) || defined(CONFIG_M68K)) || defined(CONFIG_CMD_NET) +#ifdef HAVE_PRINT_ETH static void print_eth(int idx) { char name[10], *val; @@ -437,7 +463,7 @@ static void print_eth(int idx) } #endif -#if (!defined(CONFIG_ARM) && !defined(CONFIG_X86)) +#ifdef HAVE_PRINT_LNUM static void print_lnum(const char *name, u64 value) { printf("%-12s= 0x%.8llX\n", name, value); diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index c2e8038ee8..ece1b9a1e2 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -438,9 +438,8 @@ static int bootm_start_standalone(ulong iflag, int argc, char * const argv[]) setenv("filesize", buf); return 0; } - appl = (int (*)(int, char * const []))ntohl(images.ep); + appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep); (*appl)(argc-1, &argv[1]); - return 0; } @@ -464,14 +463,14 @@ static cmd_tbl_t cmd_bootm_sub[] = { int do_bootm_subcommand (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int ret = 0; - int state; + long state; cmd_tbl_t *c; boot_os_fn *boot_fn; c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub)); if (c) { - state = (int)c->cmd; + state = (long)c->cmd; /* treat start special since it resets the state machine */ if (state == BOOTM_STATE_START) { @@ -1201,34 +1200,35 @@ U_BOOT_CMD( /* helper routines */ /*******************************************************************/ #ifdef CONFIG_SILENT_CONSOLE -static void fixup_silent_linux () +static void fixup_silent_linux(void) { char buf[256], *start, *end; - char *cmdline = getenv ("bootargs"); + char *cmdline = getenv("bootargs"); /* Only fix cmdline when requested */ if (!(gd->flags & GD_FLG_SILENT)) return; - debug ("before silent fix-up: %s\n", cmdline); + debug("before silent fix-up: %s\n", cmdline); if (cmdline) { - if ((start = strstr (cmdline, "console=")) != NULL) { - end = strchr (start, ' '); - strncpy (buf, cmdline, (start - cmdline + 8)); + start = strstr(cmdline, "console="); + if (start) { + end = strchr(start, ' '); + strncpy(buf, cmdline, (start - cmdline + 8)); if (end) - strcpy (buf + (start - cmdline + 8), end); + strcpy(buf + (start - cmdline + 8), end); else buf[start - cmdline + 8] = '\0'; } else { - strcpy (buf, cmdline); - strcat (buf, " console="); + strcpy(buf, cmdline); + strcat(buf, " console="); } } else { - strcpy (buf, "console="); + strcpy(buf, "console="); } - setenv ("bootargs", buf); - debug ("after silent fix-up: %s\n", buf); + setenv("bootargs", buf); + debug("after silent fix-up: %s\n", buf); } #endif /* CONFIG_SILENT_CONSOLE */ diff --git a/common/cmd_mem.c b/common/cmd_mem.c index e84cc4e22d..28476d750b 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -937,7 +937,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (readback != val) { printf ("\nMem error @ 0x%08X: " "found %08lX, expected %08lX\n", - (uint)addr, readback, val); + (uint)(uintptr_t)addr, readback, val); errs++; if (ctrlc()) { putc ('\n'); diff --git a/common/cmd_pxe.c b/common/cmd_pxe.c new file mode 100644 index 0000000000..3efd7008e9 --- /dev/null +++ b/common/cmd_pxe.c @@ -0,0 +1,1355 @@ +/* + * Copyright 2010-2011 Calxeda, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include <common.h> +#include <command.h> +#include <malloc.h> +#include <linux/string.h> +#include <linux/ctype.h> +#include <errno.h> +#include <linux/list.h> + +#include "menu.h" + +#define MAX_TFTP_PATH_LEN 127 + + +/* + * Like getenv, but prints an error if envvar isn't defined in the + * environment. It always returns what getenv does, so it can be used in + * place of getenv without changing error handling otherwise. + */ +static char *from_env(char *envvar) +{ + char *ret; + + ret = getenv(envvar); + + if (!ret) + printf("missing environment variable: %s\n", envvar); + + return ret; +} + +/* + * Convert an ethaddr from the environment to the format used by pxelinux + * filenames based on mac addresses. Convert's ':' to '-', and adds "01-" to + * the beginning of the ethernet address to indicate a hardware type of + * Ethernet. Also converts uppercase hex characters into lowercase, to match + * pxelinux's behavior. + * + * Returns 1 for success, -ENOENT if 'ethaddr' is undefined in the + * environment, or some other value < 0 on error. + */ +static int format_mac_pxe(char *outbuf, size_t outbuf_len) +{ + size_t ethaddr_len; + char *p, *ethaddr; + + ethaddr = from_env("ethaddr"); + + if (!ethaddr) + return -ENOENT; + + ethaddr_len = strlen(ethaddr); + + /* + * ethaddr_len + 4 gives room for "01-", ethaddr, and a NUL byte at + * the end. + */ + if (outbuf_len < ethaddr_len + 4) { + printf("outbuf is too small (%d < %d)\n", + outbuf_len, ethaddr_len + 4); + + return -EINVAL; + } + + strcpy(outbuf, "01-"); + + for (p = outbuf + 3; *ethaddr; ethaddr++, p++) { + if (*ethaddr == ':') + *p = '-'; + else + *p = tolower(*ethaddr); + } + + *p = '\0'; + + return 1; +} + +/* + * Returns the directory the file specified in the bootfile env variable is + * in. If bootfile isn't defined in the environment, return NULL, which should + * be interpreted as "don't prepend anything to paths". + */ +static int get_bootfile_path(char *bootfile_path, size_t bootfile_path_size) +{ + char *bootfile, *last_slash; + size_t path_len; + + bootfile = from_env("bootfile"); + + if (!bootfile) { + bootfile_path[0] = '\0'; + return 1; + } + + last_slash = strrchr(bootfile, '/'); + + if (last_slash == NULL) { + bootfile_path[0] = '\0'; + return 1; + } + + path_len = (last_slash - bootfile) + 1; + + if (bootfile_path_size < path_len) { + printf("bootfile_path too small. (%d < %d)\n", + bootfile_path_size, path_len); + + return -1; + } + + strncpy(bootfile_path, bootfile, path_len); + + bootfile_path[path_len] = '\0'; + + return 1; +} + +/* + * As in pxelinux, paths to files referenced from files we retrieve are + * relative to the location of bootfile. get_relfile takes such a path and + * joins it with the bootfile path to get the full path to the target file. If + * the bootfile path is NULL, we use file_path as is. + * + * Returns 1 for success, or < 0 on error. + */ +static int get_relfile(char *file_path, void *file_addr) +{ + size_t path_len; + char relfile[MAX_TFTP_PATH_LEN+1]; + char addr_buf[10]; + char *tftp_argv[] = {"tftp", NULL, NULL, NULL}; + int err; + + err = get_bootfile_path(relfile, sizeof(relfile)); + + if (err < 0) + return err; + + path_len = strlen(file_path); + path_len += strlen(relfile); + + if (path_len > MAX_TFTP_PATH_LEN) { + printf("Base path too long (%s%s)\n", + relfile, + file_path); + + return -ENAMETOOLONG; + } + + strcat(relfile, file_path); + + printf("Retrieving file: %s\n", relfile); + + sprintf(addr_buf, "%p", file_addr); + + tftp_argv[1] = addr_buf; + tftp_argv[2] = relfile; + + if (do_tftpb(NULL, 0, 3, tftp_argv)) + return -ENOENT; + + return 1; +} + +/* + * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If + * 'bootfile' was specified in the environment, the path to bootfile will be + * prepended to 'file_path' and the resulting path will be used. + * + * Returns 1 on success, or < 0 for error. + */ +static int get_pxe_file(char *file_path, void *file_addr) +{ + unsigned long config_file_size; + char *tftp_filesize; + int err; + + err = get_relfile(file_path, file_addr); + + if (err < 0) + return err; + + /* + * the file comes without a NUL byte at the end, so find out its size + * and add the NUL byte. + */ + tftp_filesize = from_env("filesize"); + + if (!tftp_filesize) + return -ENOENT; + + if (strict_strtoul(tftp_filesize, 16, &config_file_size) < 0) + return -EINVAL; + + *(char *)(file_addr + config_file_size) = '\0'; + + return 1; +} + +#define PXELINUX_DIR "pxelinux.cfg/" + +/* + * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file + * to do the hard work, the location of the 'pxelinux.cfg' folder is generated + * from the bootfile path, as described above. + * + * Returns 1 on success or < 0 on error. + */ +static int get_pxelinux_path(char *file, void *pxefile_addr_r) +{ + size_t base_len = strlen(PXELINUX_DIR); + char path[MAX_TFTP_PATH_LEN+1]; + + if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) { + printf("path (%s%s) too long, skipping\n", + PXELINUX_DIR, file); + return -ENAMETOOLONG; + } + + sprintf(path, PXELINUX_DIR "%s", file); + + return get_pxe_file(path, pxefile_addr_r); +} + +/* + * Looks for a pxe file with a name based on the pxeuuid environment variable. + * + * Returns 1 on success or < 0 on error. + */ +static int pxe_uuid_path(void *pxefile_addr_r) +{ + char *uuid_str; + + uuid_str = from_env("pxeuuid"); + + if (!uuid_str) + return -ENOENT; + + return get_pxelinux_path(uuid_str, pxefile_addr_r); +} + +/* + * Looks for a pxe file with a name based on the 'ethaddr' environment + * variable. + * + * Returns 1 on success or < 0 on error. + */ +static int pxe_mac_path(void *pxefile_addr_r) +{ + char mac_str[21]; + int err; + + err = format_mac_pxe(mac_str, sizeof(mac_str)); + + if (err < 0) + return err; + + return get_pxelinux_path(mac_str, pxefile_addr_r); +} + +/* + * Looks for pxe files with names based on our IP address. See pxelinux + * documentation for details on what these file names look like. We match + * that exactly. + * + * Returns 1 on success or < 0 on error. + */ +static int pxe_ipaddr_paths(void *pxefile_addr_r) +{ + char ip_addr[9]; + int mask_pos, err; + + sprintf(ip_addr, "%08X", ntohl(NetOurIP)); + + for (mask_pos = 7; mask_pos >= 0; mask_pos--) { + err = get_pxelinux_path(ip_addr, pxefile_addr_r); + + if (err > 0) + return err; + + ip_addr[mask_pos] = '\0'; + } + + return -ENOENT; +} + +/* + * Entry point for the 'pxe get' command. + * This Follows pxelinux's rules to download a config file from a tftp server. + * The file is stored at the location given by the pxefile_addr_r environment + * variable, which must be set. + * + * UUID comes from pxeuuid env variable, if defined + * MAC addr comes from ethaddr env variable, if defined + * IP + * + * see http://syslinux.zytor.com/wiki/index.php/PXELINUX + * + * Returns 0 on success or 1 on error. + */ +static int +do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + char *pxefile_addr_str; + void *pxefile_addr_r; + int err; + + if (argc != 1) + return cmd_usage(cmdtp); + + + pxefile_addr_str = from_env("pxefile_addr_r"); + + if (!pxefile_addr_str) + return 1; + + err = strict_strtoul(pxefile_addr_str, 16, + (unsigned long *)&pxefile_addr_r); + if (err < 0) + return 1; + + /* + * Keep trying paths until we successfully get a file we're looking + * for. + */ + if (pxe_uuid_path(pxefile_addr_r) > 0 + || pxe_mac_path(pxefile_addr_r) > 0 + || pxe_ipaddr_paths(pxefile_addr_r) > 0 + || get_pxelinux_path("default", pxefile_addr_r) > 0) { + + printf("Config file found\n"); + + return 0; + } + + printf("Config file not found\n"); + + return 1; +} + +/* + * Wrapper to make it easier to store the file at file_path in the location + * specified by envaddr_name. file_path will be joined to the bootfile path, + * if any is specified. + * + * Returns 1 on success or < 0 on error. + */ +static int get_relfile_envaddr(char *file_path, char *envaddr_name) +{ + void *file_addr; + char *envaddr; + + envaddr = from_env(envaddr_name); + + if (!envaddr) + return -ENOENT; + + if (strict_strtoul(envaddr, 16, (unsigned long *)&file_addr) < 0) + return -EINVAL; + + return get_relfile(file_path, file_addr); +} + +/* + * A note on the pxe file parser. + * + * We're parsing files that use syslinux grammar, which has a few quirks. + * String literals must be recognized based on context - there is no + * quoting or escaping support. There's also nothing to explicitly indicate + * when a label section completes. We deal with that by ending a label + * section whenever we see a line that doesn't include. + * + * As with the syslinux family, this same file format could be reused in the + * future for non pxe purposes. The only action it takes during parsing that + * would throw this off is handling of include files. It assumes we're using + * pxe, and does a tftp download of a file listed as an include file in the + * middle of the parsing operation. That could be handled by refactoring it to + * take a 'include file getter' function. + */ + +/* + * Describes a single label given in a pxe file. + * + * Create these with the 'label_create' function given below. + * + * name - the name of the menu as given on the 'menu label' line. + * kernel - the path to the kernel file to use for this label. + * append - kernel command line to use when booting this label + * initrd - path to the initrd to use for this label. + * attempted - 0 if we haven't tried to boot this label, 1 if we have. + * localboot - 1 if this label specified 'localboot', 0 otherwise. + * list - lets these form a list, which a pxe_menu struct will hold. + */ +struct pxe_label { + char *name; + char *kernel; + char *append; + char *initrd; + int attempted; + int localboot; + struct list_head list; +}; + +/* + * Describes a pxe menu as given via pxe files. + * + * title - the name of the menu as given by a 'menu title' line. + * default_label - the name of the default label, if any. + * timeout - time in tenths of a second to wait for a user key-press before + * booting the default label. + * prompt - if 0, don't prompt for a choice unless the timeout period is + * interrupted. If 1, always prompt for a choice regardless of + * timeout. + * labels - a list of labels defined for the menu. + */ +struct pxe_menu { + char *title; + char *default_label; + int timeout; + int prompt; + struct list_head labels; +}; + +/* + * Allocates memory for and initializes a pxe_label. This uses malloc, so the + * result must be free()'d to reclaim the memory. + * + * Returns NULL if malloc fails. + */ +static struct pxe_label *label_create(void) +{ + struct pxe_label *label; + + label = malloc(sizeof(struct pxe_label)); + + if (!label) + return NULL; + + memset(label, 0, sizeof(struct pxe_label)); + + return label; +} + +/* + * Free the memory used by a pxe_label, including that used by its name, + * kernel, append and initrd members, if they're non NULL. + * + * So - be sure to only use dynamically allocated memory for the members of + * the pxe_label struct, unless you want to clean it up first. These are + * currently only created by the pxe file parsing code. + */ +static void label_destroy(struct pxe_label *label) +{ + if (label->name) + free(label->name); + + if (label->kernel) + free(label->kernel); + + if (label->append) + free(label->append); + + if (label->initrd) + free(label->initrd); + + free(label); +} + +/* + * Print a label and its string members if they're defined. + * + * This is passed as a callback to the menu code for displaying each + * menu entry. + */ +static void label_print(void *data) +{ + struct pxe_label *label = data; + + printf("Label: %s\n", label->name); + + if (label->kernel) + printf("\tkernel: %s\n", label->kernel); + + if (label->append) + printf("\tappend: %s\n", label->append); + + if (label->initrd) + printf("\tinitrd: %s\n", label->initrd); +} + +/* + * Boot a label that specified 'localboot'. This requires that the 'localcmd' + * environment variable is defined. Its contents will be executed as U-boot + * command. If the label specified an 'append' line, its contents will be + * used to overwrite the contents of the 'bootargs' environment variable prior + * to running 'localcmd'. + * + * Returns 1 on success or < 0 on error. + */ +static int label_localboot(struct pxe_label *label) +{ + char *localcmd, *dupcmd; + int ret; + + localcmd = from_env("localcmd"); + + if (!localcmd) + return -ENOENT; + + /* + * dup the command to avoid any issues with the version of it existing + * in the environment changing during the execution of the command. + */ + dupcmd = strdup(localcmd); + + if (!dupcmd) + return -ENOMEM; + + if (label->append) + setenv("bootargs", label->append); + + printf("running: %s\n", dupcmd); + + ret = run_command2(dupcmd, 0); + + free(dupcmd); + + return ret; +} + +/* + * Boot according to the contents of a pxe_label. + * + * If we can't boot for any reason, we return. A successful boot never + * returns. + * + * The kernel will be stored in the location given by the 'kernel_addr_r' + * environment variable. + * + * If the label specifies an initrd file, it will be stored in the location + * given by the 'ramdisk_addr_r' environment variable. + * + * If the label specifies an 'append' line, its contents will overwrite that + * of the 'bootargs' environment variable. + */ +static void label_boot(struct pxe_label *label) +{ + char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL }; + int bootm_argc = 3; + + label_print(label); + + label->attempted = 1; + + if (label->localboot) { + label_localboot(label); + return; + } + + if (label->kernel == NULL) { + printf("No kernel given, skipping %s\n", + label->name); + return; + } + + if (label->initrd) { + if (get_relfile_envaddr(label->initrd, "ramdisk_addr_r") < 0) { + printf("Skipping %s for failure retrieving initrd\n", + label->name); + return; + } + + bootm_argv[2] = getenv("ramdisk_addr_r"); + } else { + bootm_argv[2] = "-"; + } + + if (get_relfile_envaddr(label->kernel, "kernel_addr_r") < 0) { + printf("Skipping %s for failure retrieving kernel\n", + label->name); + return; + } + + if (label->append) + setenv("bootargs", label->append); + + bootm_argv[1] = getenv("kernel_addr_r"); + + /* + * fdt usage is optional. If there is an fdt_addr specified, we will + * pass it along to bootm, and adjust argc appropriately. + */ + bootm_argv[3] = getenv("fdt_addr"); + + if (bootm_argv[3]) + bootm_argc = 4; + + do_bootm(NULL, 0, bootm_argc, bootm_argv); +} + +/* + * Tokens for the pxe file parser. + */ +enum token_type { + T_EOL, + T_STRING, + T_EOF, + T_MENU, + T_TITLE, + T_TIMEOUT, + T_LABEL, + T_KERNEL, + T_APPEND, + T_INITRD, + T_LOCALBOOT, + T_DEFAULT, + T_PROMPT, + T_INCLUDE, + T_INVALID +}; + +/* + * A token - given by a value and a type. + */ +struct token { + char *val; + enum token_type type; +}; + +/* + * Keywords recognized. + */ +static const struct token keywords[] = { + {"menu", T_MENU}, + {"title", T_TITLE}, + {"timeout", T_TIMEOUT}, + {"default", T_DEFAULT}, + {"prompt", T_PROMPT}, + {"label", T_LABEL}, + {"kernel", T_KERNEL}, + {"localboot", T_LOCALBOOT}, + {"append", T_APPEND}, + {"initrd", T_INITRD}, + {"include", T_INCLUDE}, + {NULL, T_INVALID} +}; + +/* + * Since pxe(linux) files don't have a token to identify the start of a + * literal, we have to keep track of when we're in a state where a literal is + * expected vs when we're in a state a keyword is expected. + */ +enum lex_state { + L_NORMAL = 0, + L_KEYWORD, + L_SLITERAL +}; + +/* + * get_string retrieves a string from *p and stores it as a token in + * *t. + * + * get_string used for scanning both string literals and keywords. + * + * Characters from *p are copied into t-val until a character equal to + * delim is found, or a NUL byte is reached. If delim has the special value of + * ' ', any whitespace character will be used as a delimiter. + * + * If lower is unequal to 0, uppercase characters will be converted to + * lowercase in the result. This is useful to make keywords case + * insensitive. + * + * The location of *p is updated to point to the first character after the end + * of the token - the ending delimiter. + * + * On success, the new value of t->val is returned. Memory for t->val is + * allocated using malloc and must be free()'d to reclaim it. If insufficient + * memory is available, NULL is returned. + */ +static char *get_string(char **p, struct token *t, char delim, int lower) +{ + char *b, *e; + size_t len, i; + + /* + * b and e both start at the beginning of the input stream. + * + * e is incremented until we find the ending delimiter, or a NUL byte + * is reached. Then, we take e - b to find the length of the token. + */ + b = e = *p; + + while (*e) { + if ((delim == ' ' && isspace(*e)) || delim == *e) + break; + e++; + } + + len = e - b; + + /* + * Allocate memory to hold the string, and copy it in, converting + * characters to lowercase if lower is != 0. + */ + t->val = malloc(len + 1); + if (!t->val) + return NULL; + + for (i = 0; i < len; i++, b++) { + if (lower) + t->val[i] = tolower(*b); + else + t->val[i] = *b; + } + + t->val[len] = '\0'; + + /* + * Update *p so the caller knows where to continue scanning. + */ + *p = e; + + t->type = T_STRING; + + return t->val; +} + +/* + * Populate a keyword token with a type and value. + */ +static void get_keyword(struct token *t) +{ + int i; + + for (i = 0; keywords[i].val; i++) { + if (!strcmp(t->val, keywords[i].val)) { + t->type = keywords[i].type; + break; + } + } +} + +/* + * Get the next token. We have to keep track of which state we're in to know + * if we're looking to get a string literal or a keyword. + * + * *p is updated to point at the first character after the current token. + */ +static void get_token(char **p, struct token *t, enum lex_state state) +{ + char *c = *p; + + t->type = T_INVALID; + + /* eat non EOL whitespace */ + while (isblank(*c)) + c++; + + /* + * eat comments. note that string literals can't begin with #, but + * can contain a # after their first character. + */ + if (*c == '#') { + while (*c && *c != '\n') + c++; + } + + if (*c == '\n') { + t->type = T_EOL; + c++; + } else if (*c == '\0') { + t->type = T_EOF; + c++; + } else if (state == L_SLITERAL) { + get_string(&c, t, '\n', 0); + } else if (state == L_KEYWORD) { + /* + * when we expect a keyword, we first get the next string + * token delimited by whitespace, and then check if it + * matches a keyword in our keyword list. if it does, it's + * converted to a keyword token of the appropriate type, and + * if not, it remains a string token. + */ + get_string(&c, t, ' ', 1); + get_keyword(t); + } + + *p = c; +} + +/* + * Increment *c until we get to the end of the current line, or EOF. + */ +static void eol_or_eof(char **c) +{ + while (**c && **c != '\n') + (*c)++; +} + +/* + * All of these parse_* functions share some common behavior. + * + * They finish with *c pointing after the token they parse, and return 1 on + * success, or < 0 on error. + */ + +/* + * Parse a string literal and store a pointer it at *dst. String literals + * terminate at the end of the line. + */ +static int parse_sliteral(char **c, char **dst) +{ + struct token t; + char *s = *c; + + get_token(c, &t, L_SLITERAL); + + if (t.type != T_STRING) { + printf("Expected string literal: %.*s\n", (int)(*c - s), s); + return -EINVAL; + } + + *dst = t.val; + + return 1; +} + +/* + * Parse a base 10 (unsigned) integer and store it at *dst. + */ +static int parse_integer(char **c, int *dst) +{ + struct token t; + char *s = *c; + unsigned long temp; + + get_token(c, &t, L_SLITERAL); + + if (t.type != T_STRING) { + printf("Expected string: %.*s\n", (int)(*c - s), s); + return -EINVAL; + } + + if (strict_strtoul(t.val, 10, &temp) < 0) { + printf("Expected unsigned integer: %s\n", t.val); + return -EINVAL; + } + + *dst = (int)temp; + + free(t.val); + + return 1; +} + +static int parse_pxefile_top(char *p, struct pxe_menu *cfg, int nest_level); + +/* + * Parse an include statement, and retrieve and parse the file it mentions. + * + * base should point to a location where it's safe to store the file, and + * nest_level should indicate how many nested includes have occurred. For this + * include, nest_level has already been incremented and doesn't need to be + * incremented here. + */ +static int handle_include(char **c, char *base, + struct pxe_menu *cfg, int nest_level) +{ + char *include_path; + char *s = *c; + int err; + + err = parse_sliteral(c, &include_path); + + if (err < 0) { + printf("Expected include path: %.*s\n", + (int)(*c - s), s); + return err; + } + + err = get_pxe_file(include_path, base); + + if (err < 0) { + printf("Couldn't retrieve %s\n", include_path); + return err; + } + + return parse_pxefile_top(base, cfg, nest_level); +} + +/* + * Parse lines that begin with 'menu'. + * + * b and nest are provided to handle the 'menu include' case. + * + * b should be the address where the file currently being parsed is stored. + * + * nest_level should be 1 when parsing the top level pxe file, 2 when parsing + * a file it includes, 3 when parsing a file included by that file, and so on. + */ +static int parse_menu(char **c, struct pxe_menu *cfg, char *b, int nest_level) +{ + struct token t; + char *s = *c; + int err; + + get_token(c, &t, L_KEYWORD); + + switch (t.type) { + case T_TITLE: + err = parse_sliteral(c, &cfg->title); + + break; + + case T_INCLUDE: + err = handle_include(c, b + strlen(b) + 1, cfg, + nest_level + 1); + break; + + default: + printf("Ignoring malformed menu command: %.*s\n", + (int)(*c - s), s); + } + + if (err < 0) + return err; + + eol_or_eof(c); + + return 1; +} + +/* + * Handles parsing a 'menu line' when we're parsing a label. + */ +static int parse_label_menu(char **c, struct pxe_menu *cfg, + struct pxe_label *label) +{ + struct token t; + char *s; + + s = *c; + + get_token(c, &t, L_KEYWORD); + + switch (t.type) { + case T_DEFAULT: + if (cfg->default_label) + free(cfg->default_label); + + cfg->default_label = strdup(label->name); + + if (!cfg->default_label) + return -ENOMEM; + + break; + default: + printf("Ignoring malformed menu command: %.*s\n", + (int)(*c - s), s); + } + + eol_or_eof(c); + + return 0; +} + +/* + * Parses a label and adds it to the list of labels for a menu. + * + * A label ends when we either get to the end of a file, or + * get some input we otherwise don't have a handler defined + * for. + * + */ +static int parse_label(char **c, struct pxe_menu *cfg) +{ + struct token t; + char *s = *c; + struct pxe_label *label; + int err; + + label = label_create(); + if (!label) + return -ENOMEM; + + err = parse_sliteral(c, &label->name); + if (err < 0) { + printf("Expected label name: %.*s\n", (int)(*c - s), s); + label_destroy(label); + return -EINVAL; + } + + list_add_tail(&label->list, &cfg->labels); + + while (1) { + s = *c; + get_token(c, &t, L_KEYWORD); + + err = 0; + switch (t.type) { + case T_MENU: + err = parse_label_menu(c, cfg, label); + break; + + case T_KERNEL: + err = parse_sliteral(c, &label->kernel); + break; + + case T_APPEND: + err = parse_sliteral(c, &label->append); + break; + + case T_INITRD: + err = parse_sliteral(c, &label->initrd); + break; + + case T_LOCALBOOT: + err = parse_integer(c, &label->localboot); + break; + + case T_EOL: + break; + + default: + /* + * put the token back! we don't want it - it's the end + * of a label and whatever token this is, it's + * something for the menu level context to handle. + */ + *c = s; + return 1; + } + + if (err < 0) + return err; + } +} + +/* + * This 16 comes from the limit pxelinux imposes on nested includes. + * + * There is no reason at all we couldn't do more, but some limit helps prevent + * infinite (until crash occurs) recursion if a file tries to include itself. + */ +#define MAX_NEST_LEVEL 16 + +/* + * Entry point for parsing a menu file. nest_level indicates how many times + * we've nested in includes. It will be 1 for the top level menu file. + * + * Returns 1 on success, < 0 on error. + */ +static int parse_pxefile_top(char *p, struct pxe_menu *cfg, int nest_level) +{ + struct token t; + char *s, *b, *label_name; + int err; + + b = p; + + if (nest_level > MAX_NEST_LEVEL) { + printf("Maximum nesting (%d) exceeded\n", MAX_NEST_LEVEL); + return -EMLINK; + } + + while (1) { + s = p; + + get_token(&p, &t, L_KEYWORD); + + err = 0; + switch (t.type) { + case T_MENU: + err = parse_menu(&p, cfg, b, nest_level); + break; + + case T_TIMEOUT: + err = parse_integer(&p, &cfg->timeout); + break; + + case T_LABEL: + err = parse_label(&p, cfg); + break; + + case T_DEFAULT: + err = parse_sliteral(&p, &label_name); + + if (label_name) { + if (cfg->default_label) + free(cfg->default_label); + + cfg->default_label = label_name; + } + + break; + + case T_PROMPT: + err = parse_integer(&p, &cfg->prompt); + break; + + case T_EOL: + break; + + case T_EOF: + return 1; + + default: + printf("Ignoring unknown command: %.*s\n", + (int)(p - s), s); + eol_or_eof(&p); + } + + if (err < 0) + return err; + } +} + +/* + * Free the memory used by a pxe_menu and its labels. + */ +static void destroy_pxe_menu(struct pxe_menu *cfg) +{ + struct list_head *pos, *n; + struct pxe_label *label; + + if (cfg->title) + free(cfg->title); + + if (cfg->default_label) + free(cfg->default_label); + + list_for_each_safe(pos, n, &cfg->labels) { + label = list_entry(pos, struct pxe_label, list); + + label_destroy(label); + } + + free(cfg); +} + +/* + * Entry point for parsing a pxe file. This is only used for the top level + * file. + * + * Returns NULL if there is an error, otherwise, returns a pointer to a + * pxe_menu struct populated with the results of parsing the pxe file (and any + * files it includes). The resulting pxe_menu struct can be free()'d by using + * the destroy_pxe_menu() function. + */ +static struct pxe_menu *parse_pxefile(char *menucfg) +{ + struct pxe_menu *cfg; + + cfg = malloc(sizeof(struct pxe_menu)); + + if (!cfg) + return NULL; + + memset(cfg, 0, sizeof(struct pxe_menu)); + + INIT_LIST_HEAD(&cfg->labels); + + if (parse_pxefile_top(menucfg, cfg, 1) < 0) { + destroy_pxe_menu(cfg); + return NULL; + } + + return cfg; +} + +/* + * Converts a pxe_menu struct into a menu struct for use with U-boot's generic + * menu code. + */ +static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg) +{ + struct pxe_label *label; + struct list_head *pos; + struct menu *m; + int err; + + /* + * Create a menu and add items for all the labels. + */ + m = menu_create(cfg->title, cfg->timeout, cfg->prompt, label_print); + + if (!m) + return NULL; + + list_for_each(pos, &cfg->labels) { + label = list_entry(pos, struct pxe_label, list); + + if (menu_item_add(m, label->name, label) != 1) { + menu_destroy(m); + return NULL; + } + } + + /* + * After we've created items for each label in the menu, set the + * menu's default label if one was specified. + */ + if (cfg->default_label) { + err = menu_default_set(m, cfg->default_label); + if (err != 1) { + if (err != -ENOENT) { + menu_destroy(m); + return NULL; + } + + printf("Missing default: %s\n", cfg->default_label); + } + } + + return m; +} + +/* + * Try to boot any labels we have yet to attempt to boot. + */ +static void boot_unattempted_labels(struct pxe_menu *cfg) +{ + struct list_head *pos; + struct pxe_label *label; + + list_for_each(pos, &cfg->labels) { + label = list_entry(pos, struct pxe_label, list); + + if (!label->attempted) + label_boot(label); + } +} + +/* + * Boot the system as prescribed by a pxe_menu. + * + * Use the menu system to either get the user's choice or the default, based + * on config or user input. If there is no default or user's choice, + * attempted to boot labels in the order they were given in pxe files. + * If the default or user's choice fails to boot, attempt to boot other + * labels in the order they were given in pxe files. + * + * If this function returns, there weren't any labels that successfully + * booted, or the user interrupted the menu selection via ctrl+c. + */ +static void handle_pxe_menu(struct pxe_menu *cfg) +{ + void *choice; + struct menu *m; + int err; + + m = pxe_menu_to_menu(cfg); + if (!m) + return; + + err = menu_get_choice(m, &choice); + + menu_destroy(m); + + if (err < 1) + return; + + label_boot(choice); + + boot_unattempted_labels(cfg); +} + +/* + * Boots a system using a pxe file + * + * Returns 0 on success, 1 on error. + */ +static int +do_pxe_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + unsigned long pxefile_addr_r; + struct pxe_menu *cfg; + char *pxefile_addr_str; + + if (argc == 1) { + pxefile_addr_str = from_env("pxefile_addr_r"); + if (!pxefile_addr_str) + return 1; + + } else if (argc == 2) { + pxefile_addr_str = argv[1]; + } else { + return cmd_usage(cmdtp); + } + + if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) { + printf("Invalid pxefile address: %s\n", pxefile_addr_str); + return 1; + } + + cfg = parse_pxefile((char *)(pxefile_addr_r)); + + if (cfg == NULL) { + printf("Error parsing config file\n"); + return 1; + } + + handle_pxe_menu(cfg); + + destroy_pxe_menu(cfg); + + return 0; +} + +static cmd_tbl_t cmd_pxe_sub[] = { + U_BOOT_CMD_MKENT(get, 1, 1, do_pxe_get, "", ""), + U_BOOT_CMD_MKENT(boot, 2, 1, do_pxe_boot, "", "") +}; + +int do_pxe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + cmd_tbl_t *cp; + + if (argc < 2) + return cmd_usage(cmdtp); + + /* drop initial "pxe" arg */ + argc--; + argv++; + + cp = find_cmd_tbl(argv[0], cmd_pxe_sub, ARRAY_SIZE(cmd_pxe_sub)); + + if (cp) + return cp->cmd(cmdtp, flag, argc, argv); + + return cmd_usage(cmdtp); +} + +U_BOOT_CMD( + pxe, 3, 1, do_pxe, + "commands to get and boot from pxe files", + "get - try to retrieve a pxe file using tftp\npxe " + "boot [pxefile_addr_r] - boot from the pxe file at pxefile_addr_r\n" +); diff --git a/common/command.c b/common/command.c index ed931d748c..2c0bf53449 100644 --- a/common/command.c +++ b/common/command.c @@ -27,6 +27,7 @@ #include <common.h> #include <command.h> +#include <linux/ctype.h> /* * Use puts() instead of printf() to avoid printf buffer overflow @@ -165,7 +166,7 @@ int var_complete(int argc, char * const argv[], char last_char, int maxv, char * static char tmp_buf[512]; int space; - space = last_char == '\0' || last_char == ' ' || last_char == '\t'; + space = last_char == '\0' || isblank(last_char); if (space && argc == 1) return env_complete("", maxv, cmdv, sizeof(tmp_buf), tmp_buf); @@ -206,7 +207,7 @@ static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv } /* more than one arg or one but the start of the next */ - if (argc > 1 || (last_char == '\0' || last_char == ' ' || last_char == '\t')) { + if (argc > 1 || (last_char == '\0' || isblank(last_char))) { cmdtp = find_cmd(argv[0]); if (cmdtp == NULL || cmdtp->complete == NULL) { cmdv[0] = NULL; @@ -257,7 +258,7 @@ static int make_argv(char *s, int argvsz, char *argv[]) while (argc < argvsz - 1) { /* skip any white space */ - while ((*s == ' ') || (*s == '\t')) + while (isblank(*s)) ++s; if (*s == '\0') /* end of s, no more args */ @@ -266,7 +267,7 @@ static int make_argv(char *s, int argvsz, char *argv[]) argv[argc++] = s; /* begin of argument string */ /* find end of string */ - while (*s && (*s != ' ') && (*s != '\t')) + while (*s && !isblank(*s)) ++s; if (*s == '\0') /* end of s, no more args */ diff --git a/common/fdt_support.c b/common/fdt_support.c index abf6d53781..e0d3fe33e7 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -495,7 +495,7 @@ int fdt_resize(void *blob) total = fdt_num_mem_rsv(blob); for (i = 0; i < total; i++) { fdt_get_mem_rsv(blob, i, &addr, &size); - if (addr == (uint64_t)(u32)blob) { + if (addr == (uintptr_t)blob) { fdt_del_mem_rsv(blob, i); break; } @@ -511,14 +511,14 @@ int fdt_resize(void *blob) fdt_size_dt_strings(blob) + 5 * sizeof(struct fdt_reserve_entry); /* Make it so the fdt ends on a page boundary */ - actualsize = ALIGN(actualsize + ((uint)blob & 0xfff), 0x1000); - actualsize = actualsize - ((uint)blob & 0xfff); + actualsize = ALIGN(actualsize + ((uintptr_t)blob & 0xfff), 0x1000); + actualsize = actualsize - ((uintptr_t)blob & 0xfff); /* Change the fdt header to reflect the correct size */ fdt_set_totalsize(blob, actualsize); /* Add the new reservation */ - ret = fdt_add_mem_rsv(blob, (uint)blob, actualsize); + ret = fdt_add_mem_rsv(blob, (uintptr_t)blob, actualsize); if (ret < 0) return ret; diff --git a/common/hush.c b/common/hush.c index 85a603071f..940889b898 100644 --- a/common/hush.c +++ b/common/hush.c @@ -3217,7 +3217,7 @@ int parse_stream_outer(struct in_str *inp, int flag) #ifndef __U_BOOT__ static int parse_string_outer(const char *s, int flag) #else -int parse_string_outer(char *s, int flag) +int parse_string_outer(const char *s, int flag) #endif /* __U_BOOT__ */ { struct in_str input; diff --git a/common/image.c b/common/image.c index ed6b26bd2a..32ad4da1d3 100644 --- a/common/image.c +++ b/common/image.c @@ -1578,7 +1578,7 @@ int boot_get_fdt (int flag, int argc, char * const argv[], bootm_headers_t *imag goto error; } - printf (" Booting using the fdt blob at 0x%x\n", (int)fdt_blob); + printf(" Booting using the fdt blob at 0x%p\n", fdt_blob); } else if (images->legacy_hdr_valid && image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) { @@ -1597,7 +1597,7 @@ int boot_get_fdt (int flag, int argc, char * const argv[], bootm_headers_t *imag if (fdt_len) { fdt_blob = (char *)fdt_data; - printf (" Booting using the fdt at 0x%x\n", (int)fdt_blob); + printf(" Booting using the fdt at 0x%p\n", fdt_blob); if (fdt_check_header (fdt_blob) != 0) { fdt_error ("image is not a fdt"); diff --git a/common/main.c b/common/main.c index 3324d9d6e4..e96c95a038 100644 --- a/common/main.c +++ b/common/main.c @@ -40,6 +40,7 @@ #endif #include <post.h> +#include <linux/ctype.h> #if defined(CONFIG_SILENT_CONSOLE) || defined(CONFIG_POST) || defined(CONFIG_CMDLINE_EDITING) DECLARE_GLOBAL_DATA_PTR; @@ -83,12 +84,14 @@ extern void mdm_init(void); /* defined in board.c */ /*************************************************************************** * Watch for 'delay' seconds for autoboot stop or autoboot delay string. - * returns: 0 - no key string, allow autoboot - * 1 - got key string, abort + * returns: 0 - no key string, allow autoboot 1 - got key string, abort */ #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) # if defined(CONFIG_AUTOBOOT_KEYED) -static inline int abortboot(int bootdelay) +#ifndef CONFIG_MENU +static inline +#endif +int abortboot(int bootdelay) { int abort = 0; uint64_t etime = endtick(bootdelay); @@ -202,7 +205,10 @@ static inline int abortboot(int bootdelay) static int menukey = 0; #endif -static inline int abortboot(int bootdelay) +#ifndef CONFIG_MENU +static inline +#endif +int abortboot(int bootdelay) { int abort = 0; @@ -260,6 +266,28 @@ static inline int abortboot(int bootdelay) # endif /* CONFIG_AUTOBOOT_KEYED */ #endif /* CONFIG_BOOTDELAY >= 0 */ +/* + * Return 0 on success, or != 0 on error. + */ +#ifndef CONFIG_CMD_PXE +static inline +#endif +int run_command2(const char *cmd, int flag) +{ +#ifndef CONFIG_SYS_HUSH_PARSER + /* + * run_command can return 0 or 1 for success, so clean up its result. + */ + if (run_command(cmd, flag) == -1) + return 1; + + return 0; +#else + return parse_string_outer(cmd, + FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP); +#endif +} + /****************************************************************************/ void main_loop (void) @@ -326,12 +354,7 @@ void main_loop (void) int prev = disable_ctrlc(1); /* disable Control C checking */ # endif -# ifndef CONFIG_SYS_HUSH_PARSER - run_command (p, 0); -# else - parse_string_outer(p, FLAG_PARSE_SEMICOLON | - FLAG_EXIT_FROM_LOOP); -# endif + run_command2(p, 0); # ifdef CONFIG_AUTOBOOT_KEYED disable_ctrlc(prev); /* restore Control C checking */ @@ -376,12 +399,7 @@ void main_loop (void) int prev = disable_ctrlc(1); /* disable Control C checking */ # endif -# ifndef CONFIG_SYS_HUSH_PARSER - run_command (s, 0); -# else - parse_string_outer(s, FLAG_PARSE_SEMICOLON | - FLAG_EXIT_FROM_LOOP); -# endif + run_command2(s, 0); # ifdef CONFIG_AUTOBOOT_KEYED disable_ctrlc(prev); /* restore Control C checking */ @@ -391,14 +409,8 @@ void main_loop (void) # ifdef CONFIG_MENUKEY if (menukey == CONFIG_MENUKEY) { s = getenv("menucmd"); - if (s) { -# ifndef CONFIG_SYS_HUSH_PARSER - run_command(s, 0); -# else - parse_string_outer(s, FLAG_PARSE_SEMICOLON | - FLAG_EXIT_FROM_LOOP); -# endif - } + if (s) + run_command2(s, 0); } #endif /* CONFIG_MENUKEY */ #endif /* CONFIG_BOOTDELAY */ @@ -1088,9 +1100,8 @@ int parse_line (char *line, char *argv[]) while (nargs < CONFIG_SYS_MAXARGS) { /* skip any white space */ - while ((*line == ' ') || (*line == '\t')) { + while (isblank(*line)) ++line; - } if (*line == '\0') { /* end of line, no more args */ argv[nargs] = NULL; @@ -1103,9 +1114,8 @@ int parse_line (char *line, char *argv[]) argv[nargs++] = line; /* begin of argument string */ /* find end of string */ - while (*line && (*line != ' ') && (*line != '\t')) { + while (*line && !isblank(*line)) ++line; - } if (*line == '\0') { /* end of line, no more args */ argv[nargs] = NULL; @@ -1397,14 +1407,9 @@ int do_run (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) printf ("## Error: \"%s\" not defined\n", argv[i]); return 1; } -#ifndef CONFIG_SYS_HUSH_PARSER - if (run_command (arg, flag) == -1) - return 1; -#else - if (parse_string_outer(arg, - FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0) + + if (run_command2(arg, flag) != 0) return 1; -#endif } return 0; } diff --git a/common/menu.c b/common/menu.c new file mode 100644 index 0000000000..f004823363 --- /dev/null +++ b/common/menu.c @@ -0,0 +1,417 @@ +/* + * Copyright 2010-2011 Calxeda, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <common.h> +#include <malloc.h> +#include <errno.h> +#include <linux/list.h> + +#include "menu.h" + +/* + * Internally, each item in a menu is represented by a struct menu_item. + * + * These items will be alloc'd and initialized by menu_item_add and destroyed + * by menu_item_destroy, and the consumer of the interface never sees that + * this struct is used at all. + */ +struct menu_item { + char *key; + void *data; + struct list_head list; +}; + +/* + * The menu is composed of a list of items along with settings and callbacks + * provided by the user. An incomplete definition of this struct is available + * in menu.h, but the full definition is here to prevent consumers from + * relying on its contents. + */ +struct menu { + struct menu_item *default_item; + int timeout; + char *title; + int prompt; + void (*item_data_print)(void *); + struct list_head items; +}; + +/* + * An iterator function for menu items. callback will be called for each item + * in m, with m, a pointer to the item, and extra being passed to callback. If + * callback returns a value other than NULL, iteration stops and the value + * return by callback is returned from menu_items_iter. This allows it to be + * used for search type operations. It is also safe for callback to remove the + * item from the list of items. + */ +static inline void *menu_items_iter(struct menu *m, + void *(*callback)(struct menu *, struct menu_item *, void *), + void *extra) +{ + struct list_head *pos, *n; + struct menu_item *item; + void *ret; + + list_for_each_safe(pos, n, &m->items) { + item = list_entry(pos, struct menu_item, list); + + ret = callback(m, item, extra); + + if (ret) + return ret; + } + + return NULL; +} + +/* + * Print a menu_item. If the consumer provided an item_data_print function + * when creating the menu, call it with a pointer to the item's private data. + * Otherwise, print the key of the item. + */ +static inline void *menu_item_print(struct menu *m, + struct menu_item *item, + void *extra) +{ + if (!m->item_data_print) + printf("%s\n", item->key); + else + m->item_data_print(item->data); + + return NULL; +} + +/* + * Free the memory used by a menu item. This includes the memory used by its + * key. + */ +static inline void *menu_item_destroy(struct menu *m, + struct menu_item *item, + void *extra) +{ + if (item->key) + free(item->key); + + free(item); + + return NULL; +} + +/* + * Display a menu so the user can make a choice of an item. First display its + * title, if any, and then each item in the menu. + */ +static inline void menu_display(struct menu *m) +{ + if (m->title) + printf("%s:\n", m->title); + + menu_items_iter(m, menu_item_print, NULL); +} + +/* + * Check if an item's key matches a provided string, pointed to by extra. If + * extra is NULL, an item with a NULL key will match. Otherwise, the item's + * key has to match according to strcmp. + * + * This is called via menu_items_iter, so it returns a pointer to the item if + * the key matches, and returns NULL otherwise. + */ +static inline void *menu_item_key_match(struct menu *m, + struct menu_item *item, void *extra) +{ + char *item_key = extra; + + if (!item_key || !item->key) { + if (item_key == item->key) + return item; + + return NULL; + } + + if (strcmp(item->key, item_key) == 0) + return item; + + return NULL; +} + +/* + * Find the first item with a key matching item_key, if any exists. + */ +static inline struct menu_item *menu_item_by_key(struct menu *m, + char *item_key) +{ + return menu_items_iter(m, menu_item_key_match, item_key); +} + +/* + * Wait for the user to hit a key according to the timeout set for the menu. + * Returns 1 if the user hit a key, or 0 if the timeout expired. + */ +static inline int menu_interrupted(struct menu *m) +{ + if (!m->timeout) + return 0; + + if (abortboot(m->timeout/10)) + return 1; + + return 0; +} + +/* + * Checks whether or not the default menu item should be used without + * prompting for a user choice. If the menu is set to always prompt, or the + * user hits a key during the timeout period, return 0. Otherwise, return 1 to + * indicate we should use the default menu item. + */ +static inline int menu_use_default(struct menu *m) +{ + return !m->prompt && !menu_interrupted(m); +} + +/* + * Set *choice to point to the default item's data, if any default item was + * set, and returns 1. If no default item was set, returns -ENOENT. + */ +static inline int menu_default_choice(struct menu *m, void **choice) +{ + if (m->default_item) { + *choice = m->default_item->data; + return 1; + } + + return -ENOENT; +} + +/* + * Displays the menu and asks the user to choose an item. *choice will point + * to the private data of the item the user chooses. The user makes a choice + * by inputting a string matching the key of an item. Invalid choices will + * cause the user to be prompted again, repeatedly, until the user makes a + * valid choice. The user can exit the menu without making a choice via ^c. + * + * Returns 1 if the user made a choice, or -EINTR if they bail via ^c. + */ +static inline int menu_interactive_choice(struct menu *m, void **choice) +{ + char cbuf[CONFIG_SYS_CBSIZE]; + struct menu_item *choice_item = NULL; + int readret; + + while (!choice_item) { + cbuf[0] = '\0'; + + menu_display(m); + + readret = readline_into_buffer("Enter choice: ", cbuf); + + if (readret >= 0) { + choice_item = menu_item_by_key(m, cbuf); + + if (!choice_item) + printf("%s not found\n", cbuf); + } else { + printf("^C\n"); + return -EINTR; + } + } + + *choice = choice_item->data; + + return 1; +} + +/* + * menu_default_set() - Sets the default choice for the menu. This is safe to + * call more than once on a menu. + * + * m - Points to a menu created by menu_create(). + * + * item_key - Points to a string that, when compared using strcmp, matches the + * key for an existing item in the menu. + * + * Returns 1 if successful, -EINVAL if m is NULL, or -ENOENT if no item with a + * key matching item_key is found. + */ +int menu_default_set(struct menu *m, char *item_key) +{ + struct menu_item *item; + + if (!m) + return -EINVAL; + + item = menu_item_by_key(m, item_key); + + if (!item) + return -ENOENT; + + m->default_item = item; + + return 1; +} + +/* + * menu_get_choice() - Returns the user's selected menu entry, or the default + * if the menu is set to not prompt or the timeout expires. This is safe to + * call more than once. + * + * m - Points to a menu created by menu_create(). + * + * choice - Points to a location that will store a pointer to the selected + * menu item. If no item is selected or there is an error, no value will be + * written at the location it points to. + * + * Returns 1 if successful, -EINVAL if m or choice is NULL, -ENOENT if no + * default has been set and the menu is set to not prompt or the timeout + * expires, or -EINTR if the user exits the menu via ^c. + */ +int menu_get_choice(struct menu *m, void **choice) +{ + if (!m || !choice) + return -EINVAL; + + if (menu_use_default(m)) + return menu_default_choice(m, choice); + + return menu_interactive_choice(m, choice); +} + +/* + * menu_item_add() - Adds or replaces a menu item. Note that this replaces the + * data of an item if it already exists, but doesn't change the order of the + * item. + * + * m - Points to a menu created by menu_create(). + * + * item_key - Points to a string that will uniquely identify the item. The + * string will be copied to internal storage, and is safe to discard after + * passing to menu_item_add. + * + * item_data - An opaque pointer associated with an item. It is never + * dereferenced internally, but will be passed to the item_data_print, and + * will be returned from menu_get_choice if the menu item is selected. + * + * Returns 1 if successful, -EINVAL if m is NULL, or -ENOMEM if there is + * insufficient memory to add the menu item. + */ +int menu_item_add(struct menu *m, char *item_key, void *item_data) +{ + struct menu_item *item; + + if (!m) + return -EINVAL; + + item = menu_item_by_key(m, item_key); + + if (item) { + item->data = item_data; + return 1; + } + + item = malloc(sizeof *item); + if (!item) + return -ENOMEM; + + item->key = strdup(item_key); + + if (!item->key) { + free(item); + return -ENOMEM; + } + + item->data = item_data; + + list_add_tail(&item->list, &m->items); + + return 1; +} + +/* + * menu_create() - Creates a menu handle with default settings + * + * title - If not NULL, points to a string that will be displayed before the + * list of menu items. It will be copied to internal storage, and is safe to + * discard after passing to menu_create(). + * + * timeout - A delay in seconds to wait for user input. If 0, timeout is + * disabled, and the default choice will be returned unless prompt is 1. + * + * prompt - If 0, don't ask for user input unless there is an interrupted + * timeout. If 1, the user will be prompted for input regardless of the value + * of timeout. + * + * item_data_print - If not NULL, will be called for each item when the menu + * is displayed, with the pointer to the item's data passed as the argument. + * If NULL, each item's key will be printed instead. Since an item's key is + * what must be entered to select an item, the item_data_print function should + * make it obvious what the key for each entry is. + * + * Returns a pointer to the menu if successful, or NULL if there is + * insufficient memory available to create the menu. + */ +struct menu *menu_create(char *title, int timeout, int prompt, + void (*item_data_print)(void *)) +{ + struct menu *m; + + m = malloc(sizeof *m); + + if (!m) + return NULL; + + m->default_item = NULL; + m->prompt = prompt; + m->timeout = timeout; + m->item_data_print = item_data_print; + + if (title) { + m->title = strdup(title); + if (!m->title) { + free(m); + return NULL; + } + } else + m->title = NULL; + + + INIT_LIST_HEAD(&m->items); + + return m; +} + +/* + * menu_destroy() - frees the memory used by a menu and its items. + * + * m - Points to a menu created by menu_create(). + * + * Returns 1 if successful, or -EINVAL if m is NULL. + */ +int menu_destroy(struct menu *m) +{ + if (!m) + return -EINVAL; + + menu_items_iter(m, menu_item_destroy, NULL); + + if (m->title) + free(m->title); + + free(m); + + return 1; +} @@ -277,6 +277,13 @@ export CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%)) ALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR)) ALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) +EXTRA_CPPFLAGS = $(CPPFLAGS_$(BCURDIR)/$(@F)) $(CPPFLAGS_$(BCURDIR)) +ALL_CFLAGS += $(EXTRA_CPPFLAGS) + +# The _DEP version uses the $< file target (for dependency generation) +# See rules.mk +EXTRA_CPPFLAGS_DEP = $(CPPFLAGS_$(BCURDIR)/$(addsuffix .o,$(basename $<))) \ + $(CPPFLAGS_$(BCURDIR)) $(obj)%.s: %.S $(CPP) $(ALL_AFLAGS) -o $@ $< $(obj)%.o: %.S diff --git a/doc/README.menu b/doc/README.menu new file mode 100644 index 0000000000..1259c6ad57 --- /dev/null +++ b/doc/README.menu @@ -0,0 +1,119 @@ +/* + * Copyright 2010-2011 Calxeda, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ + +U-boot provides a set of interfaces for creating and using simple, text +based menus. Menus are displayed as lists of labeled entries on the +console, and an entry can be selected by entering its label. + +To use the menu code, enable CONFIG_MENU, and include "menu.h" where +the interfaces should be available. + +Menus are composed of items. Each item has a key used to identify it in +the menu, and an opaque pointer to data controlled by the consumer. + +Interfaces +---------- +#include "menu.h" + +/* + * Consumers of the menu interfaces will use a struct menu * as the + * handle for a menu. struct menu is only fully defined in menu.c, + * preventing consumers of the menu interfaces from accessing its + * contents directly. + */ +struct menu; + +/* + * NOTE: See comments in common/menu.c for more detailed documentation on + * these interfaces. + */ + +/* + * menu_create() - Creates a menu handle with default settings + */ +struct menu *menu_create(char *title, int timeout, int prompt, + void (*item_data_print)(void *)); + +/* + * menu_item_add() - Adds or replaces a menu item + */ +int menu_item_add(struct menu *m, char *item_key, void *item_data); + +/* + * menu_default_set() - Sets the default choice for the menu + */ +int menu_default_set(struct menu *m, char *item_key); + +/* + * menu_get_choice() - Returns the user's selected menu entry, or the + * default if the menu is set to not prompt or the timeout expires. + */ +int menu_get_choice(struct menu *m, void **choice); + +/* + * menu_destroy() - frees the memory used by a menu and its items. + */ +int menu_destroy(struct menu *m); + + +Example Code +------------ +This example creates a menu that always prompts, and allows the user +to pick from a list of tools. The item key and data are the same. + +#include "menu.h" + +char *tools[] = { + "Hammer", + "Screwdriver", + "Nail gun", + NULL +}; + +char *pick_a_tool(void) +{ + struct menu *m; + int i; + char *tool = NULL; + + m = menu_create("Tools", 0, 1, NULL); + + for(i = 0; tools[i]; i++) { + if (menu_item_add(m, tools[i], tools[i]) != 1) { + printf("failed to add item!"); + menu_destroy(m); + return NULL; + } + } + + if (menu_get_choice(m, (void **)&tool) != 1) + printf("Problem picking tool!\n"); + + menu_destroy(m); + + return tool; +} + +void caller(void) +{ + char *tool = pick_a_tool(); + + if (tool) { + printf("picked a tool: %s\n", tool); + use_tool(tool); + } +} diff --git a/doc/README.pxe b/doc/README.pxe new file mode 100644 index 0000000000..9026d9c9df --- /dev/null +++ b/doc/README.pxe @@ -0,0 +1,240 @@ +/* + * Copyright 2010-2011 Calxeda, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ + +The 'pxe' commands provide a near subset of the functionality provided by +the PXELINUX boot loader. This allows U-boot based systems to be controlled +remotely using the same PXE based techniques that many non U-boot based servers +use. + +Commands +======== + +pxe get +------- + syntax: pxe get + + follows PXELINUX's rules for retrieving configuration files from a tftp + server, and supports a subset of PXELINUX's config file syntax. + + Environment + ----------- + 'pxe get' requires two environment variables to be set: + + pxefile_addr_r - should be set to a location in RAM large enough to hold + pxe files while they're being processed. Up to 16 config files may be + held in memory at once. The exact number and size of the files varies with + how the system is being used. A typical config file is a few hundred bytes + long. + + bootfile,serverip - these two are typically set in the DHCP response + handler, and correspond to fields in the DHCP response. + + 'pxe get' optionally supports these two environment variables being set: + + ethaddr - this is the standard MAC address for the ethernet adapter in use. + 'pxe get' uses it to look for a configuration file specific to a system's + MAC address. + + pxeuuid - this is a UUID in standard form using lower case hexadecimal + digits, for example, 550e8400-e29b-41d4-a716-446655440000. 'pxe get' uses + it to look for a configuration file based on the system's UUID. + + File Paths + ---------- + 'pxe get' repeatedly tries to download config files until it either + successfully downloads one or runs out of paths to try. The order and + contents of paths it tries mirrors exactly that of PXELINUX - you can + read in more detail about it at: + + http://syslinux.zytor.com/wiki/index.php/Doc/pxelinux + +pxe boot +-------- + syntax: pxe boot [pxefile_addr_r] + + Interprets a pxe file stored in memory. + + pxefile_addr_r is an optional argument giving the location of the pxe file. + The file must be terminated with a NUL byte. + + Environment + ----------- + There are some environment variables that may need to be set, depending + on conditions. + + pxefile_addr_r - if the optional argument pxefile_addr_r is not supplied, + an environment variable named pxefile_addr_r must be supplied. This is + typically the same value as is used for the 'pxe get' command. + + bootfile - typically set in the DHCP response handler based on the + same field in the DHCP respone, this path is used to generate the base + directory that all other paths to files retrieved by 'pxe boot' will use. + If no bootfile is specified, paths used in pxe files will be used as is. + + serverip - typically set in the DHCP response handler, this is the IP + address of the tftp server from which other files will be retrieved. + + kernel_addr_r, initrd_addr_r - locations in RAM at which 'pxe boot' will + store the kernel and initrd it retrieves from tftp. These locations will + be passed to the bootm command to boot the kernel. These environment + variables are required to be set. + + fdt_addr - the location of a fdt blob. If this is set, it will be passed + to bootm when booting a kernel. + +pxe file format +=============== +The pxe file format is nearly a subset of the PXELINUX file format; see +http://syslinux.zytor.com/wiki/index.php/PXELINUX. It's composed of one line +commands - global commands, and commands specific to labels. Lines begining +with # are treated as comments. White space between and at the beginning of +lines is ignored. + +The size of pxe files and the number of labels is only limited by the amount +of RAM available to U-boot. Memory for labels is dynamically allocated as +they're parsed, and memory for pxe files is statically allocated, and its +location is given by the pxefile_addr_r environment variable. The pxe code is +not aware of the size of the pxefile memory and will outgrow it if pxe files +are too large. + +Supported global commands +------------------------- +Unrecognized commands are ignored. + +default <label> - the label named here is treated as the default and is + the first label 'pxe boot' attempts to boot. + +menu title <string> - sets a title for the menu of labels being displayed. + +menu include <path> - use tftp to retrieve the pxe file at <path>, which + is then immediately parsed as if the start of its + contents were the next line in the current file. nesting + of include up to 16 files deep is supported. + +prompt <flag> - if 1, always prompt the user to enter a label to boot + from. if 0, only prompt the user if timeout expires. + +timeout <num> - wait for user input for <num>/10 seconds before + auto-booting a node. + +label <name> - begin a label definition. labels continue until + a command not recognized as a label command is seen, + or EOF is reached. + +Supported label commands +------------------------ +labels end when a command not recognized as a label command is reached, or EOF. + +menu default - set this label as the default label to boot; this is + the same behavior as the global default command but + specified in a different way + +kernel <path> - if this label is chosen, use tftp to retrieve the kernel + at <path>. it will be stored at the address indicated in + the kernel_addr_r environment variable, and that address + will be passed to bootm to boot this kernel. + +append <string> - use <string> as the kernel command line when booting this + label. + +initrd <path> - if this label is chosen, use tftp to retrieve the initrd + at <path>. it will be stored at the address indicated in + the initrd_addr_r environment variable, and that address + will be passed to bootm. + +localboot <flag> - Run the command defined by "localcmd" in the environment. + <flag> is ignored and is only here to match the syntax of + PXELINUX config files. + +Example +------- +Here's a couple of example files to show how this works. + +------------/tftpboot/pxelinux.cfg/menus/linux.list---------- +menu title Linux selections + +# This is the default label +label install + menu label Default Install Image + kernel kernels/install.bin + append console=ttyAMA0,38400 debug earlyprintk + initrd initrds/uzInitrdDebInstall + +# Just another label +label linux-2.6.38 + kernel kernels/linux-2.6.38.bin + append root=/dev/sdb1 + +# The locally installed kernel +label local + menu label Locally installed kernel + append root=/dev/sdb1 + localboot 1 +------------------------------------------------------------- + +------------/tftpboot/pxelinux.cfg/default------------------- +menu include pxelinux.cfg/menus/base.menu +timeout 500 + +default linux-2.6.38 +------------------------------------------------------------- + +When a pxe client retrieves and boots the default pxe file, +'pxe boot' will wait for user input for 5 seconds before booting +the linux-2.6.38 label, which will cause /tftpboot/kernels/linux-2.6.38.bin +to be downloaded, and boot with the command line "root=/dev/sdb1" + +Differences with PXELINUX +========================= +The biggest difference between U-boot's pxe and PXELINUX is that since +U-boot's pxe support is written entirely in C, it can run on any platform +with network support in U-boot. Here are some other differences between +PXELINUX and U-boot's pxe support. + +- U-boot's pxe does not support the PXELINUX DHCP option codes specified + in RFC 5071, but could be extended to do so. + +- when U-boot's pxe fails to boot, it will return control to U-boot, + allowing another command to run, other U-boot command, instead of resetting + the machine like PXELINUX. + +- U-boot's pxe doesn't rely on or provide an UNDI/PXE stack in memory, it + only uses U-boot. + +- U-boot's pxe doesn't provide the full menu implementation that PXELINUX + does, only a simple text based menu using the commands described in + this README. With PXELINUX, it's possible to have a graphical boot + menu, submenus, passwords, etc. U-boot's pxe could be extended to support + a more robust menuing system like that of PXELINUX's. + +- U-boot's pxe expects U-boot uimg's as kernels. Anything that would work + with the 'bootm' command in U-boot could work with the 'pxe boot' command. + +- U-boot's pxe doesn't recognize initrd options in the append command - you + must specify initrd files using the initrd command. + +- U-boot's pxe only recognizes a single file on the initrd command line. It + could be extended to support multiple. + +- in U-boot's pxe, the localboot command doesn't necessarily cause a local + disk boot - it will do whatever is defined in the 'localcmd' env + variable. And since it doesn't support a full UNDI/PXE stack, the + type field is ignored. + +- the interactive prompt in U-boot's pxe only allows you to choose a label + from the menu. If you want to boot something not listed, you can ctrl+c + out of 'pxe boot' and use existing U-boot commands to accomplish it. diff --git a/doc/README.sandbox b/doc/README.sandbox new file mode 100644 index 0000000000..04692b34fa --- /dev/null +++ b/doc/README.sandbox @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +Native Execution of U-Boot +========================== + +The 'sandbox' architecture is designed to allow U-Boot to run under Linux on +almost any hardware. To achieve this it builds U-Boot (so far as possible) +as a normal C application with a main() and normal C libraries. + +All of U-Boot's architecture-specific code therefore cannot be built as part +of the sandbox U-Boot. The purpose of running U-Boot under Linux is to test +all the generic code, not specific to any one architecture. The idea is to +create unit tests which we can run to test this upper level code. + +CONFIG_SANDBOX is defined when building a native board. + +The chosen vendor and board names are also 'sandbox', so there is a single +board in board/sandbox/sandbox. + +CONFIG_SANDBOX_BIG_ENDIAN should be defined when running on big-endian +machines. + +Note that standalone/API support is not available at present. + +The serial driver is a very simple implementation which reads and writes to +the console. It does not set the terminal into raw mode, so cursor keys and +history will not work yet. + + +Tests +----- + +So far we have no tests, but when we do these will be documented here. diff --git a/drivers/bios_emulator/x86emu/debug.c b/drivers/bios_emulator/x86emu/debug.c index 241acf3a89..6417d09998 100644 --- a/drivers/bios_emulator/x86emu/debug.c +++ b/drivers/bios_emulator/x86emu/debug.c @@ -39,6 +39,7 @@ #include <stdarg.h> #include <common.h> +#include <linux/ctype.h> #include "x86emu/x86emui.h" /*----------------------------- Implementation ----------------------------*/ @@ -333,7 +334,7 @@ static int x86emu_parse_line(char *s, int *ps, int *n) int cmd; *n = 0; - while (*s == ' ' || *s == '\t') + while (isblank(*s)) s++; ps[*n] = *s; switch (*s) { @@ -346,13 +347,13 @@ static int x86emu_parse_line(char *s, int *ps, int *n) } while (1) { - while (*s != ' ' && *s != '\t' && *s != '\n') + while (!isblank(*s) && *s != '\n') s++; if (*s == '\n') return cmd; - while (*s == ' ' || *s == '\t') + while (isblank(*s)) s++; *n += 1; diff --git a/drivers/gpio/kw_gpio.c b/drivers/gpio/kw_gpio.c index 56383c2875..2de179e827 100644 --- a/drivers/gpio/kw_gpio.c +++ b/drivers/gpio/kw_gpio.c @@ -109,7 +109,7 @@ void kw_gpio_set_valid(unsigned pin, int mode) */ int kw_gpio_direction_input(unsigned pin) { - if (!kw_gpio_is_valid(pin, GPIO_INPUT_OK)) + if (kw_gpio_is_valid(pin, GPIO_INPUT_OK) != 0) return 1; /* Configure GPIO direction. */ diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index b5c55738f7..04241109cc 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -116,13 +116,21 @@ static u8 DM9000_ior(int); static void DM9000_iow(int reg, u8 value); /* DM9000 network board routine ---------------------------- */ - +#ifndef CONFIG_DM9000_BYTE_SWAPPED #define DM9000_outb(d,r) writeb(d, (volatile u8 *)(r)) #define DM9000_outw(d,r) writew(d, (volatile u16 *)(r)) #define DM9000_outl(d,r) writel(d, (volatile u32 *)(r)) #define DM9000_inb(r) readb((volatile u8 *)(r)) #define DM9000_inw(r) readw((volatile u16 *)(r)) #define DM9000_inl(r) readl((volatile u32 *)(r)) +#else +#define DM9000_outb(d, r) __raw_writeb(d, r) +#define DM9000_outw(d, r) __raw_writew(d, r) +#define DM9000_outl(d, r) __raw_writel(d, r) +#define DM9000_inb(r) __raw_readb(r) +#define DM9000_inw(r) __raw_readw(r) +#define DM9000_inl(r) __raw_readl(r) +#endif #ifdef CONFIG_DM9000_DEBUG static void diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile index 1dcc1c7f6a..6309549fce 100644 --- a/drivers/serial/Makefile +++ b/drivers/serial/Makefile @@ -53,6 +53,7 @@ COBJS-$(CONFIG_SA1100_SERIAL) += serial_sa1100.o COBJS-$(CONFIG_S3C24X0_SERIAL) += serial_s3c24x0.o COBJS-$(CONFIG_S3C44B0_SERIAL) += serial_s3c44b0.o COBJS-$(CONFIG_XILINX_UARTLITE) += serial_xuartlite.o +COBJS-$(CONFIG_SANDBOX_SERIAL) += sandbox.o COBJS-$(CONFIG_SCIF_CONSOLE) += serial_sh.o COBJS-$(CONFIG_TEGRA2) += serial_tegra2.o diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c new file mode 100644 index 0000000000..0d65587f71 --- /dev/null +++ b/drivers/serial/sandbox.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +/* + * This provide a test serial port. It provides an emulated serial port where + * a test program and read out the serial output and inject serial input for + * U-Boot. + */ + +#include <common.h> +#include <os.h> + +int serial_init(void) +{ + return 0; +} + +void serial_setbrg(void) +{ +} + +void serial_putc(const char ch) +{ + os_write(1, &ch, 1); +} + +void serial_puts(const char *str) +{ + while (*str) + serial_putc(*str++); +} + +int serial_getc(void) +{ + char buf; + int count; + + count = os_read(0, &buf, 1); + return count == 1 ? buf : 0; +} + +int serial_tstc(void) +{ + return 0; +} diff --git a/drivers/serial/usbtty.h b/drivers/serial/usbtty.h index a23169a29d..14961c1969 100644 --- a/drivers/serial/usbtty.h +++ b/drivers/serial/usbtty.h @@ -37,7 +37,7 @@ #include <usb/spr_udc.h> #endif -#include <version_autogenerated.h> +#include <version.h> /* If no VendorID/ProductID is defined in config.h, pretend to be Linux * DO NOT Reuse this Vendor/Product setup with protocol incompatible devices */ diff --git a/examples/standalone/smc911x_eeprom.c b/examples/standalone/smc911x_eeprom.c index 00e826689f..6c79c5f65a 100644 --- a/examples/standalone/smc911x_eeprom.c +++ b/examples/standalone/smc911x_eeprom.c @@ -16,6 +16,7 @@ #include <common.h> #include <exports.h> +#include <linux/ctype.h> #include "../drivers/net/smc911x.h" /** @@ -128,7 +129,7 @@ static int write_eeprom_reg(struct eth_device *dev, u8 value, u8 reg) */ static char *skip_space(char *buf) { - while (buf[0] == ' ' || buf[0] == '\t') + while (isblank(buf[0])) ++buf; return buf; } @@ -357,7 +358,7 @@ int smc911x_eeprom(int argc, char * const argv[]) continue; /* Only accept 1 letter commands */ - if (line[0] && line[1] && line[1] != ' ' && line[1] != '\t') + if (line[0] && line[1] && !isblank(line[1])) goto unknown_cmd; /* Now parse the command */ diff --git a/include/.gitignore b/include/.gitignore index 77594e53ff..ec224c545c 100644 --- a/include/.gitignore +++ b/include/.gitignore @@ -3,5 +3,3 @@ /bmp_logo.h /config.h /config.mk -/timestamp_autogenerated.h -/version_autogenerated.h diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h new file mode 100644 index 0000000000..a1ebb28aec --- /dev/null +++ b/include/asm-generic/gpio.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +/* + * Generic GPIO API for U-Boot + * + * GPIOs are numbered from 0 to GPIO_COUNT-1 which value is defined + * by the SOC/architecture. + * + * Each GPIO can be an input or output. If an input then its value can + * be read as 0 or 1. If an output then its value can be set to 0 or 1. + * If you try to write an input then the value is undefined. If you try + * to read an output, barring something very unusual, you will get + * back the value of the output that you previously set. + * + * In some cases the operation may fail, for example if the GPIO number + * is out of range, or the GPIO is not available because its pin is + * being used by another function. In that case, functions may return + * an error value of -1. + */ + +/** + * Make a GPIO an input. + * + * @param gp GPIO number + * @return 0 if ok, -1 on error + */ +int gpio_direction_input(int gp); + +/** + * Make a GPIO an output, and set its value. + * + * @param gp GPIO number + * @param value GPIO value (0 for low or 1 for high) + * @return 0 if ok, -1 on error + */ +int gpio_direction_output(int gp, int value); + +/** + * Get a GPIO's value. This will work whether the GPIO is an input + * or an output. + * + * @param gp GPIO number + * @return 0 if low, 1 if high, -1 on error + */ +int gpio_get_value(int gp); + +/** + * Set an output GPIO's value. The GPIO must already be an output of + * this function may have no effect. + * + * @param gp GPIO number + * @param value GPIO value (0 for low or 1 for high) + * @return 0 if ok, -1 on error + */ +int gpio_set_value(int gp, int value); diff --git a/include/command.h b/include/command.h index f1accd0953..c2701101d5 100644 --- a/include/command.h +++ b/include/command.h @@ -117,7 +117,8 @@ extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); #define CMD_FLAG_REPEAT 0x0001 /* repeat last command */ #define CMD_FLAG_BOOTD 0x0002 /* command is from bootd */ -#define Struct_Section __attribute__ ((unused,section (".u_boot_cmd"))) +#define Struct_Section __attribute__((unused, section(".u_boot_cmd"), \ + aligned(4))) #ifdef CONFIG_AUTO_COMPLETE # define _CMD_COMPLETE(x) x, diff --git a/include/common.h b/include/common.h index a55600b182..4c3e3a68dc 100644 --- a/include/common.h +++ b/include/common.h @@ -255,11 +255,17 @@ int print_buffer (ulong addr, void* data, uint width, uint count, uint linelen); /* common/main.c */ void main_loop (void); int run_command (const char *cmd, int flag); +#ifdef CONFIG_CMD_PXE +int run_command2(const char *cmd, int flag); +#endif int readline (const char *const prompt); int readline_into_buffer (const char *const prompt, char * buffer); int parse_line (char *, char *[]); void init_cmd_timeout(void); void reset_cmd_timeout(void); +#ifdef CONFIG_MENU +int abortboot(int bootdelay); +#endif /* arch/$(ARCH)/lib/board.c */ void board_init_f (ulong) __attribute__ ((noreturn)); @@ -282,6 +288,9 @@ extern ulong load_addr; /* Default Load Address */ /* common/cmd_doc.c */ void doc_probe(unsigned long physadr); +/* common/cmd_net.c */ +int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); + /* common/cmd_nvedit.c */ int env_init (void); void env_relocate (void); @@ -302,6 +311,9 @@ int setenv (const char *, const char *); #ifdef CONFIG_X86 /* x86 version to be fixed! */ # include <asm/u-boot-x86.h> #endif /* CONFIG_X86 */ +#ifdef CONFIG_SANDBOX +# include <asm/u-boot-sandbox.h> /* TODO(sjg) what needs to be fixed? */ +#endif #ifdef CONFIG_AUTO_COMPLETE int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf); @@ -691,6 +703,10 @@ int strcmp_compar(const void *, const void *); /* lib/time.c */ void udelay (unsigned long); +/* lib/uuid.c */ +void uuid_str_to_bin(const char *uuid, unsigned char *out); +int uuid_str_valid(const char *uuid); + /* lib/vsprintf.c */ ulong simple_strtoul(const char *cp,char **endp,unsigned int base); int strict_strtoul(const char *cp, unsigned int base, unsigned long *res); diff --git a/include/compiler.h b/include/compiler.h index 4e047c7fd2..54999a7e82 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -111,11 +111,25 @@ typedef unsigned int uint; #include <linux/types.h> #include <asm/byteorder.h> +#if __SIZEOF_LONG__ == 8 +# define __WORDSIZE 64 +#elif __SIZEOF_LONG__ == 4 +# define __WORDSIZE 32 +#else +/* + * Assume 32-bit for now - only newer toolchains support this feature and + * this is only required for sandbox support at present. + */ +#define __WORDSIZE 32 +#endif + /* Types for `void *' pointers. */ #if __WORDSIZE == 64 typedef unsigned long int uintptr_t; -#else +#elif __WORDSIZE == 32 typedef unsigned int uintptr_t; +#else +#error "__WORDSIZE has unexpected value" #endif #endif diff --git a/include/configs/CPU86.h b/include/configs/CPU86.h index ab64adae0e..abf4ef4212 100644 --- a/include/configs/CPU86.h +++ b/include/configs/CPU86.h @@ -89,8 +89,8 @@ * - RAM for BD/Buffers is on the 60x Bus (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC1|CMXFCR_RF1CS_MSK|CMXFCR_TF1CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF1CS_CLK11|CMXFCR_TF1CS_CLK12) +# define CONFIG_SYS_CMXFCR_MASK1 (CMXFCR_FC1|CMXFCR_RF1CS_MSK|CMXFCR_TF1CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE1 (CMXFCR_RF1CS_CLK11|CMXFCR_TF1CS_CLK12) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) @@ -102,8 +102,8 @@ * - RAM for BD/Buffers is on the 60x Bus (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) +# define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) diff --git a/include/configs/CPU87.h b/include/configs/CPU87.h index 2b1716afee..723bdf3fd5 100644 --- a/include/configs/CPU87.h +++ b/include/configs/CPU87.h @@ -93,8 +93,8 @@ * - RAM for BD/Buffers is on the 60x Bus (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC1|CMXFCR_RF1CS_MSK|CMXFCR_TF1CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF1CS_CLK11|CMXFCR_TF1CS_CLK12) +# define CONFIG_SYS_CMXFCR_MASK1 (CMXFCR_FC1|CMXFCR_RF1CS_MSK|CMXFCR_TF1CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE1 (CMXFCR_RF1CS_CLK11|CMXFCR_TF1CS_CLK12) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) @@ -106,8 +106,8 @@ * - RAM for BD/Buffers is on the 60x Bus (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) +# define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) diff --git a/include/configs/IDS8247.h b/include/configs/IDS8247.h index 8552250412..be778fe809 100644 --- a/include/configs/IDS8247.h +++ b/include/configs/IDS8247.h @@ -154,8 +154,8 @@ * - RAM for BD/Buffers is on the 60x Bus (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC1|CMXFCR_RF1CS_MSK|CMXFCR_TF1CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF1CS_CLK10|CMXFCR_TF1CS_CLK9) +# define CONFIG_SYS_CMXFCR_MASK1 (CMXFCR_FC1|CMXFCR_RF1CS_MSK|CMXFCR_TF1CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE1 (CMXFCR_RF1CS_CLK10|CMXFCR_TF1CS_CLK9) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) diff --git a/include/configs/IPHASE4539.h b/include/configs/IPHASE4539.h index 0af43b667d..d9663062b9 100644 --- a/include/configs/IPHASE4539.h +++ b/include/configs/IPHASE4539.h @@ -82,8 +82,8 @@ * - Select bus for bd/buffers (see 28-13) * - Half duplex */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC3 | CMXFCR_RF3CS_MSK | CMXFCR_TF3CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF3CS_CLK14 | CMXFCR_TF3CS_CLK16) +# define CONFIG_SYS_CMXFCR_MASK3 (CMXFCR_FC3 | CMXFCR_RF3CS_MSK | CMXFCR_TF3CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE3 (CMXFCR_RF3CS_CLK14 | CMXFCR_TF3CS_CLK16) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) diff --git a/include/configs/ISPAN.h b/include/configs/ISPAN.h index 49c6510703..922b0798cf 100644 --- a/include/configs/ISPAN.h +++ b/include/configs/ISPAN.h @@ -72,8 +72,8 @@ #if CONFIG_ETHER_INDEX == 3 #define CONFIG_SYS_PHY_ADDR 0 -#define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF3CS_CLK14 | CMXFCR_TF3CS_CLK16) -#define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC3 | CMXFCR_RF3CS_MSK | CMXFCR_TF3CS_MSK) +#define CONFIG_SYS_CMXFCR_VALUE3 (CMXFCR_RF3CS_CLK14 | CMXFCR_TF3CS_CLK16) +#define CONFIG_SYS_CMXFCR_MASK3 (CMXFCR_FC3 | CMXFCR_RF3CS_MSK | CMXFCR_TF3CS_MSK) #endif /* CONFIG_ETHER_INDEX == 3 */ diff --git a/include/configs/MPC8260ADS.h b/include/configs/MPC8260ADS.h index 2225b46b28..e4ea178f5e 100644 --- a/include/configs/MPC8260ADS.h +++ b/include/configs/MPC8260ADS.h @@ -128,20 +128,20 @@ #if CONFIG_ETHER_INDEX == 1 # define CONFIG_SYS_PHY_ADDR 0 -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF1CS_CLK11 | CMXFCR_TF1CS_CLK10) -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC1 | CMXFCR_RF1CS_MSK | CMXFCR_TF1CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE1 (CMXFCR_RF1CS_CLK11 | CMXFCR_TF1CS_CLK10) +# define CONFIG_SYS_CMXFCR_MASK1 (CMXFCR_FC1 | CMXFCR_RF1CS_MSK | CMXFCR_TF1CS_MSK) #elif CONFIG_ETHER_INDEX == 2 #if CONFIG_ADSTYPE == CONFIG_SYS_8272ADS /* RxCLK is CLK15, TxCLK is CLK16 */ # define CONFIG_SYS_PHY_ADDR 3 -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK15 | CMXFCR_TF2CS_CLK16) +# define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK15 | CMXFCR_TF2CS_CLK16) #else /* RxCLK is CLK13, TxCLK is CLK14 */ # define CONFIG_SYS_PHY_ADDR 0 -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) +# define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) #endif /* CONFIG_ADSTYPE == CONFIG_SYS_8272ADS */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) +# define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) #endif /* CONFIG_ETHER_INDEX */ diff --git a/include/configs/MPC8266ADS.h b/include/configs/MPC8266ADS.h index 5794473368..0474140fb3 100644 --- a/include/configs/MPC8266ADS.h +++ b/include/configs/MPC8266ADS.h @@ -122,8 +122,8 @@ * - Select bus for bd/buffers (see 28-13) * - Half duplex */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) +# define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE | FCC_PSMR_LPB) diff --git a/include/configs/MPC8560ADS.h b/include/configs/MPC8560ADS.h index 8cf2bf2b3c..84a5bccbc2 100644 --- a/include/configs/MPC8560ADS.h +++ b/include/configs/MPC8560ADS.h @@ -333,8 +333,8 @@ * - Select bus for bd/buffers * - Full duplex */ - #define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) - #define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) + #define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) + #define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) #define CONFIG_SYS_CPMFCR_RAMTYPE 0 #define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE) #define FETH2_RST 0x01 diff --git a/include/configs/RPXsuper.h b/include/configs/RPXsuper.h index 9d97f2fd37..c1865fc636 100644 --- a/include/configs/RPXsuper.h +++ b/include/configs/RPXsuper.h @@ -107,8 +107,8 @@ * - RAM for BD/Buffers is on the 60x Bus (see 28-13) * - Enable Half Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC3|CMXFCR_RF3CS_MSK|CMXFCR_TF3CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF3CS_CLK15|CMXFCR_TF3CS_CLK16) +# define CONFIG_SYS_CMXFCR_MASK3 (CMXFCR_FC3|CMXFCR_RF3CS_MSK|CMXFCR_TF3CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE3 (CMXFCR_RF3CS_CLK15|CMXFCR_TF3CS_CLK16) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 /*#define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) */ # define CONFIG_SYS_FCC_PSMR 0 diff --git a/include/configs/Rattler.h b/include/configs/Rattler.h index 4844fba885..9ddf626eb9 100644 --- a/include/configs/Rattler.h +++ b/include/configs/Rattler.h @@ -80,8 +80,8 @@ * - BDs/buffers on 60x bus * - Full duplex */ -#define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC1 | CMXFCR_RF1CS_MSK | CMXFCR_TF1CS_MSK) -#define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF1CS_CLK11 | CMXFCR_TF1CS_CLK10) +#define CONFIG_SYS_CMXFCR_MASK1 (CMXFCR_FC1 | CMXFCR_RF1CS_MSK | CMXFCR_TF1CS_MSK) +#define CONFIG_SYS_CMXFCR_VALUE1 (CMXFCR_RF1CS_CLK11 | CMXFCR_TF1CS_CLK10) #define CONFIG_SYS_CPMFCR_RAMTYPE 0 #define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE | FCC_PSMR_LPB) @@ -92,8 +92,8 @@ * - BDs/buffers on 60x bus * - Full duplex */ -#define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) -#define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK15 | CMXFCR_TF2CS_CLK14) +#define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) +#define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK15 | CMXFCR_TF2CS_CLK14) #define CONFIG_SYS_CPMFCR_RAMTYPE 0 #define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE | FCC_PSMR_LPB) diff --git a/include/configs/SBC8540.h b/include/configs/SBC8540.h index 7a96530803..434b96b1d3 100644 --- a/include/configs/SBC8540.h +++ b/include/configs/SBC8540.h @@ -260,8 +260,8 @@ * - Select bus for bd/buffers * - Full duplex */ - #define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) - #define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) + #define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) + #define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) #define CONFIG_SYS_CPMFCR_RAMTYPE 0 #define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE) diff --git a/include/configs/SCM.h b/include/configs/SCM.h index ec26290be0..73216dc799 100644 --- a/include/configs/SCM.h +++ b/include/configs/SCM.h @@ -153,8 +153,8 @@ * - RAM for BD/Buffers is on the 60x Bus (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC1|CMXFCR_RF1CS_MSK|CMXFCR_TF1CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF1CS_CLK12|CMXFCR_TF1CS_CLK11) +# define CONFIG_SYS_CMXFCR_MASK1 (CMXFCR_FC1|CMXFCR_RF1CS_MSK|CMXFCR_TF1CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE1 (CMXFCR_RF1CS_CLK12|CMXFCR_TF1CS_CLK11) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) @@ -166,8 +166,8 @@ * - RAM for BD/Buffers is on the 60x Bus (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC3|CMXFCR_RF3CS_MSK|CMXFCR_TF3CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF3CS_CLK15|CMXFCR_TF3CS_CLK16) +# define CONFIG_SYS_CMXFCR_MASK3 (CMXFCR_FC3|CMXFCR_RF3CS_MSK|CMXFCR_TF3CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE3 (CMXFCR_RF3CS_CLK15|CMXFCR_TF3CS_CLK16) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) diff --git a/include/configs/TQM8260.h b/include/configs/TQM8260.h index 36ecbd8b52..626cf19bd0 100644 --- a/include/configs/TQM8260.h +++ b/include/configs/TQM8260.h @@ -181,7 +181,7 @@ * - RX clk is CLK11 * - TX clk is CLK12 */ -# define CONFIG_SYS_CMXSCR_VALUE (CMXSCR_RS1CS_CLK11 | CMXSCR_TS1CS_CLK12) +# define CONFIG_SYS_CMXSCR_VALUE1 (CMXSCR_RS1CS_CLK11 | CMXSCR_TS1CS_CLK12) #elif defined(CONFIG_ETHER_ON_FCC) && (CONFIG_ETHER_INDEX == 2) @@ -191,8 +191,8 @@ * - RAM for BD/Buffers is on the 60x Bus (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) +# define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) diff --git a/include/configs/TQM8272.h b/include/configs/TQM8272.h index d1d9e8e68d..413ce640af 100644 --- a/include/configs/TQM8272.h +++ b/include/configs/TQM8272.h @@ -208,8 +208,8 @@ * - RAM for BD/Buffers is on the 60x Bus (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) +# define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) diff --git a/include/configs/ZPC1900.h b/include/configs/ZPC1900.h index 265b1112fe..4cda22fe4b 100644 --- a/include/configs/ZPC1900.h +++ b/include/configs/ZPC1900.h @@ -76,8 +76,8 @@ * - Select bus for bd/buffers (see 28-13) * - Full duplex */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) +# define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE | FCC_PSMR_LPB) diff --git a/include/configs/ca9x4_ct_vxp.h b/include/configs/ca9x4_ct_vxp.h index 2675c56b06..c5226ab143 100644 --- a/include/configs/ca9x4_ct_vxp.h +++ b/include/configs/ca9x4_ct_vxp.h @@ -69,6 +69,8 @@ /* Command line configuration */ #define CONFIG_CMD_BDI #define CONFIG_CMD_DHCP +#define CONFIG_CMD_PXE +#define CONFIG_MENU #define CONFIG_CMD_ELF #define CONFIG_CMD_ENV #define CONFIG_CMD_FLASH @@ -94,6 +96,9 @@ #define CONFIG_BOOTP_BOOTPATH #define CONFIG_BOOTP_GATEWAY #define CONFIG_BOOTP_HOSTNAME +#define CONFIG_BOOTP_PXE +#define CONFIG_BOOTP_PXE_CLIENTARCH 0x100 +#define CONFIG_BOOTP_VCI_STRING "U-boot.armv7.ca9x4_ct_vxp" /* Miscellaneous configurable options */ #undef CONFIG_SYS_CLKS_IN_HZ @@ -127,10 +132,12 @@ #define CONFIG_BOOTCOMMAND "run bootflash;" #define CONFIG_EXTRA_ENV_SETTINGS \ "loadaddr=0x80008000\0" \ - "initrd=0x61000000\0" \ - "kerneladdr=0x44100000\0" \ - "initrdaddr=0x44800000\0" \ - "maxinitrd=0x1800000\0" \ + "ramdisk_addr_r=0x61000000\0" \ + "kernel_addr=0x44100000\0" \ + "ramdisk_addr=0x44800000\0" \ + "maxramdisk=0x1800000\0" \ + "pxefile_addr_r=0x88000000\0" \ + "kernel_addr_r=0x80008000\0" \ "console=ttyAMA0,38400n8\0" \ "dram=1024M\0" \ "root=/dev/sda1 rw\0" \ @@ -140,8 +147,8 @@ "mem=${dram} mtdparts=${mtd} mmci.fmax=190000 " \ "devtmpfs.mount=0 vmalloc=256M\0" \ "bootflash=run flashargs; " \ - "cp ${initrdaddr} ${initrd} ${maxinitrd}; " \ - "bootm ${kerneladdr} ${initrd}\0" + "cp ${ramdisk_addr} ${ramdisk_addr_r} ${maxramdisk}; " \ + "bootm ${kernel_addr} ${ramdisk_addr_r}\0" /* FLASH and environment organization */ #define PHYS_FLASH_SIZE 0x04000000 /* 64MB */ diff --git a/include/configs/ep8260.h b/include/configs/ep8260.h index b15659d918..f19360d501 100644 --- a/include/configs/ep8260.h +++ b/include/configs/ep8260.h @@ -200,8 +200,8 @@ * - RAM for BD/Buffers is on the local Bus (see 28-13) * - Enable Half Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC3|CMXFCR_RF3CS_MSK|CMXFCR_TF3CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF3CS_CLK15|CMXFCR_TF3CS_CLK16) +# define CONFIG_SYS_CMXFCR_MASK3 (CMXFCR_FC3|CMXFCR_RF3CS_MSK|CMXFCR_TF3CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE3 (CMXFCR_RF3CS_CLK15|CMXFCR_TF3CS_CLK16) /* * - RAM for BD/Buffers is on the local Bus (see 28-13) diff --git a/include/configs/gw8260.h b/include/configs/gw8260.h index 93d688581f..2a40de1fae 100644 --- a/include/configs/gw8260.h +++ b/include/configs/gw8260.h @@ -240,8 +240,8 @@ * - Select bus for bd/buffers (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) +# define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE | FCC_PSMR_LPB) @@ -253,8 +253,8 @@ * - Select bus for bd/buffers (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC3|CMXFCR_RF3CS_MSK|CMXFCR_TF3CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF3CS_CLK15|CMXFCR_TF3CS_CLK16) +# define CONFIG_SYS_CMXFCR_MASK3 (CMXFCR_FC3|CMXFCR_RF3CS_MSK|CMXFCR_TF3CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE3 (CMXFCR_RF3CS_CLK15|CMXFCR_TF3CS_CLK16) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE | FCC_PSMR_LPB) diff --git a/include/configs/hymod.h b/include/configs/hymod.h index 7c4c2ba4ea..8c9f3d1f5a 100644 --- a/include/configs/hymod.h +++ b/include/configs/hymod.h @@ -89,8 +89,8 @@ * - RAM for BD/Buffers is on the 60x Bus (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC1|CMXFCR_RF1CS_MSK|CMXFCR_TF1CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF1CS_CLK10|CMXFCR_TF1CS_CLK11) +# define CONFIG_SYS_CMXFCR_MASK1 (CMXFCR_FC1|CMXFCR_RF1CS_MSK|CMXFCR_TF1CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE1 (CMXFCR_RF1CS_CLK10|CMXFCR_TF1CS_CLK11) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) @@ -110,8 +110,8 @@ * - RAM for BD/Buffers is on the 60x Bus (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) +# define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) @@ -131,8 +131,8 @@ * - RAM for BD/Buffers is on the 60x Bus (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC3|CMXFCR_RF3CS_MSK|CMXFCR_TF3CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF3CS_CLK15|CMXFCR_TF3CS_CLK16) +# define CONFIG_SYS_CMXFCR_MASK3 (CMXFCR_FC3|CMXFCR_RF3CS_MSK|CMXFCR_TF3CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE3 (CMXFCR_RF3CS_CLK15|CMXFCR_TF3CS_CLK16) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB) diff --git a/include/configs/muas3001.h b/include/configs/muas3001.h index 8b3022b2c0..18bd37e91c 100644 --- a/include/configs/muas3001.h +++ b/include/configs/muas3001.h @@ -83,8 +83,8 @@ * - Rx-CLK is CLK11 * - Tx-CLK is CLK12 */ -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF1CS_CLK11 | CMXFCR_TF1CS_CLK12) -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC1 | CMXFCR_RF1CS_MSK | CMXFCR_TF1CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE1 (CMXFCR_RF1CS_CLK11 | CMXFCR_TF1CS_CLK12) +# define CONFIG_SYS_CMXFCR_MASK1 (CMXFCR_FC1 | CMXFCR_RF1CS_MSK | CMXFCR_TF1CS_MSK) /* * - RAM for BD/Buffers is on the 60x Bus (see 28-13) */ diff --git a/include/configs/ppmc8260.h b/include/configs/ppmc8260.h index 68c62770f2..327863ec90 100644 --- a/include/configs/ppmc8260.h +++ b/include/configs/ppmc8260.h @@ -372,8 +372,8 @@ * - Select bus for bd/buffers (see 28-13) * - Enable Full Duplex in FSMR */ -#define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) -#define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) +#define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) +#define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) #define CONFIG_SYS_CPMFCR_RAMTYPE 0 #define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE | FCC_PSMR_LPB) #endif /* CONFIG_ETHER_INDEX */ diff --git a/include/configs/rsdproto.h b/include/configs/rsdproto.h index 2ed189ef67..3a700419f2 100644 --- a/include/configs/rsdproto.h +++ b/include/configs/rsdproto.h @@ -82,8 +82,8 @@ * - Select bus for bd/buffers (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) +# define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) # define CONFIG_SYS_CPMFCR_RAMTYPE (0) # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE | FCC_PSMR_LPB) diff --git a/include/configs/sacsng.h b/include/configs/sacsng.h index 914767ac1b..43036b2d3b 100644 --- a/include/configs/sacsng.h +++ b/include/configs/sacsng.h @@ -203,7 +203,7 @@ * - RX clk is CLK11 * - TX clk is CLK12 */ -# define CONFIG_SYS_CMXSCR_VALUE (CMXSCR_RS1CS_CLK11 | CMXSCR_TS1CS_CLK12) +# define CONFIG_SYS_CMXSCR_VALUE1 (CMXSCR_RS1CS_CLK11 | CMXSCR_TS1CS_CLK12) #elif defined(CONFIG_ETHER_ON_FCC) && (CONFIG_ETHER_INDEX == 2) @@ -213,8 +213,8 @@ * - Select bus for bd/buffers (see 28-13) * - Enable Full Duplex in FSMR */ -# define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) -# define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) +# define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2|CMXFCR_RF2CS_MSK|CMXFCR_TF2CS_MSK) +# define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14) # define CONFIG_SYS_CPMFCR_RAMTYPE 0 # define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE | FCC_PSMR_LPB) diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h new file mode 100644 index 0000000000..0230256478 --- /dev/null +++ b/include/configs/sandbox.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#ifndef __CONFIG_H +#define __CONFIG_H + +#define CONFIG_NR_DRAM_BANKS 1 +#define CONFIG_DRAM_SIZE (128 << 20) + +/* Number of bits in a C 'long' on this architecture */ +#define CONFIG_SANDBOX_BITS_PER_LONG 64 + +/* + * Size of malloc() pool, although we don't actually use this yet. + */ +#define CONFIG_SYS_MALLOC_LEN (4 << 20) /* 4MB */ + +#define CONFIG_SYS_PROMPT "=>" /* Command Prompt */ +#define CONFIG_SYS_HUSH_PARSER +#define CONFIG_SYS_PROMPT_HUSH_PS2 "> " +#define CONFIG_SYS_LONGHELP /* #undef to save memory */ +#define CONFIG_SYS_CBSIZE 1024 /* Console I/O Buffer Size */ + +/* Print Buffer Size */ +#define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + sizeof(CONFIG_SYS_PROMPT) + 16) +#define CONFIG_SYS_MAXARGS 16 + +/* turn on command-line edit/c/auto */ +#define CONFIG_CMDLINE_EDITING +#define CONFIG_COMMAND_HISTORY +#define CONFIG_AUTOCOMPLETE + +#define CONFIG_ENV_SIZE 8192 +#define CONFIG_ENV_IS_NOWHERE + +#define CONFIG_SYS_HZ 1000 + +/* Memory things - we don't really want a memory test */ +#define CONFIG_SYS_LOAD_ADDR 0x10000000 +#define CONFIG_SYS_MEMTEST_START 0x10000000 +#define CONFIG_SYS_MEMTEST_END (CONFIG_SYS_MEMTEST_START + 0x1000) +#define CONFIG_PHYS_64BIT + +/* Size of our emulated memory */ +#define CONFIG_SYS_SDRAM_SIZE (128 << 20) + +#define CONFIG_BAUDRATE 115200 +#define CONFIG_SYS_BAUDRATE_TABLE {4800, 9600, 19200, 38400, 57600,\ + 115200} +#define CONFIG_SANDBOX_SERIAL + +#define CONFIG_SYS_NO_FLASH + +/* include default commands */ +#include <config_cmd_default.h> + +/* We don't have networking support yet */ +#undef CONFIG_CMD_NET +#undef CONFIG_CMD_NFS + +#define CONFIG_BOOTARGS "" + +#define CONFIG_EXTRA_ENV_SETTINGS "stdin=serial\0" \ + "stdout=serial\0" \ + "stderr=serial\0" + +#endif diff --git a/include/configs/sbc8560.h b/include/configs/sbc8560.h index d2199257f8..f928622f27 100644 --- a/include/configs/sbc8560.h +++ b/include/configs/sbc8560.h @@ -260,8 +260,8 @@ * - Select bus for bd/buffers * - Full duplex */ - #define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) - #define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) + #define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) + #define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) #define CONFIG_SYS_CPMFCR_RAMTYPE 0 #define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE) diff --git a/include/configs/stxgp3.h b/include/configs/stxgp3.h index 90d249b964..6f611be900 100644 --- a/include/configs/stxgp3.h +++ b/include/configs/stxgp3.h @@ -255,8 +255,8 @@ * - Select bus for bd/buffers * - Full duplex */ - #define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) - #define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) + #define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) + #define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) #define CONFIG_SYS_CPMFCR_RAMTYPE 0 #if 0 #define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE) diff --git a/include/configs/stxssa.h b/include/configs/stxssa.h index 3d385b4253..50a615fc7a 100644 --- a/include/configs/stxssa.h +++ b/include/configs/stxssa.h @@ -285,8 +285,8 @@ * - Select bus for bd/buffers * - Full duplex */ - #define CONFIG_SYS_CMXFCR_MASK (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) - #define CONFIG_SYS_CMXFCR_VALUE (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) + #define CONFIG_SYS_CMXFCR_MASK2 (CMXFCR_FC2 | CMXFCR_RF2CS_MSK | CMXFCR_TF2CS_MSK) + #define CONFIG_SYS_CMXFCR_VALUE2 (CMXFCR_RF2CS_CLK13 | CMXFCR_TF2CS_CLK14) #define CONFIG_SYS_CPMFCR_RAMTYPE 0 #if 0 #define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE) diff --git a/include/hush.h b/include/hush.h index 5c566cc8da..ecf9222d27 100644 --- a/include/hush.h +++ b/include/hush.h @@ -29,7 +29,7 @@ #define FLAG_REPARSING (1 << 2) /* >=2nd pass */ extern int u_boot_hush_start(void); -extern int parse_string_outer(char *, int); +extern int parse_string_outer(const char *, int); extern int parse_file_outer(void); int set_local_var(const char *s, int flg_export); diff --git a/include/image.h b/include/image.h index cca1cc533c..b7caaa625a 100644 --- a/include/image.h +++ b/include/image.h @@ -106,6 +106,7 @@ #define IH_ARCH_BLACKFIN 16 /* Blackfin */ #define IH_ARCH_AVR32 17 /* AVR32 */ #define IH_ARCH_ST200 18 /* STMicroelectronics ST200 */ +#define IH_ARCH_SANDBOX 19 /* Sandbox architecture (test only) */ /* * Image Types diff --git a/include/linux/ctype.h b/include/linux/ctype.h index 6dec944a37..42f9305a02 100644 --- a/include/linux/ctype.h +++ b/include/linux/ctype.h @@ -31,6 +31,12 @@ extern const unsigned char _ctype[]; #define isupper(c) ((__ismask(c)&(_U)) != 0) #define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0) +/* + * Rather than doubling the size of the _ctype lookup table to hold a 'blank' + * flag, just check for space or tab. + */ +#define isblank(c) (c == ' ' || c == '\t') + #define isascii(c) (((unsigned char)(c))<=0x7f) #define toascii(c) (((unsigned char)(c))&0x7f) diff --git a/include/menu.h b/include/menu.h new file mode 100644 index 0000000000..cf14a9cca3 --- /dev/null +++ b/include/menu.h @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2011 Calxeda, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __MENU_H__ +#define __MENU_H__ + +struct menu; + +struct menu *menu_create(char *title, int timeout, int prompt, + void (*item_data_print)(void *)); +int menu_default_set(struct menu *m, char *item_key); +int menu_get_choice(struct menu *m, void **choice); +int menu_item_add(struct menu *m, char *item_key, void *item_data); +int menu_destroy(struct menu *m); + +#endif /* __MENU_H__ */ diff --git a/include/os.h b/include/os.h new file mode 100644 index 0000000000..3ea6d2ddee --- /dev/null +++ b/include/os.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +/* + * Operating System Interface + * + * This provides access to useful OS routines from the sandbox architecture + */ + +/** + * Access to the OS read() system call + * + * \param fd File descriptor as returned by os_open() + * \param buf Buffer to place data + * \param count Number of bytes to read + * \return number of bytes read, or -1 on error + */ +ssize_t os_read(int fd, void *buf, size_t count); + +/** + * Access to the OS write() system call + * + * \param fd File descriptor as returned by os_open() + * \param buf Buffer containing data to write + * \param count Number of bytes to write + * \return number of bytes written, or -1 on error + */ +ssize_t os_write(int fd, const void *buf, size_t count); + +/** + * Access to the OS open() system call + * + * \param pathname Pathname of file to open + * \param flags Flags, like O_RDONLY, O_RDWR + * \return file descriptor, or -1 on error + */ +int os_open(const char *pathname, int flags); + +/** + * Access to the OS close() system call + * + * \param fd File descriptor to close + * \return 0 on success, -1 on error + */ +int os_close(int fd); + +/** + * Access to the OS exit() system call + * + * This exits with the supplied return code, which should be 0 to indicate + * success. + * + * @param exit_code exit code for U-Boot + */ +void os_exit(int exit_code); diff --git a/include/timestamp.h b/include/timestamp.h index b2f4cf4d7b..05a6658573 100644 --- a/include/timestamp.h +++ b/include/timestamp.h @@ -24,7 +24,7 @@ #define __TIMESTAMP_H__ #ifndef DO_DEPS_ONLY -#include "timestamp_autogenerated.h" +#include "generated/timestamp_autogenerated.h" #endif #endif /* __TIMESTAMP_H__ */ diff --git a/include/version.h b/include/version.h index 129acef0b8..c908bd3013 100644 --- a/include/version.h +++ b/include/version.h @@ -27,7 +27,7 @@ #include <timestamp.h> #ifndef DO_DEPS_ONLY -#include "version_autogenerated.h" +#include "generated/version_autogenerated.h" #endif #ifndef CONFIG_IDENT_STRING diff --git a/lib/Makefile b/lib/Makefile index 884f64c00a..075bb8c284 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -55,6 +55,7 @@ COBJS-y += ctype.o COBJS-y += div64.o COBJS-y += string.o COBJS-y += time.o +COBJS-$(CONFIG_BOOTP_PXE) += uuid.o COBJS-y += vsprintf.o COBJS := $(COBJS-y) diff --git a/lib/hashtable.c b/lib/hashtable.c index 026dbca2fa..6895550d3c 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -32,6 +32,7 @@ #ifdef USE_HOSTCC /* HOST build */ # include <string.h> # include <assert.h> +# include <ctype.h> # ifndef debug # ifdef DEBUG @@ -43,6 +44,7 @@ #else /* U-Boot build */ # include <common.h> # include <linux/string.h> +# include <linux/ctype.h> #endif #ifndef CONFIG_ENV_MIN_ENTRIES /* minimum number of entries */ @@ -690,7 +692,7 @@ int himport_r(struct hsearch_data *htab, ENTRY e, *rv; /* skip leading white space */ - while ((*dp == ' ') || (*dp == '\t')) + while (isblank(*dp)) ++dp; /* skip comment lines */ diff --git a/lib/uuid.c b/lib/uuid.c new file mode 100644 index 0000000000..10b022fcb8 --- /dev/null +++ b/lib/uuid.c @@ -0,0 +1,85 @@ +/* + * Copyright 2011 Calxeda, Inc. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <linux/ctype.h> +#include "common.h" + +/* + * This is what a UUID string looks like. + * + * x is a hexadecimal character. fields are separated by '-'s. When converting + * to a binary UUID, le means the field should be converted to little endian, + * and be means it should be converted to big endian. + * + * 0 9 14 19 24 + * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + * le le le be be + */ + +int uuid_str_valid(const char *uuid) +{ + int i, valid; + + if (uuid == NULL) + return 0; + + for (i = 0, valid = 1; uuid[i] && valid; i++) { + switch (i) { + case 8: case 13: case 18: case 23: + valid = (uuid[i] == '-'); + break; + default: + valid = isxdigit(uuid[i]); + break; + } + } + + if (i != 36 || !valid) + return 0; + + return 1; +} + +void uuid_str_to_bin(const char *uuid, unsigned char *out) +{ + uint16_t tmp16; + uint32_t tmp32; + uint64_t tmp64; + + if (!uuid || !out) + return; + + tmp32 = cpu_to_le32(simple_strtoul(uuid, NULL, 16)); + memcpy(out, &tmp32, 4); + + tmp16 = cpu_to_le16(simple_strtoul(uuid + 9, NULL, 16)); + memcpy(out + 4, &tmp16, 2); + + tmp16 = cpu_to_le16(simple_strtoul(uuid + 14, NULL, 16)); + memcpy(out + 6, &tmp16, 2); + + tmp16 = cpu_to_be16(simple_strtoul(uuid + 19, NULL, 16)); + memcpy(out + 8, &tmp16, 2); + + tmp64 = cpu_to_be64(simple_strtoull(uuid + 24, NULL, 16)); + memcpy(out + 10, (char *)&tmp64 + 2, 6); +} diff --git a/net/bootp.c b/net/bootp.c index a003c422bd..73470f2d46 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -381,6 +381,11 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R { u8 *start = e; u8 *cnt; +#if defined(CONFIG_BOOTP_PXE) + char *uuid; + size_t vci_strlen; + u16 clientarch; +#endif #if defined(CONFIG_BOOTP_VENDOREX) u8 *x; @@ -435,6 +440,41 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R } #endif +#if defined(CONFIG_BOOTP_PXE) + clientarch = CONFIG_BOOTP_PXE_CLIENTARCH; + *e++ = 93; /* Client System Architecture */ + *e++ = 2; + *e++ = (clientarch >> 8) & 0xff; + *e++ = clientarch & 0xff; + + *e++ = 94; /* Client Network Interface Identifier */ + *e++ = 3; + *e++ = 1; /* type field for UNDI */ + *e++ = 0; /* major revision */ + *e++ = 0; /* minor revision */ + + uuid = getenv("pxeuuid"); + + if (uuid) { + if (uuid_str_valid(uuid)) { + *e++ = 97; /* Client Machine Identifier */ + *e++ = 17; + *e++ = 0; /* type 0 - UUID */ + + uuid_str_to_bin(uuid, e); + e += 16; + } else { + printf("Invalid pxeuuid: %s\n", uuid); + } + } + + *e++ = 60; /* Vendor Class Identifier */ + vci_strlen = strlen(CONFIG_BOOTP_VCI_STRING); + *e++ = vci_strlen; + memcpy(e, CONFIG_BOOTP_VCI_STRING, vci_strlen); + e += vci_strlen; +#endif + #if defined(CONFIG_BOOTP_VENDOREX) if ((x = dhcp_vendorex_prep (e))) return x - start; @@ -25,17 +25,40 @@ _depend: $(obj).depend -$(obj).depend: $(src)Makefile $(TOPDIR)/config.mk $(SRCS) $(HOSTSRCS) - @rm -f $@ - @touch $@ - @for f in $(SRCS); do \ - g=`basename $$f | sed -e 's/\(.*\)\.[[:alnum:]_]/\1.o/'`; \ - $(CC) -M $(CPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \ - done - @for f in $(HOSTSRCS); do \ - g=`basename $$f | sed -e 's/\(.*\)\.[[:alnum:]_]/\1.o/'`; \ - $(HOSTCC) -M $(HOSTCPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \ - done +# Split the source files into two camps: those in the current directory, and +# those somewhere else. For the first camp we want to support CPPFLAGS_<fname> +# and for the second we don't / can't. +PWD_SRCS := $(filter $(notdir $(SRCS)),$(SRCS)) +OTHER_SRCS := $(filter-out $(notdir $(SRCS)),$(SRCS)) + +# This is a list of dependency files to generate +DEPS := $(basename $(patsubst %,$(obj).depend.%,$(PWD_SRCS))) + +# Join all the dependencies into a single file, in three parts +# 1 .Concatenate all the generated depend files together +# 2. Add in the deps from OTHER_SRCS which we couldn't process +# 3. Add in the HOSTSRCS +$(obj).depend: $(src)Makefile $(TOPDIR)/config.mk $(DEPS) $(OTHER_SRCS) \ + $(HOSTSRCS) + cat /dev/null $(DEPS) >$@ + @for f in $(OTHER_SRCS); do \ + g=`basename $$f | sed -e 's/\(.*\)\.[[:alnum:]_]/\1.o/'`; \ + $(CC) -M $(CPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \ + done + @for f in $(HOSTSRCS); do \ + g=`basename $$f | sed -e 's/\(.*\)\.[[:alnum:]_]/\1.o/'`; \ + $(HOSTCC) -M $(HOSTCPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \ + done + +MAKE_DEPEND = $(CC) -M $(CPPFLAGS) $(EXTRA_CPPFLAGS_DEP) \ + -MQ $(addsuffix .o,$(obj)$(basename $<)) $< >$@ + + +$(obj).depend.%: %.c + $(MAKE_DEPEND) + +$(obj).depend.%: %.S + $(MAKE_DEPEND) $(HOSTOBJS): $(obj)%.o: %.c $(HOSTCC) $(HOSTCFLAGS) $(HOSTCFLAGS_$(@F)) $(HOSTCFLAGS_$(BCURDIR)) -o $@ $< -c |