summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/Makefile8
-rw-r--r--common/cmd_bdinfo.c10
-rw-r--r--common/cmd_disk.c144
-rw-r--r--common/cmd_ext2.c219
-rw-r--r--common/cmd_ext4.c145
-rw-r--r--common/cmd_ext_common.c197
-rw-r--r--common/cmd_fat.c100
-rw-r--r--common/cmd_fdt.c13
-rw-r--r--common/cmd_ide.c151
-rw-r--r--common/cmd_mmc.c3
-rw-r--r--common/cmd_nand.c25
-rw-r--r--common/cmd_nvedit.c194
-rw-r--r--common/cmd_part.c105
-rw-r--r--common/cmd_reiser.c81
-rw-r--r--common/cmd_scsi.c123
-rw-r--r--common/cmd_usb.c138
-rw-r--r--common/cmd_zfs.c88
-rw-r--r--common/dlmalloc.c10
-rw-r--r--common/env_common.c39
-rw-r--r--common/env_mmc.c64
-rw-r--r--common/env_nand.c2
-rw-r--r--common/env_remote.c4
-rw-r--r--common/image.c1
-rw-r--r--common/usb_hub.c14
24 files changed, 971 insertions, 907 deletions
diff --git a/common/Makefile b/common/Makefile
index 57da76f..b56df1d 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -34,6 +34,7 @@ COBJS-$(CONFIG_SYS_HUSH_PARSER) += hush.o
COBJS-y += s_record.o
COBJS-$(CONFIG_SERIAL_MULTI) += serial.o
COBJS-y += xyzModem.o
+COBJS-y += cmd_disk.o
# core command
COBJS-y += cmd_boot.o
@@ -86,7 +87,13 @@ COBJS-$(CONFIG_ENV_IS_IN_EEPROM) += cmd_eeprom.o
COBJS-$(CONFIG_CMD_EEPROM) += cmd_eeprom.o
COBJS-$(CONFIG_CMD_ELF) += cmd_elf.o
COBJS-$(CONFIG_SYS_HUSH_PARSER) += cmd_exit.o
+COBJS-$(CONFIG_CMD_EXT4) += cmd_ext4.o
COBJS-$(CONFIG_CMD_EXT2) += cmd_ext2.o
+ifdef CONFIG_CMD_EXT4
+COBJS-y += cmd_ext_common.o
+else
+COBJS-$(CONFIG_CMD_EXT2) += cmd_ext_common.o
+endif
COBJS-$(CONFIG_CMD_FAT) += cmd_fat.o
COBJS-$(CONFIG_CMD_FDC)$(CONFIG_CMD_FDOS) += cmd_fdc.o
COBJS-$(CONFIG_OF_LIBFDT) += cmd_fdt.o fdt_support.o
@@ -129,6 +136,7 @@ COBJS-$(CONFIG_CMD_NAND) += cmd_nand.o
COBJS-$(CONFIG_CMD_NET) += cmd_net.o
COBJS-$(CONFIG_CMD_ONENAND) += cmd_onenand.o
COBJS-$(CONFIG_CMD_OTP) += cmd_otp.o
+COBJS-$(CONFIG_CMD_PART) += cmd_part.o
ifdef CONFIG_PCI
COBJS-$(CONFIG_CMD_PCI) += cmd_pci.o
endif
diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c
index 42f08fd..23bd8a5 100644
--- a/common/cmd_bdinfo.c
+++ b/common/cmd_bdinfo.c
@@ -216,15 +216,15 @@ int do_bdinfo(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
print_num("flashstart ", bd->bi_flashstart);
print_num("CONFIG_SYS_MONITOR_BASE ", CONFIG_SYS_MONITOR_BASE);
print_num("CONFIG_ENV_ADDR ", CONFIG_ENV_ADDR);
- printf("CONFIG_SYS_RELOC_MONITOR_BASE = 0x%lx (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE,
+ printf("CONFIG_SYS_RELOC_MONITOR_BASE = 0x%x (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE,
CONFIG_SYS_MONITOR_LEN);
- printf("CONFIG_SYS_MALLOC_BASE = 0x%lx (%d)\n", CONFIG_SYS_MALLOC_BASE,
+ printf("CONFIG_SYS_MALLOC_BASE = 0x%x (%d)\n", CONFIG_SYS_MALLOC_BASE,
CONFIG_SYS_MALLOC_LEN);
- printf("CONFIG_SYS_INIT_SP_OFFSET = 0x%lx (%d)\n", CONFIG_SYS_INIT_SP_OFFSET,
+ printf("CONFIG_SYS_INIT_SP_OFFSET = 0x%x (%d)\n", CONFIG_SYS_INIT_SP_OFFSET,
CONFIG_SYS_STACK_SIZE);
- printf("CONFIG_SYS_PROM_OFFSET = 0x%lx (%d)\n", CONFIG_SYS_PROM_OFFSET,
+ printf("CONFIG_SYS_PROM_OFFSET = 0x%x (%d)\n", CONFIG_SYS_PROM_OFFSET,
CONFIG_SYS_PROM_SIZE);
- printf("CONFIG_SYS_GBL_DATA_OFFSET = 0x%lx (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET,
+ printf("CONFIG_SYS_GBL_DATA_OFFSET = 0x%x (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET,
GENERATED_GBL_DATA_SIZE);
#if defined(CONFIG_CMD_NET)
diff --git a/common/cmd_disk.c b/common/cmd_disk.c
new file mode 100644
index 0000000..ee4e215
--- /dev/null
+++ b/common/cmd_disk.c
@@ -0,0 +1,144 @@
+/*
+ * (C) Copyright 2000-2011
+ * 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 <common.h>
+#include <command.h>
+#include <part.h>
+
+#if defined(CONFIG_CMD_IDE) || defined(CONFIG_CMD_SCSI) || \
+ defined(CONFIG_USB_STORAGE)
+int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
+ char *const argv[])
+{
+ int dev, part;
+ ulong addr = CONFIG_SYS_LOAD_ADDR;
+ ulong cnt;
+ disk_partition_t info;
+ image_header_t *hdr;
+ block_dev_desc_t *dev_desc;
+
+#if defined(CONFIG_FIT)
+ const void *fit_hdr = NULL;
+#endif
+
+ bootstage_mark(BOOTSTAGE_ID_IDE_START);
+ if (argc > 3) {
+ bootstage_error(BOOTSTAGE_ID_IDE_ADDR);
+ return CMD_RET_USAGE;
+ }
+ bootstage_mark(BOOTSTAGE_ID_IDE_ADDR);
+
+ if (argc > 1)
+ addr = simple_strtoul(argv[1], NULL, 16);
+
+ bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
+
+ part = get_device_and_partition(intf, (argc == 3) ? argv[2] : NULL,
+ &dev_desc, &info, 1);
+ if (part < 0) {
+ bootstage_error(BOOTSTAGE_ID_IDE_TYPE);
+ return 1;
+ }
+
+ dev = dev_desc->dev;
+ bootstage_mark(BOOTSTAGE_ID_IDE_TYPE);
+
+ printf("\nLoading from %s device %d, partition %d: "
+ "Name: %.32s Type: %.32s\n", intf, dev, part, info.name,
+ info.type);
+
+ debug("First Block: %ld, # of blocks: %ld, Block Size: %ld\n",
+ info.start, info.size, info.blksz);
+
+ if (dev_desc->block_read(dev, info.start, 1, (ulong *) addr) != 1) {
+ printf("** Read error on %d:%d\n", dev, part);
+ bootstage_error(BOOTSTAGE_ID_IDE_PART_READ);
+ return 1;
+ }
+ bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ);
+
+ switch (genimg_get_format((void *) addr)) {
+ case IMAGE_FORMAT_LEGACY:
+ hdr = (image_header_t *) addr;
+
+ bootstage_mark(BOOTSTAGE_ID_IDE_FORMAT);
+
+ if (!image_check_hcrc(hdr)) {
+ puts("\n** Bad Header Checksum **\n");
+ bootstage_error(BOOTSTAGE_ID_IDE_CHECKSUM);
+ return 1;
+ }
+ bootstage_mark(BOOTSTAGE_ID_IDE_CHECKSUM);
+
+ image_print_contents(hdr);
+
+ cnt = image_get_image_size(hdr);
+ break;
+#if defined(CONFIG_FIT)
+ case IMAGE_FORMAT_FIT:
+ fit_hdr = (const void *) addr;
+ puts("Fit image detected...\n");
+
+ cnt = fit_get_size(fit_hdr);
+ break;
+#endif
+ default:
+ bootstage_error(BOOTSTAGE_ID_IDE_FORMAT);
+ puts("** Unknown image type\n");
+ return 1;
+ }
+
+ cnt += info.blksz - 1;
+ cnt /= info.blksz;
+ cnt -= 1;
+
+ if (dev_desc->block_read(dev, info.start + 1, cnt,
+ (ulong *)(addr + info.blksz)) != cnt) {
+ printf("** Read error on %d:%d\n", dev, part);
+ bootstage_error(BOOTSTAGE_ID_IDE_READ);
+ return 1;
+ }
+ bootstage_mark(BOOTSTAGE_ID_IDE_READ);
+
+#if defined(CONFIG_FIT)
+ /* This cannot be done earlier,
+ * we need complete FIT image in RAM first */
+ if (genimg_get_format((void *) addr) == IMAGE_FORMAT_FIT) {
+ if (!fit_check_format(fit_hdr)) {
+ bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ);
+ puts("** Bad FIT image format\n");
+ return 1;
+ }
+ bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK);
+ fit_print_contents(fit_hdr);
+ }
+#endif
+
+ flush_cache(addr, (cnt+1)*info.blksz);
+
+ /* Loading ok, update default load address */
+ load_addr = addr;
+
+ return bootm_maybe_autostart(cmdtp, argv[0]);
+}
+#endif
diff --git a/common/cmd_ext2.c b/common/cmd_ext2.c
index 79b1e2f..c27d9c7 100644
--- a/common/cmd_ext2.c
+++ b/common/cmd_ext2.c
@@ -1,4 +1,9 @@
/*
+ * (C) Copyright 2011 - 2012 Samsung Electronics
+ * EXT4 filesystem implementation in Uboot by
+ * Uma Shankar <uma.shankar@samsung.com>
+ * Manjunatha C Achar <a.manjunatha@samsung.com>
+
* (C) Copyright 2004
* esd gmbh <www.esd-electronics.com>
* Reinhard Arlt <reinhard.arlt@esd-electronics.com>
@@ -33,225 +38,35 @@
* Ext2fs support
*/
#include <common.h>
-#include <part.h>
-#include <config.h>
-#include <command.h>
-#include <image.h>
-#include <linux/ctype.h>
-#include <asm/byteorder.h>
-#include <ext2fs.h>
-#if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
-#include <usb.h>
-#endif
-
-#if !defined(CONFIG_DOS_PARTITION) && !defined(CONFIG_EFI_PARTITION)
-#error DOS or EFI partition support must be selected
-#endif
-
-/* #define EXT2_DEBUG */
-
-#ifdef EXT2_DEBUG
-#define PRINTF(fmt,args...) printf (fmt ,##args)
-#else
-#define PRINTF(fmt,args...)
-#endif
+#include <ext_common.h>
int do_ext2ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- char *filename = "/";
- int dev=0;
- int part=1;
- char *ep;
- block_dev_desc_t *dev_desc=NULL;
- int part_length;
-
- if (argc < 3)
- return CMD_RET_USAGE;
-
- dev = (int)simple_strtoul (argv[2], &ep, 16);
- dev_desc = get_dev(argv[1],dev);
-
- if (dev_desc == NULL) {
- printf ("\n** Block device %s %d not supported\n", argv[1], dev);
- return 1;
- }
-
- if (*ep) {
- if (*ep != ':') {
- puts ("\n** Invalid boot device, use `dev[:part]' **\n");
- return 1;
- }
- part = (int)simple_strtoul(++ep, NULL, 16);
- }
-
- if (argc == 4)
- filename = argv[3];
-
- PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
-
- if ((part_length = ext2fs_set_blk_dev(dev_desc, part)) == 0) {
- printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
- ext2fs_close();
- return 1;
- }
-
- if (!ext2fs_mount(part_length)) {
- printf ("** Bad ext2 partition or disk - %s %d:%d **\n", argv[1], dev, part);
- ext2fs_close();
- return 1;
- }
-
- if (ext2fs_ls (filename)) {
- printf ("** Error ext2fs_ls() **\n");
- ext2fs_close();
- return 1;
- };
-
- ext2fs_close();
+ if (do_ext_ls(cmdtp, flag, argc, argv))
+ return -1;
return 0;
}
-U_BOOT_CMD(
- ext2ls, 4, 1, do_ext2ls,
- "list files in a directory (default /)",
- "<interface> <dev[:part]> [directory]\n"
- " - list files from 'dev' on 'interface' in a 'directory'"
-);
-
/******************************************************************************
* Ext2fs boot command intepreter. Derived from diskboot
*/
int do_ext2load (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- char *filename = NULL;
- char *ep;
- int dev, part = 1;
- ulong addr = 0, part_length;
- int filelen;
- disk_partition_t info;
- block_dev_desc_t *dev_desc = NULL;
- char buf [12];
- unsigned long count;
- char *addr_str;
-
- switch (argc) {
- case 3:
- addr_str = getenv("loadaddr");
- if (addr_str != NULL)
- addr = simple_strtoul (addr_str, NULL, 16);
- else
- addr = CONFIG_SYS_LOAD_ADDR;
-
- filename = getenv ("bootfile");
- count = 0;
- break;
- case 4:
- addr = simple_strtoul (argv[3], NULL, 16);
- filename = getenv ("bootfile");
- count = 0;
- break;
- case 5:
- addr = simple_strtoul (argv[3], NULL, 16);
- filename = argv[4];
- count = 0;
- break;
- case 6:
- addr = simple_strtoul (argv[3], NULL, 16);
- filename = argv[4];
- count = simple_strtoul (argv[5], NULL, 16);
- break;
-
- default:
- return CMD_RET_USAGE;
- }
-
- if (!filename) {
- puts ("** No boot file defined **\n");
- return 1;
- }
-
- dev = (int)simple_strtoul (argv[2], &ep, 16);
- dev_desc = get_dev(argv[1],dev);
- if (dev_desc==NULL) {
- printf ("** Block device %s %d not supported\n", argv[1], dev);
- return 1;
- }
- if (*ep) {
- if (*ep != ':') {
- puts ("** Invalid boot device, use `dev[:part]' **\n");
- return 1;
- }
- part = (int)simple_strtoul(++ep, NULL, 16);
- }
-
- PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part);
-
- if (part != 0) {
- if (get_partition_info (dev_desc, part, &info)) {
- printf ("** Bad partition %d **\n", part);
- return 1;
- }
-
- if (strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
- printf ("** Invalid partition type \"%.32s\""
- " (expect \"" BOOT_PART_TYPE "\")\n",
- info.type);
- return 1;
- }
- printf ("Loading file \"%s\" "
- "from %s device %d:%d (%.32s)\n",
- filename,
- argv[1], dev, part, info.name);
- } else {
- printf ("Loading file \"%s\" from %s device %d\n",
- filename, argv[1], dev);
- }
-
-
- if ((part_length = ext2fs_set_blk_dev(dev_desc, part)) == 0) {
- printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
- ext2fs_close();
- return 1;
- }
-
- if (!ext2fs_mount(part_length)) {
- printf ("** Bad ext2 partition or disk - %s %d:%d **\n",
- argv[1], dev, part);
- ext2fs_close();
- return 1;
- }
-
- filelen = ext2fs_open(filename);
- if (filelen < 0) {
- printf("** File not found %s\n", filename);
- ext2fs_close();
- return 1;
- }
- if ((count < filelen) && (count != 0)) {
- filelen = count;
- }
-
- if (ext2fs_read((char *)addr, filelen) != filelen) {
- printf("** Unable to read \"%s\" from %s %d:%d **\n",
- filename, argv[1], dev, part);
- ext2fs_close();
- return 1;
- }
-
- ext2fs_close();
-
- /* Loading ok, update default load address */
- load_addr = addr;
-
- printf ("%d bytes read\n", filelen);
- sprintf(buf, "%X", filelen);
- setenv("filesize", buf);
+ if (do_ext_load(cmdtp, flag, argc, argv))
+ return -1;
return 0;
}
U_BOOT_CMD(
+ ext2ls, 4, 1, do_ext2ls,
+ "list files in a directory (default /)",
+ "<interface> <dev[:part]> [directory]\n"
+ " - list files from 'dev' on 'interface' in a 'directory'"
+);
+
+U_BOOT_CMD(
ext2load, 6, 0, do_ext2load,
"load binary file from a Ext2 filesystem",
"<interface> <dev[:part]> [addr] [filename] [bytes]\n"
diff --git a/common/cmd_ext4.c b/common/cmd_ext4.c
new file mode 100644
index 0000000..ca46561
--- /dev/null
+++ b/common/cmd_ext4.c
@@ -0,0 +1,145 @@
+/*
+ * (C) Copyright 2011 - 2012 Samsung Electronics
+ * EXT4 filesystem implementation in Uboot by
+ * Uma Shankar <uma.shankar@samsung.com>
+ * Manjunatha C Achar <a.manjunatha@samsung.com>
+ *
+ * Ext4fs support
+ * made from existing cmd_ext2.c file of Uboot
+ *
+ * (C) Copyright 2004
+ * esd gmbh <www.esd-electronics.com>
+ * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
+ *
+ * made from cmd_reiserfs by
+ *
+ * (C) Copyright 2003 - 2004
+ * Sysgo Real-Time Solutions, AG <www.elinos.com>
+ * Pavel Bartusek <pba@sysgo.com>
+ *
+ * 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
+ *
+ */
+
+/*
+ * Changelog:
+ * 0.1 - Newly created file for ext4fs support. Taken from cmd_ext2.c
+ * file in uboot. Added ext4fs ls load and write support.
+ */
+
+#include <common.h>
+#include <part.h>
+#include <config.h>
+#include <command.h>
+#include <image.h>
+#include <linux/ctype.h>
+#include <asm/byteorder.h>
+#include <ext_common.h>
+#include <ext4fs.h>
+#include <linux/stat.h>
+#include <malloc.h>
+
+#if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
+#include <usb.h>
+#endif
+
+int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ if (do_ext_load(cmdtp, flag, argc, argv))
+ return -1;
+
+ return 0;
+}
+
+int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+ if (do_ext_ls(cmdtp, flag, argc, argv))
+ return -1;
+
+ return 0;
+}
+
+#if defined(CONFIG_CMD_EXT4_WRITE)
+int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ const char *filename = "/";
+ int dev, part;
+ unsigned long ram_address;
+ unsigned long file_size;
+ disk_partition_t info;
+ block_dev_desc_t *dev_desc;
+
+ if (argc < 6)
+ return cmd_usage(cmdtp);
+
+ part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ if (part < 0)
+ return 1;
+
+ dev = dev_desc->dev;
+
+ /* get the filename */
+ filename = argv[3];
+
+ /* get the address in hexadecimal format (string to int) */
+ ram_address = simple_strtoul(argv[4], NULL, 16);
+
+ /* get the filesize in base 10 format */
+ file_size = simple_strtoul(argv[5], NULL, 10);
+
+ /* set the device as block device */
+ ext4fs_set_blk_dev(dev_desc, &info);
+
+ /* mount the filesystem */
+ if (!ext4fs_mount(info.size)) {
+ printf("Bad ext4 partition %s %d:%lu\n", argv[1], dev, part);
+ goto fail;
+ }
+
+ /* start write */
+ if (ext4fs_write(filename, (unsigned char *)ram_address, file_size)) {
+ printf("** Error ext4fs_write() **\n");
+ goto fail;
+ }
+ ext4fs_close();
+
+ return 0;
+
+fail:
+ ext4fs_close();
+
+ return 1;
+}
+
+U_BOOT_CMD(ext4write, 6, 1, do_ext4_write,
+ "create a file in the root directory",
+ "<interface> <dev[:part]> [Absolute filename path] [Address] [sizebytes]\n"
+ " - create a file in / directory");
+
+#endif
+
+U_BOOT_CMD(ext4ls, 4, 1, do_ext4_ls,
+ "list files in a directory (default /)",
+ "<interface> <dev[:part]> [directory]\n"
+ " - list files from 'dev' on 'interface' in a 'directory'");
+
+U_BOOT_CMD(ext4load, 6, 0, do_ext4_load,
+ "load binary file from a Ext4 filesystem",
+ "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
+ " - load binary file 'filename' from 'dev' on 'interface'\n"
+ " to address 'addr' from ext4 filesystem");
diff --git a/common/cmd_ext_common.c b/common/cmd_ext_common.c
new file mode 100644
index 0000000..1952f4d
--- /dev/null
+++ b/common/cmd_ext_common.c
@@ -0,0 +1,197 @@
+/*
+ * (C) Copyright 2011 - 2012 Samsung Electronics
+ * EXT2/4 filesystem implementation in Uboot by
+ * Uma Shankar <uma.shankar@samsung.com>
+ * Manjunatha C Achar <a.manjunatha@samsung.com>
+ *
+ * Ext4fs support
+ * made from existing cmd_ext2.c file of Uboot
+ *
+ * (C) Copyright 2004
+ * esd gmbh <www.esd-electronics.com>
+ * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
+ *
+ * made from cmd_reiserfs by
+ *
+ * (C) Copyright 2003 - 2004
+ * Sysgo Real-Time Solutions, AG <www.elinos.com>
+ * Pavel Bartusek <pba@sysgo.com>
+ *
+ * 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
+ *
+ */
+
+/*
+ * Changelog:
+ * 0.1 - Newly created file for ext4fs support. Taken from cmd_ext2.c
+ * file in uboot. Added ext4fs ls load and write support.
+ */
+
+#include <common.h>
+#include <part.h>
+#include <config.h>
+#include <command.h>
+#include <image.h>
+#include <linux/ctype.h>
+#include <asm/byteorder.h>
+#include <ext_common.h>
+#include <ext4fs.h>
+#include <linux/stat.h>
+#include <malloc.h>
+
+#if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
+#include <usb.h>
+#endif
+
+#if !defined(CONFIG_DOS_PARTITION) && !defined(CONFIG_EFI_PARTITION)
+#error DOS or EFI partition support must be selected
+#endif
+
+#define DOS_PART_MAGIC_OFFSET 0x1fe
+#define DOS_FS_TYPE_OFFSET 0x36
+#define DOS_FS32_TYPE_OFFSET 0x52
+
+int do_ext_load(cmd_tbl_t *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ char *filename = NULL;
+ int dev, part;
+ ulong addr = 0;
+ int filelen;
+ disk_partition_t info;
+ block_dev_desc_t *dev_desc;
+ char buf[12];
+ unsigned long count;
+ const char *addr_str;
+
+ count = 0;
+ addr = simple_strtoul(argv[3], NULL, 16);
+ filename = getenv("bootfile");
+ switch (argc) {
+ case 3:
+ addr_str = getenv("loadaddr");
+ if (addr_str != NULL)
+ addr = simple_strtoul(addr_str, NULL, 16);
+ else
+ addr = CONFIG_SYS_LOAD_ADDR;
+
+ break;
+ case 4:
+ break;
+ case 5:
+ filename = argv[4];
+ break;
+ case 6:
+ filename = argv[4];
+ count = simple_strtoul(argv[5], NULL, 16);
+ break;
+
+ default:
+ return cmd_usage(cmdtp);
+ }
+
+ if (!filename) {
+ puts("** No boot file defined **\n");
+ return 1;
+ }
+
+ part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ if (part < 0)
+ return 1;
+
+ dev = dev_desc->dev;
+ printf("Loading file \"%s\" from %s device %d%c%c\n",
+ filename, argv[1], dev,
+ part ? ':' : ' ', part ? part + '0' : ' ');
+
+ ext4fs_set_blk_dev(dev_desc, &info);
+
+ if (!ext4fs_mount(info.size)) {
+ printf("** Bad ext2 partition or disk - %s %d:%d **\n",
+ argv[1], dev, part);
+ ext4fs_close();
+ goto fail;
+ }
+
+ filelen = ext4fs_open(filename);
+ if (filelen < 0) {
+ printf("** File not found %s\n", filename);
+ ext4fs_close();
+ goto fail;
+ }
+ if ((count < filelen) && (count != 0))
+ filelen = count;
+
+ if (ext4fs_read((char *)addr, filelen) != filelen) {
+ printf("** Unable to read \"%s\" from %s %d:%d **\n",
+ filename, argv[1], dev, part);
+ ext4fs_close();
+ goto fail;
+ }
+
+ ext4fs_close();
+ /* Loading ok, update default load address */
+ load_addr = addr;
+
+ printf("%d bytes read\n", filelen);
+ sprintf(buf, "%X", filelen);
+ setenv("filesize", buf);
+
+ return 0;
+fail:
+ return 1;
+}
+
+int do_ext_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+ const char *filename = "/";
+ int dev;
+ int part;
+ block_dev_desc_t *dev_desc;
+ disk_partition_t info;
+
+ if (argc < 2)
+ return cmd_usage(cmdtp);
+
+ part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ if (part < 0)
+ return 1;
+
+ if (argc == 4)
+ filename = argv[3];
+
+ dev = dev_desc->dev;
+ ext4fs_set_blk_dev(dev_desc, &info);
+
+ if (!ext4fs_mount(info.size)) {
+ printf("** Bad ext2 partition or disk - %s %d:%d **\n",
+ argv[1], dev, part);
+ ext4fs_close();
+ goto fail;
+ }
+
+ if (ext4fs_ls(filename)) {
+ printf("** Error extfs_ls() **\n");
+ ext4fs_close();
+ goto fail;
+ };
+
+ ext4fs_close();
+ return 0;
+
+fail:
+ return 1;
+}
diff --git a/common/cmd_fat.c b/common/cmd_fat.c
index 559a16d..01e02f5 100644
--- a/common/cmd_fat.c
+++ b/common/cmd_fat.c
@@ -40,29 +40,20 @@ int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
unsigned long count;
char buf [12];
block_dev_desc_t *dev_desc=NULL;
- int dev=0;
- int part=1;
- char *ep;
+ disk_partition_t info;
+ int part, dev;
if (argc < 5) {
- printf( "usage: fatload <interface> <dev[:part]> "
+ printf("usage: fatload <interface> [<dev[:part]>] "
"<addr> <filename> [bytes]\n");
return 1;
}
- dev = (int)simple_strtoul(argv[2], &ep, 16);
- dev_desc = get_dev(argv[1],dev);
- if (dev_desc == NULL) {
- puts("\n** Invalid boot device **\n");
+ part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ if (part < 0)
return 1;
- }
- if (*ep) {
- if (*ep != ':') {
- puts("\n** Invalid boot device, use `dev[:part]' **\n");
- return 1;
- }
- part = (int)simple_strtoul(++ep, NULL, 16);
- }
+
+ dev = dev_desc->dev;
if (fat_register_device(dev_desc,part)!=0) {
printf("\n** Unable to use %s %d:%d for fatload **\n",
argv[1], dev, part);
@@ -93,7 +84,7 @@ int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
U_BOOT_CMD(
fatload, 6, 0, do_fat_fsload,
"load binary file from a dos filesystem",
- "<interface> <dev[:part]> <addr> <filename> [bytes]\n"
+ "<interface> [<dev[:part]>] <addr> <filename> [bytes]\n"
" - load binary file 'filename' from 'dev' on 'interface'\n"
" to address 'addr' from dos filesystem"
);
@@ -101,29 +92,20 @@ U_BOOT_CMD(
int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char *filename = "/";
- int ret;
- int dev=0;
- int part=1;
- char *ep;
+ int ret, dev, part;
block_dev_desc_t *dev_desc=NULL;
+ disk_partition_t info;
- if (argc < 3) {
- printf("usage: fatls <interface> <dev[:part]> [directory]\n");
+ if (argc < 2) {
+ printf("usage: fatls <interface> [<dev[:part]>] [directory]\n");
return 0;
}
- dev = (int)simple_strtoul(argv[2], &ep, 16);
- dev_desc = get_dev(argv[1],dev);
- if (dev_desc == NULL) {
- puts("\n** Invalid boot device **\n");
+
+ part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ if (part < 0)
return 1;
- }
- if (*ep) {
- if (*ep != ':') {
- puts("\n** Invalid boot device, use `dev[:part]' **\n");
- return 1;
- }
- part = (int)simple_strtoul(++ep, NULL, 16);
- }
+
+ dev = dev_desc->dev;
if (fat_register_device(dev_desc,part)!=0) {
printf("\n** Unable to use %s %d:%d for fatls **\n",
argv[1], dev, part);
@@ -142,34 +124,26 @@ int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
U_BOOT_CMD(
fatls, 4, 1, do_fat_ls,
"list files in a directory (default /)",
- "<interface> <dev[:part]> [directory]\n"
+ "<interface> [<dev[:part]>] [directory]\n"
" - list files from 'dev' on 'interface' in a 'directory'"
);
int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- int dev=0;
- int part=1;
- char *ep;
- block_dev_desc_t *dev_desc=NULL;
+ int dev, part;
+ block_dev_desc_t *dev_desc;
+ disk_partition_t info;
if (argc < 2) {
- printf("usage: fatinfo <interface> <dev[:part]>\n");
+ printf("usage: fatinfo <interface> [<dev[:part]>]\n");
return 0;
}
- dev = (int)simple_strtoul(argv[2], &ep, 16);
- dev_desc = get_dev(argv[1],dev);
- if (dev_desc == NULL) {
- puts("\n** Invalid boot device **\n");
+
+ part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ if (part < 0)
return 1;
- }
- if (*ep) {
- if (*ep != ':') {
- puts("\n** Invalid boot device, use `dev[:part]' **\n");
- return 1;
- }
- part = (int)simple_strtoul(++ep, NULL, 16);
- }
+
+ dev = dev_desc->dev;
if (fat_register_device(dev_desc,part)!=0) {
printf("\n** Unable to use %s %d:%d for fatinfo **\n",
argv[1], dev, part);
@@ -181,7 +155,7 @@ int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
U_BOOT_CMD(
fatinfo, 3, 1, do_fat_fsinfo,
"print information about filesystem",
- "<interface> <dev[:part]>\n"
+ "<interface> [<dev[:part]>]\n"
" - print information about filesystem from 'dev' on 'interface'"
);
@@ -193,6 +167,7 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
unsigned long addr;
unsigned long count;
block_dev_desc_t *dev_desc = NULL;
+ disk_partition_t info;
int dev = 0;
int part = 1;
char *ep;
@@ -200,19 +175,12 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
if (argc < 5)
return cmd_usage(cmdtp);
- dev = (int)simple_strtoul(argv[2], &ep, 16);
- dev_desc = get_dev(argv[1], dev);
- if (dev_desc == NULL) {
- puts("\n** Invalid boot device **\n");
+ part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ if (part < 0)
return 1;
- }
- if (*ep) {
- if (*ep != ':') {
- puts("\n** Invalid boot device, use `dev[:part]' **\n");
- return 1;
- }
- part = (int)simple_strtoul(++ep, NULL, 16);
- }
+
+ dev = dev_desc->dev;
+
if (fat_register_device(dev_desc, part) != 0) {
printf("\n** Unable to use %s %d:%d for fatwrite **\n",
argv[1], dev, part);
diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c
index 9a5c53e..e2225c4 100644
--- a/common/cmd_fdt.c
+++ b/common/cmd_fdt.c
@@ -114,10 +114,21 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
}
}
+ return CMD_RET_SUCCESS;
+ }
+
+ if (!working_fdt) {
+ puts(
+ "No FDT memory address configured. Please configure\n"
+ "the FDT address via \"fdt addr <address>\" command.\n"
+ "Aborting!\n");
+ return CMD_RET_FAILURE;
+ }
+
/*
* Move the working_fdt
*/
- } else if (strncmp(argv[1], "mo", 2) == 0) {
+ if (strncmp(argv[1], "mo", 2) == 0) {
struct fdt_header *newaddr;
int len;
int err;
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index f5b6c7b..6e1e568 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -334,156 +334,7 @@ int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
- char *boot_device = NULL;
- char *ep;
- int dev, part = 0;
- ulong addr, cnt;
- disk_partition_t info;
- image_header_t *hdr;
-
-#if defined(CONFIG_FIT)
- const void *fit_hdr = NULL;
-#endif
-
- bootstage_mark(BOOTSTAGE_ID_IDE_START);
- switch (argc) {
- case 1:
- addr = CONFIG_SYS_LOAD_ADDR;
- boot_device = getenv("bootdevice");
- break;
- case 2:
- addr = simple_strtoul(argv[1], NULL, 16);
- boot_device = getenv("bootdevice");
- break;
- case 3:
- addr = simple_strtoul(argv[1], NULL, 16);
- boot_device = argv[2];
- break;
- default:
- bootstage_error(BOOTSTAGE_ID_IDE_ADDR);
- return CMD_RET_USAGE;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_ADDR);
-
- if (!boot_device) {
- puts("\n** No boot device **\n");
- bootstage_error(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
-
- dev = simple_strtoul(boot_device, &ep, 16);
-
- if (ide_dev_desc[dev].type == DEV_TYPE_UNKNOWN) {
- printf("\n** Device %d not available\n", dev);
- bootstage_error(BOOTSTAGE_ID_IDE_TYPE);
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_TYPE);
-
- if (*ep) {
- if (*ep != ':') {
- puts("\n** Invalid boot device, use `dev[:part]' **\n");
- bootstage_error(BOOTSTAGE_ID_IDE_PART);
- return 1;
- }
- part = simple_strtoul(++ep, NULL, 16);
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_PART);
-
- if (get_partition_info(&ide_dev_desc[dev], part, &info)) {
- bootstage_error(BOOTSTAGE_ID_IDE_PART_INFO);
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_PART_INFO);
-
- if ((strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0)
- &&
- (strncmp((char *)info.type, BOOT_PART_COMP, sizeof(info.type)) != 0)
- ) {
- printf("\n** Invalid partition type \"%.32s\"" " (expect \""
- BOOT_PART_TYPE "\")\n",
- info.type);
- bootstage_error(BOOTSTAGE_ID_IDE_PART_TYPE);
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_PART_TYPE);
-
- printf("\nLoading from IDE device %d, partition %d: "
- "Name: %.32s Type: %.32s\n", dev, part, info.name, info.type);
-
- debug("First Block: %ld, # of blocks: %ld, Block Size: %ld\n",
- info.start, info.size, info.blksz);
-
- if (ide_dev_desc[dev].
- block_read(dev, info.start, 1, (ulong *) addr) != 1) {
- printf("** Read error on %d:%d\n", dev, part);
- bootstage_error(BOOTSTAGE_ID_IDE_PART_READ);
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ);
-
- switch (genimg_get_format((void *) addr)) {
- case IMAGE_FORMAT_LEGACY:
- hdr = (image_header_t *) addr;
-
- bootstage_mark(BOOTSTAGE_ID_IDE_FORMAT);
-
- if (!image_check_hcrc(hdr)) {
- puts("\n** Bad Header Checksum **\n");
- bootstage_error(BOOTSTAGE_ID_IDE_CHECKSUM);
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_CHECKSUM);
-
- image_print_contents(hdr);
-
- cnt = image_get_image_size(hdr);
- break;
-#if defined(CONFIG_FIT)
- case IMAGE_FORMAT_FIT:
- fit_hdr = (const void *) addr;
- puts("Fit image detected...\n");
-
- cnt = fit_get_size(fit_hdr);
- break;
-#endif
- default:
- bootstage_error(BOOTSTAGE_ID_IDE_FORMAT);
- puts("** Unknown image type\n");
- return 1;
- }
-
- cnt += info.blksz - 1;
- cnt /= info.blksz;
- cnt -= 1;
-
- if (ide_dev_desc[dev].block_read(dev, info.start + 1, cnt,
- (ulong *)(addr + info.blksz)) != cnt) {
- printf("** Read error on %d:%d\n", dev, part);
- bootstage_error(BOOTSTAGE_ID_IDE_READ);
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_READ);
-
-#if defined(CONFIG_FIT)
- /* This cannot be done earlier, we need complete FIT image in RAM first */
- if (genimg_get_format((void *) addr) == IMAGE_FORMAT_FIT) {
- if (!fit_check_format(fit_hdr)) {
- bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ);
- puts("** Bad FIT image format\n");
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK);
- fit_print_contents(fit_hdr);
- }
-#endif
-
- /* Loading ok, update default load address */
-
- load_addr = addr;
-
- return bootm_maybe_autostart(cmdtp, argv[0]);
+ return common_diskboot(cmdtp, "ide", argc, argv);
}
/* ------------------------------------------------------------------------- */
diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
index 750509d..79a1088 100644
--- a/common/cmd_mmc.c
+++ b/common/cmd_mmc.c
@@ -144,8 +144,7 @@ int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
U_BOOT_CMD(
mmcinfo, 1, 0, do_mmcinfo,
"display MMC info",
- " - device number of the device to dislay info of\n"
- ""
+ "- dislay info of the current MMC device"
);
int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index a91ccf4..e24ed7f 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -48,8 +48,8 @@ static int nand_dump(nand_info_t *nand, ulong off, int only_oob, int repeat)
last = off;
- datbuf = malloc(nand->writesize);
- oobbuf = malloc(nand->oobsize);
+ datbuf = memalign(ARCH_DMA_MINALIGN, nand->writesize);
+ oobbuf = memalign(ARCH_DMA_MINALIGN, nand->oobsize);
if (!datbuf || !oobbuf) {
puts("No memory for page buffer\n");
return 1;
@@ -231,12 +231,18 @@ print:
#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
static void print_status(ulong start, ulong end, ulong erasesize, int status)
{
+ /*
+ * Micron NAND flash (e.g. MT29F4G08ABADAH4) BLOCK LOCK READ STATUS is
+ * not the same as others. Instead of bit 1 being lock, it is
+ * #lock_tight. To make the driver support either format, ignore bit 1
+ * and use only bit 0 and bit 2.
+ */
printf("%08lx - %08lx: %08lx blocks %s%s%s\n",
start,
end - 1,
(end - start) / erasesize,
((status & NAND_LOCK_STATUS_TIGHT) ? "TIGHT " : ""),
- ((status & NAND_LOCK_STATUS_LOCK) ? "LOCK " : ""),
+ (!(status & NAND_LOCK_STATUS_UNLOCK) ? "LOCK " : ""),
((status & NAND_LOCK_STATUS_UNLOCK) ? "UNLOCK " : ""));
}
@@ -749,11 +755,18 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
return 0;
}
- if (strcmp(cmd, "unlock") == 0) {
+ if (strncmp(cmd, "unlock", 5) == 0) {
+ int allexcept = 0;
+
+ s = strchr(cmd, '.');
+
+ if (s && !strcmp(s, ".allexcept"))
+ allexcept = 1;
+
if (arg_off_size(argc - 2, argv + 2, &dev, &off, &size) < 0)
return 1;
- if (!nand_unlock(&nand_info[dev], off, size)) {
+ if (!nand_unlock(&nand_info[dev], off, size, allexcept)) {
puts("NAND flash successfully unlocked\n");
} else {
puts("Error unlocking NAND flash, "
@@ -807,7 +820,7 @@ U_BOOT_CMD(
"\n"
"nand lock [tight] [status]\n"
" bring nand to lock state or display locked pages\n"
- "nand unlock [offset] [size] - unlock section"
+ "nand unlock[.allexcept] [offset] [size] - unlock section"
#endif
#ifdef CONFIG_ENV_OFFSET_OOB
"\n"
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index fd05e72..3474bc6 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -198,31 +198,20 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
#endif
/*
- * Set a new environment variable,
- * or replace or delete an existing one.
+ * Perform consistency checking before setting, replacing, or deleting an
+ * environment variable, then (if successful) apply the changes to internals so
+ * to make them effective. Code for this function was taken out of
+ * _do_env_set(), which now calls it instead.
+ * Also called as a callback function by himport_r().
+ * Returns 0 in case of success, 1 in case of failure.
+ * When (flag & H_FORCE) is set, do not print out any error message and force
+ * overwriting of write-once variables.
*/
-int _do_env_set(int flag, int argc, char * const argv[])
+
+int env_check_apply(const char *name, const char *oldval,
+ const char *newval, int flag)
{
- int i, len;
int console = -1;
- char *name, *value, *s;
- ENTRY e, *ep;
-
- name = argv[1];
-
- if (strchr(name, '=')) {
- printf("## Error: illegal character '=' in variable name"
- "\"%s\"\n", name);
- return 1;
- }
-
- env_id++;
- /*
- * search if variable with this name already exists
- */
- e.key = name;
- e.data = NULL;
- hsearch_r(e, FIND, &ep, &env_htab);
/* Check for console redirection */
if (strcmp(name, "stdin") == 0)
@@ -233,60 +222,75 @@ int _do_env_set(int flag, int argc, char * const argv[])
console = stderr;
if (console != -1) {
- if (argc < 3) { /* Cannot delete it! */
- printf("Can't delete \"%s\"\n", name);
+ if ((newval == NULL) || (*newval == '\0')) {
+ /* We cannot delete stdin/stdout/stderr */
+ if ((flag & H_FORCE) == 0)
+ printf("Can't delete \"%s\"\n", name);
return 1;
}
#ifdef CONFIG_CONSOLE_MUX
- i = iomux_doenv(console, argv[2]);
- if (i)
- return i;
+ if (iomux_doenv(console, newval))
+ return 1;
#else
/* Try assigning specified device */
- if (console_assign(console, argv[2]) < 0)
+ if (console_assign(console, newval) < 0)
return 1;
#ifdef CONFIG_SERIAL_MULTI
- if (serial_assign(argv[2]) < 0)
+ if (serial_assign(newval) < 0)
return 1;
#endif
#endif /* CONFIG_CONSOLE_MUX */
}
/*
- * Some variables like "ethaddr" and "serial#" can be set only
- * once and cannot be deleted; also, "ver" is readonly.
+ * Some variables like "ethaddr" and "serial#" can be set only once and
+ * cannot be deleted, unless CONFIG_ENV_OVERWRITE is defined.
*/
- if (ep) { /* variable exists */
#ifndef CONFIG_ENV_OVERWRITE
+ if (oldval != NULL && /* variable exists */
+ (flag & H_FORCE) == 0) { /* and we are not forced */
if (strcmp(name, "serial#") == 0 ||
(strcmp(name, "ethaddr") == 0
#if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
- && strcmp(ep->data, MK_STR(CONFIG_ETHADDR)) != 0
+ && strcmp(oldval, MK_STR(CONFIG_ETHADDR)) != 0
#endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
)) {
printf("Can't overwrite \"%s\"\n", name);
return 1;
}
+ }
#endif
+ /*
+ * When we change baudrate, or we are doing an env default -a
+ * (which will erase all variables prior to calling this),
+ * we want the baudrate to actually change - for real.
+ */
+ if (oldval != NULL || /* variable exists */
+ (flag & H_NOCLEAR) == 0) { /* or env is clear */
/*
* Switch to new baudrate if new baudrate is supported
*/
if (strcmp(name, "baudrate") == 0) {
- int baudrate = simple_strtoul(argv[2], NULL, 10);
+ int baudrate = simple_strtoul(newval, NULL, 10);
int i;
for (i = 0; i < N_BAUDRATES; ++i) {
if (baudrate == baudrate_table[i])
break;
}
if (i == N_BAUDRATES) {
- printf("## Baudrate %d bps not supported\n",
- baudrate);
+ if ((flag & H_FORCE) == 0)
+ printf("## Baudrate %d bps not "
+ "supported\n", baudrate);
return 1;
}
+ if (gd->baudrate == baudrate) {
+ /* If unchanged, we just say it's OK */
+ return 0;
+ }
printf("## Switch baudrate to %d bps and"
- "press ENTER ...\n", baudrate);
+ "press ENTER ...\n", baudrate);
udelay(50000);
gd->baudrate = baudrate;
#if defined(CONFIG_PPC) || defined(CONFIG_MCF52x2)
@@ -300,9 +304,62 @@ int _do_env_set(int flag, int argc, char * const argv[])
}
}
+ /*
+ * Some variables should be updated when the corresponding
+ * entry in the environment is changed
+ */
+ if (strcmp(name, "loadaddr") == 0) {
+ load_addr = simple_strtoul(newval, NULL, 16);
+ return 0;
+ }
+#if defined(CONFIG_CMD_NET)
+ else if (strcmp(name, "bootfile") == 0) {
+ copy_filename(BootFile, newval, sizeof(BootFile));
+ return 0;
+ }
+#endif
+ return 0;
+}
+
+/*
+ * Set a new environment variable,
+ * or replace or delete an existing one.
+*/
+int _do_env_set(int flag, int argc, char * const argv[])
+{
+ int i, len;
+ char *name, *value, *s;
+ ENTRY e, *ep;
+
+ name = argv[1];
+ value = argv[2];
+
+ if (strchr(name, '=')) {
+ printf("## Error: illegal character '='"
+ "in variable name \"%s\"\n", name);
+ return 1;
+ }
+
+ env_id++;
+ /*
+ * search if variable with this name already exists
+ */
+ e.key = name;
+ e.data = NULL;
+ hsearch_r(e, FIND, &ep, &env_htab);
+
+ /*
+ * Perform requested checks. Notice how since we are overwriting
+ * a single variable, we need to set H_NOCLEAR
+ */
+ if (env_check_apply(name, ep ? ep->data : NULL, value, H_NOCLEAR)) {
+ debug("check function did not approve, refusing\n");
+ return 1;
+ }
+
/* Delete only ? */
if (argc < 3 || argv[2] == NULL) {
- int rc = hdelete_r(name, &env_htab);
+ int rc = hdelete_r(name, &env_htab, 0);
return !rc;
}
@@ -337,20 +394,6 @@ int _do_env_set(int flag, int argc, char * const argv[])
return 1;
}
- /*
- * Some variables should be updated when the corresponding
- * entry in the environment is changed
- */
- if (strcmp(argv[1], "loadaddr") == 0) {
- load_addr = simple_strtoul(argv[2], NULL, 16);
- return 0;
- }
-#if defined(CONFIG_CMD_NET)
- else if (strcmp(argv[1], "bootfile") == 0) {
- copy_filename(BootFile, argv[2], sizeof(BootFile));
- return 0;
- }
-#endif
return 0;
}
@@ -613,14 +656,41 @@ int envmatch(uchar *s1, int i2)
return -1;
}
-static int do_env_default(cmd_tbl_t *cmdtp, int flag,
+static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
int argc, char * const argv[])
{
- if (argc != 2 || strcmp(argv[1], "-f") != 0)
- return CMD_RET_USAGE;
+ int all = 0, flag = 0;
- set_default_env("## Resetting to default environment\n");
- return 0;
+ debug("Initial value for argc=%d\n", argc);
+ while (--argc > 0 && **++argv == '-') {
+ char *arg = *argv;
+
+ while (*++arg) {
+ switch (*arg) {
+ case 'a': /* default all */
+ all = 1;
+ break;
+ case 'f': /* force */
+ flag |= H_FORCE;
+ break;
+ default:
+ return cmd_usage(cmdtp);
+ }
+ }
+ }
+ debug("Final value for argc=%d\n", argc);
+ if (all && (argc == 0)) {
+ /* Reset the whole environment */
+ set_default_env("## Resetting to default environment\n");
+ return 0;
+ }
+ if (!all && (argc > 0)) {
+ /* Reset individual variables */
+ set_default_vars(argc, argv);
+ return 0;
+ }
+
+ return cmd_usage(cmdtp);
}
static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
@@ -872,7 +942,8 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag,
addr = (char *)ep->data;
}
- if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR) == 0) {
+ if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR,
+ 0, NULL, 0 /* do_apply */) == 0) {
error("Environment import failed: errno = %d\n", errno);
return 1;
}
@@ -950,15 +1021,20 @@ U_BOOT_CMD(
#if defined(CONFIG_CMD_ASKENV)
"ask name [message] [size] - ask for environment variable\nenv "
#endif
- "default -f - reset default environment\n"
+ "default [-f] -a - [forcibly] reset default environment\n"
+ "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
#if defined(CONFIG_CMD_EDITENV)
"env edit name - edit environment variable\n"
#endif
+#if defined(CONFIG_CMD_EXPORTENV)
"env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n"
+#endif
#if defined(CONFIG_CMD_GREPENV)
"env grep string [...] - search environment\n"
#endif
+#if defined(CONFIG_CMD_IMPORTENV)
"env import [-d] [-t | -b | -c] addr [size] - import environment\n"
+#endif
"env print [name ...] - print environment\n"
#if defined(CONFIG_CMD_RUN)
"env run var [...] - run commands in an environment variable\n"
diff --git a/common/cmd_part.c b/common/cmd_part.c
new file mode 100644
index 0000000..d997597
--- /dev/null
+++ b/common/cmd_part.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
+ *
+ * made from cmd_ext2, which was:
+ *
+ * (C) Copyright 2004
+ * esd gmbh <www.esd-electronics.com>
+ * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
+ *
+ * made from cmd_reiserfs by
+ *
+ * (C) Copyright 2003 - 2004
+ * Sysgo Real-Time Solutions, AG <www.elinos.com>
+ * Pavel Bartusek <pba@sysgo.com>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <part.h>
+#include <vsprintf.h>
+
+#ifndef CONFIG_PARTITION_UUIDS
+#error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_PART to be enabled
+#endif
+
+int do_part_uuid(int argc, char * const argv[])
+{
+ int part;
+ block_dev_desc_t *dev_desc;
+ disk_partition_t info;
+
+ if (argc < 2)
+ return CMD_RET_USAGE;
+ if (argc > 3)
+ return CMD_RET_USAGE;
+
+ part = get_device_and_partition(argv[0], argv[1], &dev_desc, &info, 0);
+ if (part < 0)
+ return 1;
+
+ if (argc > 2)
+ setenv(argv[2], info.uuid);
+ else
+ printf("%s\n", info.uuid);
+
+ return 0;
+}
+
+int do_part_list(int argc, char * const argv[])
+{
+ int ret;
+ block_dev_desc_t *desc;
+
+ if (argc != 2)
+ return CMD_RET_USAGE;
+
+ ret = get_device(argv[0], argv[1], &desc);
+ if (ret < 0)
+ return 1;
+
+ print_part(desc);
+
+ return 0;
+}
+
+int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ if (argc < 2)
+ return CMD_RET_USAGE;
+
+ if (!strcmp(argv[1], "uuid"))
+ return do_part_uuid(argc - 2, argv + 2);
+ else if (!strcmp(argv[1], "list"))
+ return do_part_list(argc - 2, argv + 2);
+
+ return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+ part, 5, 1, do_part,
+ "disk partition related commands",
+ "part uuid <interface> <dev>:<part>\n"
+ " - print partition UUID\n"
+ "part uuid <interface> <dev>:<part> <varname>\n"
+ " - set environment variable to partition UUID\n"
+ "part list <interface> <dev>\n"
+ " - print a device's partition table"
+);
diff --git a/common/cmd_reiser.c b/common/cmd_reiser.c
index fbb9484..e658618 100644
--- a/common/cmd_reiser.c
+++ b/common/cmd_reiser.c
@@ -50,43 +50,27 @@
int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char *filename = "/";
- int dev=0;
- int part=1;
- char *ep;
+ int dev, part;
block_dev_desc_t *dev_desc=NULL;
- int part_length;
+ disk_partition_t info;
if (argc < 3)
return CMD_RET_USAGE;
- dev = (int)simple_strtoul (argv[2], &ep, 16);
- dev_desc = get_dev(argv[1],dev);
-
- if (dev_desc == NULL) {
- printf ("\n** Block device %s %d not supported\n", argv[1], dev);
+ part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ if (part < 0)
return 1;
- }
-
- if (*ep) {
- if (*ep != ':') {
- puts ("\n** Invalid boot device, use `dev[:part]' **\n");
- return 1;
- }
- part = (int)simple_strtoul(++ep, NULL, 16);
- }
if (argc == 4) {
filename = argv[3];
}
+ dev = dev_desc->dev;
PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
- if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
- printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
- return 1;
- }
+ reiserfs_set_blk_dev(dev_desc, &info);
- if (!reiserfs_mount(part_length)) {
+ if (!reiserfs_mount(info.size)) {
printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
return 1;
}
@@ -112,9 +96,8 @@ U_BOOT_CMD(
int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char *filename = NULL;
- char *ep;
- int dev, part = 0;
- ulong addr = 0, part_length, filelen;
+ int dev, part;
+ ulong addr = 0, filelen;
disk_partition_t info;
block_dev_desc_t *dev_desc = NULL;
char buf [12];
@@ -157,49 +140,19 @@ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 1;
}
- dev = (int)simple_strtoul (argv[2], &ep, 16);
- dev_desc = get_dev(argv[1],dev);
- if (dev_desc==NULL) {
- printf ("\n** Block device %s %d not supported\n", argv[1], dev);
+ part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ if (part < 0)
return 1;
- }
- if (*ep) {
- if (*ep != ':') {
- puts ("\n** Invalid boot device, use `dev[:part]' **\n");
- return 1;
- }
- part = (int)simple_strtoul(++ep, NULL, 16);
- }
- PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part);
+ dev = dev_desc->dev;
- if (part != 0) {
- if (get_partition_info (dev_desc, part, &info)) {
- printf ("** Bad partition %d **\n", part);
- return 1;
- }
+ printf("Loading file \"%s\" from %s device %d%c%c\n",
+ filename, argv[1], dev,
+ part ? ':' : ' ', part ? part + '0' : ' ');
- if (strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
- printf ("\n** Invalid partition type \"%.32s\""
- " (expect \"" BOOT_PART_TYPE "\")\n",
- info.type);
- return 1;
- }
- PRINTF ("\nLoading from block device %s device %d, partition %d: "
- "Name: %.32s Type: %.32s File:%s\n",
- argv[1], dev, part, info.name, info.type, filename);
- } else {
- PRINTF ("\nLoading from block device %s device %d, File:%s\n",
- argv[1], dev, filename);
- }
-
-
- if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
- printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
- return 1;
- }
+ reiserfs_set_blk_dev(dev_desc, &info);
- if (!reiserfs_mount(part_length)) {
+ if (!reiserfs_mount(info.size)) {
printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
return 1;
}
diff --git a/common/cmd_scsi.c b/common/cmd_scsi.c
index d15b567..22d0119 100644
--- a/common/cmd_scsi.c
+++ b/common/cmd_scsi.c
@@ -206,128 +206,7 @@ block_dev_desc_t * scsi_get_dev(int dev)
*/
int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- char *boot_device = NULL;
- char *ep;
- int dev, part = 0;
- ulong addr, cnt;
- disk_partition_t info;
- image_header_t *hdr;
-#if defined(CONFIG_FIT)
- const void *fit_hdr = NULL;
-#endif
-
- switch (argc) {
- case 1:
- addr = CONFIG_SYS_LOAD_ADDR;
- boot_device = getenv ("bootdevice");
- break;
- case 2:
- addr = simple_strtoul(argv[1], NULL, 16);
- boot_device = getenv ("bootdevice");
- break;
- case 3:
- addr = simple_strtoul(argv[1], NULL, 16);
- boot_device = argv[2];
- break;
- default:
- return CMD_RET_USAGE;
- }
-
- if (!boot_device) {
- puts ("\n** No boot device **\n");
- return 1;
- }
-
- dev = simple_strtoul(boot_device, &ep, 16);
- printf("booting from dev %d\n",dev);
- if (scsi_dev_desc[dev].type == DEV_TYPE_UNKNOWN) {
- printf ("\n** Device %d not available\n", dev);
- return 1;
- }
-
- if (*ep) {
- if (*ep != ':') {
- puts ("\n** Invalid boot device, use `dev[:part]' **\n");
- return 1;
- }
- part = simple_strtoul(++ep, NULL, 16);
- }
- if (get_partition_info (&scsi_dev_desc[dev], part, &info)) {
- printf("error reading partinfo\n");
- return 1;
- }
- if ((strncmp((char *)(info.type), BOOT_PART_TYPE, sizeof(info.type)) != 0) &&
- (strncmp((char *)(info.type), BOOT_PART_COMP, sizeof(info.type)) != 0)) {
- printf ("\n** Invalid partition type \"%.32s\""
- " (expect \"" BOOT_PART_TYPE "\")\n",
- info.type);
- return 1;
- }
-
- printf ("\nLoading from SCSI device %d, partition %d: "
- "Name: %.32s Type: %.32s\n",
- dev, part, info.name, info.type);
-
- debug ("First Block: %ld, # of blocks: %ld, Block Size: %ld\n",
- info.start, info.size, info.blksz);
-
- if (scsi_read (dev, info.start, 1, (ulong *)addr) != 1) {
- printf ("** Read error on %d:%d\n", dev, part);
- return 1;
- }
-
- switch (genimg_get_format ((void *)addr)) {
- case IMAGE_FORMAT_LEGACY:
- hdr = (image_header_t *)addr;
-
- if (!image_check_hcrc (hdr)) {
- puts ("\n** Bad Header Checksum **\n");
- return 1;
- }
-
- image_print_contents (hdr);
- cnt = image_get_image_size (hdr);
- break;
-#if defined(CONFIG_FIT)
- case IMAGE_FORMAT_FIT:
- fit_hdr = (const void *)addr;
- puts ("Fit image detected...\n");
-
- cnt = fit_get_size (fit_hdr);
- break;
-#endif
- default:
- puts ("** Unknown image type\n");
- return 1;
- }
-
- cnt += info.blksz - 1;
- cnt /= info.blksz;
- cnt -= 1;
-
- if (scsi_read (dev, info.start+1, cnt,
- (ulong *)(addr+info.blksz)) != cnt) {
- printf ("** Read error on %d:%d\n", dev, part);
- return 1;
- }
-
-#if defined(CONFIG_FIT)
- /* This cannot be done earlier, we need complete FIT image in RAM first */
- if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) {
- if (!fit_check_format (fit_hdr)) {
- puts ("** Bad FIT image format\n");
- return 1;
- }
- fit_print_contents (fit_hdr);
- }
-#endif
-
- /* Loading ok, update default load address */
- load_addr = addr;
-
- flush_cache (addr, (cnt+1)*info.blksz);
-
- return bootm_maybe_autostart(cmdtp, argv[0]);
+ return common_diskboot(cmdtp, "scsi", argc, argv);
}
/*********************************************************************************
diff --git a/common/cmd_usb.c b/common/cmd_usb.c
index a8e3ae5..181e727 100644
--- a/common/cmd_usb.c
+++ b/common/cmd_usb.c
@@ -355,143 +355,7 @@ void usb_show_tree(struct usb_device *dev)
#ifdef CONFIG_USB_STORAGE
int do_usbboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- char *boot_device = NULL;
- char *ep;
- int dev, part = 1;
- ulong addr, cnt;
- disk_partition_t info;
- image_header_t *hdr;
- block_dev_desc_t *stor_dev;
-#if defined(CONFIG_FIT)
- const void *fit_hdr = NULL;
-#endif
-
- switch (argc) {
- case 1:
- addr = CONFIG_SYS_LOAD_ADDR;
- boot_device = getenv("bootdevice");
- break;
- case 2:
- addr = simple_strtoul(argv[1], NULL, 16);
- boot_device = getenv("bootdevice");
- break;
- case 3:
- addr = simple_strtoul(argv[1], NULL, 16);
- boot_device = argv[2];
- break;
- default:
- return CMD_RET_USAGE;
- }
-
- if (!boot_device) {
- puts("\n** No boot device **\n");
- return 1;
- }
-
- dev = simple_strtoul(boot_device, &ep, 16);
- stor_dev = usb_stor_get_dev(dev);
- if (stor_dev == NULL || stor_dev->type == DEV_TYPE_UNKNOWN) {
- printf("\n** Device %d not available\n", dev);
- return 1;
- }
- if (stor_dev->block_read == NULL) {
- printf("storage device not initialized. Use usb scan\n");
- return 1;
- }
- if (*ep) {
- if (*ep != ':') {
- puts("\n** Invalid boot device, use `dev[:part]' **\n");
- return 1;
- }
- part = simple_strtoul(++ep, NULL, 16);
- }
-
- if (get_partition_info(stor_dev, part, &info)) {
- /* try to boot raw .... */
- strncpy((char *)&info.type[0], BOOT_PART_TYPE,
- sizeof(BOOT_PART_TYPE));
- strncpy((char *)&info.name[0], "Raw", 4);
- info.start = 0;
- info.blksz = 0x200;
- info.size = 2880;
- printf("error reading partinfo...try to boot raw\n");
- }
- if ((strncmp((char *)info.type, BOOT_PART_TYPE,
- sizeof(info.type)) != 0) &&
- (strncmp((char *)info.type, BOOT_PART_COMP,
- sizeof(info.type)) != 0)) {
- printf("\n** Invalid partition type \"%.32s\""
- " (expect \"" BOOT_PART_TYPE "\")\n",
- info.type);
- return 1;
- }
- printf("\nLoading from USB device %d, partition %d: "
- "Name: %.32s Type: %.32s\n",
- dev, part, info.name, info.type);
-
- debug("First Block: %ld, # of blocks: %ld, Block Size: %ld\n",
- info.start, info.size, info.blksz);
-
- if (stor_dev->block_read(dev, info.start, 1, (ulong *)addr) != 1) {
- printf("** Read error on %d:%d\n", dev, part);
- return 1;
- }
-
- switch (genimg_get_format((void *)addr)) {
- case IMAGE_FORMAT_LEGACY:
- hdr = (image_header_t *)addr;
-
- if (!image_check_hcrc(hdr)) {
- puts("\n** Bad Header Checksum **\n");
- return 1;
- }
-
- image_print_contents(hdr);
-
- cnt = image_get_image_size(hdr);
- break;
-#if defined(CONFIG_FIT)
- case IMAGE_FORMAT_FIT:
- fit_hdr = (const void *)addr;
- puts("Fit image detected...\n");
-
- cnt = fit_get_size(fit_hdr);
- break;
-#endif
- default:
- puts("** Unknown image type\n");
- return 1;
- }
-
- cnt += info.blksz - 1;
- cnt /= info.blksz;
- cnt -= 1;
-
- if (stor_dev->block_read(dev, info.start+1, cnt,
- (ulong *)(addr+info.blksz)) != cnt) {
- printf("\n** Read error on %d:%d\n", dev, part);
- return 1;
- }
-
-#if defined(CONFIG_FIT)
- /* This cannot be done earlier, we need complete FIT image in RAM
- * first
- */
- if (genimg_get_format((void *)addr) == IMAGE_FORMAT_FIT) {
- if (!fit_check_format(fit_hdr)) {
- puts("** Bad FIT image format\n");
- return 1;
- }
- fit_print_contents(fit_hdr);
- }
-#endif
-
- /* Loading ok, update default load address */
- load_addr = addr;
-
- flush_cache(addr, (cnt+1)*info.blksz);
-
- return bootm_maybe_autostart(cmdtp, argv[0]);
+ return common_diskboot(cmdtp, "usb", argc, argv);
}
#endif /* CONFIG_USB_STORAGE */
diff --git a/common/cmd_zfs.c b/common/cmd_zfs.c
index a6ea2c0..d580f7b 100644
--- a/common/cmd_zfs.c
+++ b/common/cmd_zfs.c
@@ -49,12 +49,11 @@
static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
char *filename = NULL;
- char *ep;
int dev;
- unsigned long part = 1;
+ int part;
ulong addr = 0;
- ulong part_length;
disk_partition_t info;
+ block_dev_desc_t *dev_desc;
char buf[12];
unsigned long count;
const char *addr_str;
@@ -95,48 +94,17 @@ static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
return 1;
}
- dev = (int)simple_strtoul(argv[2], &ep, 16);
- zfs_dev_desc = get_dev(argv[1], dev);
- if (zfs_dev_desc == NULL) {
- printf("** Block device %s %d not supported\n", argv[1], dev);
+ part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ if (part < 0)
return 1;
- }
- if (*ep) {
- if (*ep != ':') {
- puts("** Invalid boot device, use `dev[:part]' **\n");
- return 1;
- }
- part = simple_strtoul(++ep, NULL, 16);
- }
+ dev = dev_desc->dev;
+ printf("Loading file \"%s\" from %s device %d%c%c\n",
+ filename, argv[1], dev,
+ part ? ':' : ' ', part ? part + '0' : ' ');
- if (part != 0) {
- if (get_partition_info(zfs_dev_desc, part, &info)) {
- printf("** Bad partition %lu **\n", part);
- return 1;
- }
-
- if (strncmp((char *)info.type, BOOT_PART_TYPE,
- strlen(BOOT_PART_TYPE)) != 0) {
- printf("** Invalid partition type \"%s\" (expect \"" BOOT_PART_TYPE "\")\n",
- info.type);
- return 1;
- }
- printf("Loading file \"%s\" "
- "from %s device %d:%lu %s\n",
- filename, argv[1], dev, part, info.name);
- } else {
- printf("Loading file \"%s\" from %s device %d\n",
- filename, argv[1], dev);
- }
-
- part_length = zfs_set_blk_dev(zfs_dev_desc, part);
- if (part_length == 0) {
- printf("**Bad partition - %s %d:%lu **\n", argv[1], dev, part);
- return 1;
- }
-
- vdev.part_length = part_length;
+ zfs_set_blk_dev(dev_desc, &info);
+ vdev.part_length = info.size;
memset(&zfile, 0, sizeof(zfile));
zfile.device = &vdev;
@@ -149,7 +117,7 @@ static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
zfile.size = (uint64_t)count;
if (zfs_read(&zfile, (char *)addr, zfile.size) != zfile.size) {
- printf("** Unable to read \"%s\" from %s %d:%lu **\n",
+ printf("** Unable to read \"%s\" from %s %d:%d **\n",
filename, argv[1], dev, part);
zfs_close(&zfile);
return 1;
@@ -181,41 +149,23 @@ int zfs_print(const char *entry, const struct zfs_dirhook_info *data)
static int do_zfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
const char *filename = "/";
- int dev;
- unsigned long part = 1;
- char *ep;
- int part_length;
+ int part;
+ block_dev_desc_t *dev_desc;
+ disk_partition_t info;
struct device_s vdev;
- if (argc < 3)
+ if (argc < 2)
return cmd_usage(cmdtp);
- dev = (int)simple_strtoul(argv[2], &ep, 16);
- zfs_dev_desc = get_dev(argv[1], dev);
-
- if (zfs_dev_desc == NULL) {
- printf("\n** Block device %s %d not supported\n", argv[1], dev);
- return 1;
- }
-
- if (*ep) {
- if (*ep != ':') {
- puts("\n** Invalid boot device, use `dev[:part]' **\n");
- return 1;
- }
- part = simple_strtoul(++ep, NULL, 16);
- }
-
if (argc == 4)
filename = argv[3];
- part_length = zfs_set_blk_dev(zfs_dev_desc, part);
- if (part_length == 0) {
- printf("** Bad partition - %s %d:%lu **\n", argv[1], dev, part);
+ part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
+ if (part < 0)
return 1;
- }
- vdev.part_length = part_length;
+ zfs_set_blk_dev(dev_desc, &info);
+ vdev.part_length = info.size;
zfs_ls(&vdev, filename,
zfs_print);
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index c645d73..1d7e527 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -1487,11 +1487,11 @@ static mbinptr av_[NAV * 2 + 2] = {
#ifdef CONFIG_NEEDS_MANUAL_RELOC
void malloc_bin_reloc (void)
{
- unsigned long *p = (unsigned long *)(&av_[2]);
- int i;
- for (i=2; i<(sizeof(av_)/sizeof(mbinptr)); ++i) {
- *p++ += gd->reloc_off;
- }
+ mbinptr *p = &av_[2];
+ size_t i;
+
+ for (i = 2; i < ARRAY_SIZE(av_); ++i, ++p)
+ *p = (mbinptr)((ulong)*p + gd->reloc_off);
}
#endif
diff --git a/common/env_common.c b/common/env_common.c
index d9e990d..3e46c26 100644
--- a/common/env_common.c
+++ b/common/env_common.c
@@ -80,6 +80,9 @@ const uchar default_environment[] = {
#ifdef CONFIG_ETH5ADDR
"eth5addr=" MK_STR(CONFIG_ETH5ADDR) "\0"
#endif
+#ifdef CONFIG_ETHPRIME
+ "ethprime=" CONFIG_ETHPRIME "\0"
+#endif
#ifdef CONFIG_IPADDR
"ipaddr=" MK_STR(CONFIG_IPADDR) "\0"
#endif
@@ -133,7 +136,9 @@ const uchar default_environment[] = {
"\0"
};
-struct hsearch_data env_htab;
+struct hsearch_data env_htab = {
+ .apply = env_check_apply,
+};
static uchar __env_get_char_spec(int index)
{
@@ -175,6 +180,11 @@ const uchar *env_get_addr(int index)
void set_default_env(const char *s)
{
+ /*
+ * By default, do not apply changes as they will eventually
+ * be applied by someone else
+ */
+ int do_apply = 0;
if (sizeof(default_environment) > ENV_SIZE) {
puts("*** Error - default environment is too large\n\n");
return;
@@ -186,6 +196,14 @@ void set_default_env(const char *s)
"using default environment\n\n",
s + 1);
} else {
+ /*
+ * This set_to_default was explicitly asked for
+ * by the user, as opposed to being a recovery
+ * mechanism. Therefore we check every single
+ * variable and apply changes to the system
+ * right away (e.g. baudrate, console).
+ */
+ do_apply = 1;
puts(s);
}
} else {
@@ -193,12 +211,26 @@ void set_default_env(const char *s)
}
if (himport_r(&env_htab, (char *)default_environment,
- sizeof(default_environment), '\0', 0) == 0)
+ sizeof(default_environment), '\0', 0,
+ 0, NULL, do_apply) == 0)
error("Environment import failed: errno = %d\n", errno);
gd->flags |= GD_FLG_ENV_READY;
}
+
+/* [re]set individual variables to their value in the default environment */
+int set_default_vars(int nvars, char * const vars[])
+{
+ /*
+ * Special use-case: import from default environment
+ * (and use \0 as a separator)
+ */
+ return himport_r(&env_htab, (const char *)default_environment,
+ sizeof(default_environment), '\0', H_NOCLEAR,
+ nvars, vars, 1 /* do_apply */);
+}
+
/*
* Check if CRC is valid and (if yes) import the environment.
* Note that "buf" may or may not be aligned.
@@ -218,7 +250,8 @@ int env_import(const char *buf, int check)
}
}
- if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0)) {
+ if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0,
+ 0, NULL, 0 /* do_apply */)) {
gd->flags |= GD_FLG_ENV_READY;
return 1;
}
diff --git a/common/env_mmc.c b/common/env_mmc.c
index be2f2be..a2ff90b 100644
--- a/common/env_mmc.c
+++ b/common/env_mmc.c
@@ -75,9 +75,28 @@ static int init_mmc_for_env(struct mmc *mmc)
return -1;
}
+#ifdef CONFIG_SYS_MMC_ENV_PART
+ if (CONFIG_SYS_MMC_ENV_PART != mmc->part_num) {
+ if (mmc_switch_part(CONFIG_SYS_MMC_ENV_DEV,
+ CONFIG_SYS_MMC_ENV_PART)) {
+ puts("MMC partition switch failed\n");
+ return -1;
+ }
+ }
+#endif
+
return 0;
}
+static void fini_mmc_for_env(struct mmc *mmc)
+{
+#ifdef CONFIG_SYS_MMC_ENV_PART
+ if (CONFIG_SYS_MMC_ENV_PART != mmc->part_num)
+ mmc_switch_part(CONFIG_SYS_MMC_ENV_DEV,
+ mmc->part_num);
+#endif
+}
+
#ifdef CONFIG_CMD_SAVEENV
static inline int write_env(struct mmc *mmc, unsigned long size,
unsigned long offset, const void *buffer)
@@ -100,26 +119,38 @@ int saveenv(void)
char *res;
struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
u32 offset;
+ int ret;
- if (init_mmc_for_env(mmc) || mmc_get_env_addr(mmc, &offset))
+ if (init_mmc_for_env(mmc))
return 1;
+ if (mmc_get_env_addr(mmc, &offset)) {
+ ret = 1;
+ goto fini;
+ }
+
res = (char *)&env_new->data;
len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
- return 1;
+ ret = 1;
+ goto fini;
}
env_new->crc = crc32(0, &env_new->data[0], ENV_SIZE);
printf("Writing to MMC(%d)... ", CONFIG_SYS_MMC_ENV_DEV);
if (write_env(mmc, CONFIG_ENV_SIZE, offset, (u_char *)env_new)) {
puts("failed\n");
- return 1;
+ ret = 1;
+ goto fini;
}
puts("done\n");
- return 0;
+ ret = 0;
+
+fini:
+ fini_mmc_for_env(mmc);
+ return ret;
}
#endif /* CONFIG_CMD_SAVEENV */
@@ -143,13 +174,30 @@ void env_relocate_spec(void)
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
u32 offset;
+ int ret;
- if (init_mmc_for_env(mmc) || mmc_get_env_addr(mmc, &offset))
- return set_default_env(NULL);
+ if (init_mmc_for_env(mmc)) {
+ ret = 1;
+ goto err;
+ }
- if (read_env(mmc, CONFIG_ENV_SIZE, offset, buf))
- return set_default_env(NULL);
+ if (mmc_get_env_addr(mmc, &offset)) {
+ ret = 1;
+ goto fini;
+ }
+
+ if (read_env(mmc, CONFIG_ENV_SIZE, offset, buf)) {
+ ret = 1;
+ goto fini;
+ }
env_import(buf, 1);
+ ret = 0;
+
+fini:
+ fini_mmc_for_env(mmc);
+err:
+ if (ret)
+ set_default_env(NULL);
#endif
}
diff --git a/common/env_nand.c b/common/env_nand.c
index e635472..79e8033 100644
--- a/common/env_nand.c
+++ b/common/env_nand.c
@@ -226,7 +226,7 @@ int saveenv(void)
int saveenv(void)
{
int ret = 0;
- ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, sizeof(env_t));
+ ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
ssize_t len;
char *res;
nand_erase_options_t nand_erase_options;
diff --git a/common/env_remote.c b/common/env_remote.c
index 3bf0f95..a7b147b 100644
--- a/common/env_remote.c
+++ b/common/env_remote.c
@@ -62,8 +62,8 @@ int env_init(void)
#ifdef CONFIG_CMD_SAVEENV
int saveenv(void)
{
-#ifdef CONFIG_SRIOBOOT_SLAVE
- printf("Can not support the 'saveenv' when boot from SRIO!\n");
+#ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE
+ printf("Can not support the 'saveenv' when boot from SRIO or PCIE!\n");
return 1;
#else
return 0;
diff --git a/common/image.c b/common/image.c
index 70a112d..f084d2b 100644
--- a/common/image.c
+++ b/common/image.c
@@ -143,6 +143,7 @@ static const table_entry_t uimage_type[] = {
{ IH_TYPE_INVALID, NULL, "Invalid Image", },
{ IH_TYPE_MULTI, "multi", "Multi-File Image", },
{ IH_TYPE_OMAPIMAGE, "omapimage", "TI OMAP SPL With GP CH",},
+ { IH_TYPE_PBLIMAGE, "pblimage", "Freescale PBL Boot Image",},
{ IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
{ IH_TYPE_SCRIPT, "script", "Script", },
{ IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
diff --git a/common/usb_hub.c b/common/usb_hub.c
index f35ad95..32750e8 100644
--- a/common/usb_hub.c
+++ b/common/usb_hub.c
@@ -43,6 +43,7 @@
#include <common.h>
#include <command.h>
#include <asm/processor.h>
+#include <asm/unaligned.h>
#include <linux/ctype.h>
#include <asm/byteorder.h>
#include <asm/unaligned.h>
@@ -269,6 +270,7 @@ static int usb_hub_configure(struct usb_device *dev)
int i;
ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, USB_BUFSIZ);
unsigned char *bitmap;
+ short hubCharacteristics;
struct usb_hub_descriptor *descriptor;
struct usb_hub_device *hub;
#ifdef USB_HUB_DEBUG
@@ -304,8 +306,9 @@ static int usb_hub_configure(struct usb_device *dev)
}
memcpy((unsigned char *)&hub->desc, buffer, descriptor->bLength);
/* adjust 16bit values */
- hub->desc.wHubCharacteristics =
- le16_to_cpu(descriptor->wHubCharacteristics);
+ put_unaligned(le16_to_cpu(get_unaligned(
+ &descriptor->wHubCharacteristics)),
+ &hub->desc.wHubCharacteristics);
/* set the bitmap */
bitmap = (unsigned char *)&hub->desc.DeviceRemovable[0];
/* devices not removable by default */
@@ -322,7 +325,8 @@ static int usb_hub_configure(struct usb_device *dev)
dev->maxchild = descriptor->bNbrPorts;
USB_HUB_PRINTF("%d ports detected\n", dev->maxchild);
- switch (hub->desc.wHubCharacteristics & HUB_CHAR_LPSM) {
+ hubCharacteristics = get_unaligned(&hub->desc.wHubCharacteristics);
+ switch (hubCharacteristics & HUB_CHAR_LPSM) {
case 0x00:
USB_HUB_PRINTF("ganged power switching\n");
break;
@@ -335,12 +339,12 @@ static int usb_hub_configure(struct usb_device *dev)
break;
}
- if (hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND)
+ if (hubCharacteristics & HUB_CHAR_COMPOUND)
USB_HUB_PRINTF("part of a compound device\n");
else
USB_HUB_PRINTF("standalone hub\n");
- switch (hub->desc.wHubCharacteristics & HUB_CHAR_OCPM) {
+ switch (hubCharacteristics & HUB_CHAR_OCPM) {
case 0x00:
USB_HUB_PRINTF("global over-current protection\n");
break;