[U-Boot] [PATCH 1/7] ide: Add printf format string for CONFIG_SYS_64BIT_LBA option

From: Gabe Black gabeblack@chromium.org
The size of an LBA type changes depending on this option. We need to use a different printf() string in each case, so create a define for this.
Signed-off-by: Gabe Black gabeblack@chromium.org Signed-off-by: Simon Glass sjg@chromium.org --- include/ide.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/include/ide.h b/include/ide.h index 385e909..18d63b2 100644 --- a/include/ide.h +++ b/include/ide.h @@ -42,8 +42,10 @@
#ifdef CONFIG_SYS_64BIT_LBA typedef uint64_t lbaint_t; +#define LBAF "%llx" #else typedef ulong lbaint_t; +#define LBAF "%lx" #endif
/*

From: Gabe Black gabeblack@chromium.org
usb_storage wouldn't compile when the CONFIG_SYS_64BIT_LBA option is turned on because the used fixed size data types in their exported functions when they should have used lbaint_t for the block count parameter. That meant that when the sizes happened to be the same, when using a 28 bit LBA, the driver would build, but when it wasn't, a 48 bit LBA, things broke.
This change adjusts the signatures to use the right type and makes small adjustments in the affected functions.
Signed-off-by: Gabe Black gabeblack@chromium.org Signed-off-by: Simon Glass sjg@chromium.org --- common/usb_storage.c | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/common/usb_storage.c b/common/usb_storage.c index 950451e..0c2a4c7 100644 --- a/common/usb_storage.c +++ b/common/usb_storage.c @@ -179,9 +179,9 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *us, int usb_storage_probe(struct usb_device *dev, unsigned int ifnum, struct us_data *ss); unsigned long usb_stor_read(int device, unsigned long blknr, - unsigned long blkcnt, void *buffer); + lbaint_t blkcnt, void *buffer); unsigned long usb_stor_write(int device, unsigned long blknr, - unsigned long blkcnt, const void *buffer); + lbaint_t blkcnt, const void *buffer); struct usb_device * usb_get_dev_index(int index); void uhci_show_temp_int_td(void);
@@ -1053,9 +1053,10 @@ static void usb_bin_fixup(struct usb_device_descriptor descriptor, #endif /* CONFIG_USB_BIN_FIXUP */
unsigned long usb_stor_read(int device, unsigned long blknr, - unsigned long blkcnt, void *buffer) + lbaint_t blkcnt, void *buffer) { - unsigned long start, blks, buf_addr; + lbaint_t start, blks; + uintptr_t buf_addr; unsigned short smallblks; struct usb_device *dev; struct us_data *ss; @@ -1084,7 +1085,7 @@ unsigned long usb_stor_read(int device, unsigned long blknr, start = blknr; blks = blkcnt;
- USB_STOR_PRINTF("\nusb_read: dev %d startblk %lx, blccnt %lx" + USB_STOR_PRINTF("\nusb_read: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n", device, start, blks, buf_addr);
do { @@ -1114,7 +1115,8 @@ retry_it: } while (blks != 0); ss->flags &= ~USB_READY;
- USB_STOR_PRINTF("usb_read: end startblk %lx, blccnt %x buffer %lx\n", + USB_STOR_PRINTF("usb_read: end startblk " LBAF + ", blccnt %x buffer %lx\n", start, smallblks, buf_addr);
usb_disable_asynch(0); /* asynch transfer allowed */ @@ -1124,9 +1126,10 @@ retry_it: }
unsigned long usb_stor_write(int device, unsigned long blknr, - unsigned long blkcnt, const void *buffer) + lbaint_t blkcnt, const void *buffer) { - unsigned long start, blks, buf_addr; + lbaint_t start, blks; + uintptr_t buf_addr; unsigned short smallblks; struct usb_device *dev; struct us_data *ss; @@ -1156,7 +1159,7 @@ unsigned long usb_stor_write(int device, unsigned long blknr, start = blknr; blks = blkcnt;
- USB_STOR_PRINTF("\nusb_write: dev %d startblk %lx, blccnt %lx" + USB_STOR_PRINTF("\nusb_write: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n", device, start, blks, buf_addr);
do { @@ -1188,7 +1191,8 @@ retry_it: } while (blks != 0); ss->flags &= ~USB_READY;
- USB_STOR_PRINTF("usb_write: end startblk %lx, blccnt %x buffer %lx\n", + USB_STOR_PRINTF("usb_write: end startblk " LBAF + ", blccnt %x buffer %lx\n", start, smallblks, buf_addr);
usb_disable_asynch(0); /* asynch transfer allowed */

Dear Simon Glass,
From: Gabe Black gabeblack@chromium.org
usb_storage wouldn't compile when the CONFIG_SYS_64BIT_LBA option is turned on because the used fixed size data types in their exported functions when they should have used lbaint_t for the block count parameter. That meant that when the sizes happened to be the same, when using a 28 bit LBA, the driver would build, but when it wasn't, a 48 bit LBA, things broke.
Reviewed-by: Marek Vasut marex@denx.de
This change adjusts the signatures to use the right type and makes small adjustments in the affected functions.
Signed-off-by: Gabe Black gabeblack@chromium.org Signed-off-by: Simon Glass sjg@chromium.org
common/usb_storage.c | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/common/usb_storage.c b/common/usb_storage.c index 950451e..0c2a4c7 100644 --- a/common/usb_storage.c +++ b/common/usb_storage.c @@ -179,9 +179,9 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *us, int usb_storage_probe(struct usb_device *dev, unsigned int ifnum, struct us_data *ss); unsigned long usb_stor_read(int device, unsigned long blknr,
unsigned long blkcnt, void *buffer);
lbaint_t blkcnt, void *buffer);
unsigned long usb_stor_write(int device, unsigned long blknr,
unsigned long blkcnt, const void *buffer);
lbaint_t blkcnt, const void *buffer);
struct usb_device * usb_get_dev_index(int index); void uhci_show_temp_int_td(void);
@@ -1053,9 +1053,10 @@ static void usb_bin_fixup(struct usb_device_descriptor descriptor, #endif /* CONFIG_USB_BIN_FIXUP */
unsigned long usb_stor_read(int device, unsigned long blknr,
unsigned long blkcnt, void *buffer)
lbaint_t blkcnt, void *buffer)
{
- unsigned long start, blks, buf_addr;
- lbaint_t start, blks;
- uintptr_t buf_addr; unsigned short smallblks; struct usb_device *dev; struct us_data *ss;
@@ -1084,7 +1085,7 @@ unsigned long usb_stor_read(int device, unsigned long blknr, start = blknr; blks = blkcnt;
- USB_STOR_PRINTF("\nusb_read: dev %d startblk %lx, blccnt %lx"
USB_STOR_PRINTF("\nusb_read: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n", device, start, blks, buf_addr);
do {
@@ -1114,7 +1115,8 @@ retry_it: } while (blks != 0); ss->flags &= ~USB_READY;
- USB_STOR_PRINTF("usb_read: end startblk %lx, blccnt %x buffer %lx\n",
USB_STOR_PRINTF("usb_read: end startblk " LBAF
", blccnt %x buffer %lx\n", start, smallblks, buf_addr);
usb_disable_asynch(0); /* asynch transfer allowed */
@@ -1124,9 +1126,10 @@ retry_it: }
unsigned long usb_stor_write(int device, unsigned long blknr,
unsigned long blkcnt, const void *buffer)
lbaint_t blkcnt, const void *buffer)
{
- unsigned long start, blks, buf_addr;
- lbaint_t start, blks;
- uintptr_t buf_addr; unsigned short smallblks; struct usb_device *dev; struct us_data *ss;
@@ -1156,7 +1159,7 @@ unsigned long usb_stor_write(int device, unsigned long blknr, start = blknr; blks = blkcnt;
- USB_STOR_PRINTF("\nusb_write: dev %d startblk %lx, blccnt %lx"
USB_STOR_PRINTF("\nusb_write: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n", device, start, blks, buf_addr);
do {
@@ -1188,7 +1191,8 @@ retry_it: } while (blks != 0); ss->flags &= ~USB_READY;
- USB_STOR_PRINTF("usb_write: end startblk %lx, blccnt %x buffer %lx\n",
USB_STOR_PRINTF("usb_write: end startblk " LBAF
", blccnt %x buffer %lx\n", start, smallblks, buf_addr);
usb_disable_asynch(0); /* asynch transfer allowed */

From: Gabe Black gabeblack@chromium.org
Currently, if the disk partition code is compiled with all of the parition types compiled out, it hits an #error which stops the build. This change adjusts that file so that those functions will fall through to their defaults in those cases instead of breaking the build. These functions are needed because other code calls them, and that code is needed because other config options are overly broad and bring in support we don't need along with support we do.
Also reduce repetition of the 6-term #ifdef throughout the file.
Signed-off-by: Gabe Black gabeblack@chromium.org Signed-off-by: Simon Glass sjg@chromium.org --- disk/part.c | 50 +++++++++++++++++--------------------------------- 1 files changed, 17 insertions(+), 33 deletions(-)
diff --git a/disk/part.c b/disk/part.c index 3022969..ec50516 100644 --- a/disk/part.c +++ b/disk/part.c @@ -35,12 +35,15 @@ #define PRINTF(fmt,args...) #endif
+/* Rather than repeat this expression each time, add a define for it */ #if (defined(CONFIG_CMD_IDE) || \ defined(CONFIG_CMD_SATA) || \ defined(CONFIG_CMD_SCSI) || \ defined(CONFIG_CMD_USB) || \ defined(CONFIG_MMC) || \ defined(CONFIG_SYSTEMACE) ) +#define HAVE_BLOCK_DEVICE +#endif
struct block_drvr { char *name; @@ -71,6 +74,7 @@ static const struct block_drvr block_drvr[] = {
DECLARE_GLOBAL_DATA_PTR;
+#ifdef HAVE_BLOCK_DEVICE block_dev_desc_t *get_dev(const char *ifname, int dev) { const struct block_drvr *drvr = block_drvr; @@ -104,12 +108,7 @@ block_dev_desc_t *get_dev(const char *ifname, int dev) } #endif
-#if (defined(CONFIG_CMD_IDE) || \ - defined(CONFIG_CMD_SATA) || \ - defined(CONFIG_CMD_SCSI) || \ - defined(CONFIG_CMD_USB) || \ - defined(CONFIG_MMC) || \ - defined(CONFIG_SYSTEMACE) ) +#ifdef HAVE_BLOCK_DEVICE
/* ------------------------------------------------------------------------- */ /* @@ -239,18 +238,7 @@ void dev_print (block_dev_desc_t *dev_desc) } #endif
-#if (defined(CONFIG_CMD_IDE) || \ - defined(CONFIG_CMD_SATA) || \ - defined(CONFIG_CMD_SCSI) || \ - defined(CONFIG_CMD_USB) || \ - defined(CONFIG_MMC) || \ - defined(CONFIG_SYSTEMACE) ) - -#if defined(CONFIG_MAC_PARTITION) || \ - defined(CONFIG_DOS_PARTITION) || \ - defined(CONFIG_ISO_PARTITION) || \ - defined(CONFIG_AMIGA_PARTITION) || \ - defined(CONFIG_EFI_PARTITION) +#ifdef HAVE_BLOCK_DEVICE
void init_part (block_dev_desc_t * dev_desc) { @@ -293,6 +281,12 @@ void init_part (block_dev_desc_t * dev_desc) }
+#if defined(CONFIG_MAC_PARTITION) || \ + defined(CONFIG_DOS_PARTITION) || \ + defined(CONFIG_ISO_PARTITION) || \ + defined(CONFIG_AMIGA_PARTITION) || \ + defined(CONFIG_EFI_PARTITION) + static void print_part_header (const char *type, block_dev_desc_t * dev_desc) { puts ("\nPartition Map for "); @@ -326,6 +320,8 @@ static void print_part_header (const char *type, block_dev_desc_t * dev_desc) dev_desc->dev, type); }
+#endif /* any CONFIG_..._PARTITION */ + void print_part (block_dev_desc_t * dev_desc) {
@@ -372,24 +368,12 @@ void print_part (block_dev_desc_t * dev_desc) puts ("## Unknown partition table\n"); }
- -#else /* neither MAC nor DOS nor ISO nor AMIGA nor EFI partition configured */ -# error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION -# error nor CONFIG_ISO_PARTITION nor CONFIG_AMIGA_PARTITION -# error nor CONFIG_EFI_PARTITION configured! -#endif - -#endif +#endif /* HAVE_BLOCK_DEVICE */
int get_partition_info(block_dev_desc_t *dev_desc, int part , disk_partition_t *info) { -#if defined(CONFIG_CMD_IDE) || \ - defined(CONFIG_CMD_SATA) || \ - defined(CONFIG_CMD_SCSI) || \ - defined(CONFIG_CMD_USB) || \ - defined(CONFIG_MMC) || \ - defined(CONFIG_SYSTEMACE) +#ifdef HAVE_BLOCK_DEVICE
#ifdef CONFIG_PARTITION_UUIDS /* The common case is no UUID support */ @@ -444,7 +428,7 @@ int get_partition_info(block_dev_desc_t *dev_desc, int part default: break; } -#endif +#endif /* HAVE_BLOCK_DEVICE */
return -1; }

From: Taylor Hutt thutt@chromium.org
This change addresses a few printf-formatting errors, and a typecast error.
Signed-off-by: Taylor Hutt thutt@chromium.org Signed-off-by: Simon Glass sjg@chromium.org --- disk/part_efi.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/disk/part_efi.c b/disk/part_efi.c index 264ea9c..22a1dad 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -405,7 +405,7 @@ static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc, count = le32_to_int(pgpt_head->num_partition_entries) * le32_to_int(pgpt_head->sizeof_partition_entry);
- debug("%s: count = %lu * %lu = %u\n", __func__, + debug("%s: count = %lu * %lu = %zu\n", __func__, le32_to_int(pgpt_head->num_partition_entries), le32_to_int(pgpt_head->sizeof_partition_entry), count);
@@ -415,7 +415,8 @@ static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc, }
if (count == 0 || pte == NULL) { - printf("%s: ERROR: Can't allocate 0x%X bytes for GPT Entries\n", + printf("%s: ERROR: Can't allocate 0x%zX " + "bytes for GPT Entries\n", __func__, count); return NULL; } @@ -457,7 +458,7 @@ static int is_pte_valid(gpt_entry * pte) sizeof(unused_guid.b)) == 0) {
debug("%s: Found an unused PTE GUID at 0x%08X\n", __func__, - (unsigned int)pte); + (unsigned int)(uintptr_t)pte);
return 0; } else {

From: Stefan Reinauer reinauer@chromium.org
ChromeOS uses a GPT partition table to partition the disk. However, Windows will refuse to install on a GPT partitioned disk if there is no EFI available (Even if there is an MBR, too) To hide the GPT partition table from Windows, we need to write it with a header magic other than "EFI PART". To support old and new systems, Check for the magic string "CHROMEOS" too.
Signed-off-by: Stefan Reinauer reinauer@chromium.org
Signed-off-by: Simon Glass sjg@chromium.org --- disk/part_efi.c | 3 ++- disk/part_efi.h | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/disk/part_efi.c b/disk/part_efi.c index 22a1dad..f2a2445 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -307,7 +307,8 @@ static int is_gpt_valid(block_dev_desc_t * dev_desc, unsigned long long lba, }
/* Check the GPT header signature */ - if (le64_to_int(pgpt_head->signature) != GPT_HEADER_SIGNATURE) { + if ((le64_to_int(pgpt_head->signature) != GPT_HEADER_SIGNATURE) && + (le64_to_int(pgpt_head->signature) != GPT_HEADER_SIGNATURE2)) { printf("GUID Partition Table Header signature is wrong:" "0x%llX != 0x%llX\n", (unsigned long long)le64_to_int(pgpt_head->signature), diff --git a/disk/part_efi.h b/disk/part_efi.h index 5903e7c..07e590d 100644 --- a/disk/part_efi.h +++ b/disk/part_efi.h @@ -37,7 +37,9 @@ #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE
#define GPT_BLOCK_SIZE 512 -#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL +#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL +#define GPT_HEADER_SIGNATURE2 0x534f454d4f524843ULL + #define GPT_HEADER_REVISION_V1 0x00010000 #define GPT_PRIMARY_PARTITION_TABLE_LBA 1ULL #define GPT_ENTRY_NAME "gpt"

On 10/12/2012 06:26 PM, Simon Glass wrote:
From: Stefan Reinauer reinauer@chromium.org
ChromeOS uses a GPT partition table to partition the disk. However, Windows will refuse to install on a GPT partitioned disk if there is no EFI available (Even if there is an MBR, too) To hide the GPT partition table from Windows, we need to write it with a header magic other than "EFI PART". To support old and new systems, Check for the magic string "CHROMEOS" too.
Surely if you wanted to install Windows on a disk containing ChromeOS, you would just wipe the disk and re-partition it? I suppose perhaps you're talking about dual-boot though?
Either way, it doesn't see like a good idea to be using non-standard EFI signatures - especially if the idea is to hide the GPT from Windows, and presumably then have Windows use the MBR partitions, since that will end up with a decidedly non-standard partition setup; some partitions will only be represented in the MBR (those Windows creates) and some in GPT (presumably whatever ChromeOS created before).

On Mon, Oct 15, 2012 at 8:19 AM, Stephen Warren swarren@wwwdotorg.orgwrote:
On 10/12/2012 06:26 PM, Simon Glass wrote:
From: Stefan Reinauer reinauer@chromium.org
ChromeOS uses a GPT partition table to partition the disk. However, Windows will refuse to install on a GPT partitioned disk if there is no EFI available (Even if there is an MBR, too) To hide the GPT partition table from Windows, we need to write it with a header magic other than "EFI PART". To support old and new systems, Check for the magic string "CHROMEOS" too.
Surely if you wanted to install Windows on a disk containing ChromeOS, you would just wipe the disk and re-partition it? I suppose perhaps you're talking about dual-boot though?
Yes, this is only required if we're dual-booting on Windows and ChromeOS on the same disk.
Either way, it doesn't see like a good idea to be using non-standard EFI
signatures - especially if the idea is to hide the GPT from Windows, and presumably then have Windows use the MBR partitions, since that will end up with a decidedly non-standard partition setup; some partitions will only be represented in the MBR (those Windows creates) and some in GPT (presumably whatever ChromeOS created before).
Yes, you will have to create a hybrid partition setup to make this work. It is unfortunate that Windows enforces this and there is no real way around it. This is a workaround specific to ChromeOS machines, and should be fixed differently in the long run (e.g. by using Tiano Core as a payload instead of SeaBIOS for booting Windows)
Stefan

On 10/15/2012 11:17 AM, Stefan Reinauer wrote:
On Mon, Oct 15, 2012 at 8:19 AM, Stephen Warren <swarren@wwwdotorg.org mailto:swarren@wwwdotorg.org> wrote:
On 10/12/2012 06:26 PM, Simon Glass wrote: > From: Stefan Reinauer <reinauer@chromium.org <mailto:reinauer@chromium.org>> > > ChromeOS uses a GPT partition table to partition the disk. > However, Windows will refuse to install on a GPT partitioned > disk if there is no EFI available (Even if there is an MBR, too) > To hide the GPT partition table from Windows, we need to write > it with a header magic other than "EFI PART". To support old > and new systems, Check for the magic string "CHROMEOS" too. Surely if you wanted to install Windows on a disk containing ChromeOS, you would just wipe the disk and re-partition it? I suppose perhaps you're talking about dual-boot though?
Yes, this is only required if we're dual-booting on Windows and ChromeOS on the same disk.
Either way, it doesn't see like a good idea to be using non-standard EFI signatures - especially if the idea is to hide the GPT from Windows, and presumably then have Windows use the MBR partitions, since that will end up with a decidedly non-standard partition setup; some partitions will only be represented in the MBR (those Windows creates) and some in GPT (presumably whatever ChromeOS created before).
Yes, you will have to create a hybrid partition setup to make this work. It is unfortunate that Windows enforces this and there is no real way around it.
Is this something common that someone using upstream U-Boot would care about, or is it something specific that should be contained in a ChromeOS U-Boot tree? I'm worried that applying this patch will just (a) support a situation that'll be very confusing to the user and (b) slightly de-stabilizes the U-Boot code in other situations by allowing non-standard (perhaps considered corrupt even) EFI partition tables.
Still, I suppose I won't be impacted by case (a) so I probably shouldn't care much about it, and case (b) hopefully won't cause practical problems (famous last words), so I'm not opposed to this patch, it just feels slightly risky to me.

On Fri, Oct 12, 2012 at 05:26:10PM -0700, Simon Glass wrote:
From: Stefan Reinauer reinauer@chromium.org
ChromeOS uses a GPT partition table to partition the disk. However, Windows will refuse to install on a GPT partitioned disk if there is no EFI available (Even if there is an MBR, too) To hide the GPT partition table from Windows, we need to write it with a header magic other than "EFI PART". To support old and new systems, Check for the magic string "CHROMEOS" too.
Signed-off-by: Stefan Reinauer reinauer@chromium.org
Signed-off-by: Simon Glass sjg@chromium.org
Stephen brings up a good point in that this is a ChromeOS specific work-around for a real issue. With my TI hat on, we've been pushing the idea that our releases will be mainline + patches, and those patches will be things that are either backports, works in progress or simply not mainlineable patches (enforce a CONFIG_BOOTDELAY of 3 for all boards, add mojo to just load uImages to their XIP address, etc). In my mind, this patch falls into the last grouping and I hope you're OK with just holding onto this as a not appropriate for mainline change.
The rest of the series looks fine and no need to respin, I'll just skip this patch when I pick it up, assuming no further changes are needed elsewhere.

On Wed, Oct 17, 2012 at 4:36 PM, Tom Rini trini@ti.com wrote:
Stephen brings up a good point in that this is a ChromeOS specific work-around for a real issue. With my TI hat on, we've been pushing the idea that our releases will be mainline + patches, and those patches will be things that are either backports, works in progress or simply not mainlineable patches (enforce a CONFIG_BOOTDELAY of 3 for all boards, add mojo to just load uImages to their XIP address, etc). In my mind, this patch falls into the last grouping and I hope you're OK with just holding onto this as a not appropriate for mainline change.
Yes, it's exactly that kind of change.
The rest of the series looks fine and no need to respin, I'll just skip this patch when I pick it up, assuming no further changes are needed elsewhere.
Great! Thanks a lot
Stefan

Hi Tom,
On Wed, Oct 17, 2012 at 4:39 PM, Stefan Reinauer reinauer@google.com wrote:
On Wed, Oct 17, 2012 at 4:36 PM, Tom Rini trini@ti.com wrote:
Stephen brings up a good point in that this is a ChromeOS specific work-around for a real issue. With my TI hat on, we've been pushing the idea that our releases will be mainline + patches, and those patches will be things that are either backports, works in progress or simply not mainlineable patches (enforce a CONFIG_BOOTDELAY of 3 for all boards, add mojo to just load uImages to their XIP address, etc). In my mind, this patch falls into the last grouping and I hope you're OK with just holding onto this as a not appropriate for mainline change.
Yes, it's exactly that kind of change.
The rest of the series looks fine and no need to respin, I'll just skip this patch when I pick it up, assuming no further changes are needed elsewhere.
Great! Thanks a lot
Good with me too, thanks Tom.
Stefan
Regards, Simon

From: Gabe Black gabeblack@chromium.org
This change adds CBFS support and some commands to use it to u-boot. These commands are:
cbfsinit - Initialize CBFS support and pull all metadata into RAM. The end of the ROM is an optional parameter which defaults to the standard 0xffffffff and can be used to support multiple CBFSes in a system. The last one set up with cbfsinit is the one that will be used.
cbfsinfo - Print information from the CBFS header.
cbfsls - Print out the size, type, and name of all the files in the current CBFS. Recognized types are translated into symbolic names.
cbfsload - Load a file from CBFS into memory. Like the similar command for fat filesystems, you can optionally provide a maximum size.
Support for CBFS is compiled in when the CONFIG_CMD_CBFS option is specified.
The CBFS driver can also be used programmatically from within u-boot.
If u-boot needs something out of CBFS very early before the heap is configured, it won't be able to use the normal CBFS support which caches some information in memory it allocates from the heap. The cbfs_file_find_uncached function searches a CBFS instance without touching the heap.
Signed-off-by: Gabe Black gabeblack@google.com Signed-off-by: Stefan Reinauer reinauer@chromium.org Signed-off-by: Simon Glass sjg@chromium.org --- Makefile | 3 +- README | 7 + common/Makefile | 1 + common/cmd_cbfs.c | 214 +++++++++++++++++++++++++++++++++ fs/Makefile | 1 + fs/cbfs/Makefile | 43 +++++++ fs/cbfs/cbfs.c | 339 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/cbfs.h | 181 ++++++++++++++++++++++++++++ 8 files changed, 788 insertions(+), 1 deletions(-) create mode 100644 common/cmd_cbfs.c create mode 100644 fs/cbfs/Makefile create mode 100644 fs/cbfs/cbfs.c create mode 100644 include/cbfs.h
diff --git a/Makefile b/Makefile index 90e99af..d2cfac0 100644 --- a/Makefile +++ b/Makefile @@ -242,7 +242,8 @@ LIBS-y += drivers/net/npe/libnpe.o endif LIBS-$(CONFIG_OF_EMBED) += dts/libdts.o LIBS-y += arch/$(ARCH)/lib/lib$(ARCH).o -LIBS-y += fs/cramfs/libcramfs.o \ +LIBS-y += fs/cbfs/libcbfs.o \ + fs/cramfs/libcramfs.o \ fs/ext4/libext4fs.o \ fs/fat/libfat.o \ fs/fdos/libfdos.o \ diff --git a/README b/README index 9804cea..f5adcc0 100644 --- a/README +++ b/README @@ -1316,6 +1316,13 @@ The following options need to be configured: This will also enable the command "fatwrite" enabling the user to write files to FAT.
+CBFS (Coreboot Filesystem) support + CONFIG_CMD_CBFS + + Define this to enable support for reading from a Coreboot + filesystem. Available commands are cbfsinit, cbfsinfo, cbfsls + and cbfsload. + - Keyboard Support: CONFIG_ISA_KEYBOARD
diff --git a/common/Makefile b/common/Makefile index a4eb477..7cb0e88 100644 --- a/common/Makefile +++ b/common/Makefile @@ -69,6 +69,7 @@ COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o cmd_bedbug.o COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o COBJS-$(CONFIG_CMD_CACHE) += cmd_cache.o +COBJS-$(CONFIG_CMD_CBFS) += cmd_cbfs.o COBJS-$(CONFIG_CMD_CONSOLE) += cmd_console.o COBJS-$(CONFIG_CMD_CPLBINFO) += cmd_cplbinfo.o COBJS-$(CONFIG_DATAFLASH_MMC_SELECT) += cmd_dataflash_mmc_mux.o diff --git a/common/cmd_cbfs.c b/common/cmd_cbfs.c new file mode 100644 index 0000000..3b6cfd8 --- /dev/null +++ b/common/cmd_cbfs.c @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. + * + * 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 + */ + +/* + * CBFS commands + */ +#include <common.h> +#include <command.h> +#include <cbfs.h> + +int do_cbfs_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{ + uintptr_t end_of_rom = 0xffffffff; + char *ep; + + if (argc > 2) { + printf("usage: cbfsls [end of rom]>\n"); + return 0; + } + if (argc == 2) { + end_of_rom = (int)simple_strtoul(argv[1], &ep, 16); + if (*ep) { + puts("\n** Invalid end of ROM **\n"); + return 1; + } + } + file_cbfs_init(end_of_rom); + if (file_cbfs_result != CBFS_SUCCESS) { + printf("%s.\n", file_cbfs_error()); + return 1; + } + return 0; +} + +U_BOOT_CMD( + cbfsinit, 2, 0, do_cbfs_init, + "initialize the cbfs driver", + "[end of rom]\n" + " - Initialize the cbfs driver. The optional 'end of rom'\n" + " parameter specifies where the end of the ROM is that the\n" + " CBFS is in. It defaults to 0xFFFFFFFF\n" +); + +int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{ + const struct cbfs_cachenode *file; + unsigned long offset; + unsigned long count; + char buf[12]; + long size; + + if (argc < 3) { + printf("usage: cbfsload <addr> <filename> [bytes]\n"); + return 1; + } + + /* parse offset and count */ + offset = simple_strtoul(argv[1], NULL, 16); + if (argc == 4) + count = simple_strtoul(argv[3], NULL, 16); + else + count = 0; + + file = file_cbfs_find(argv[2]); + if (!file) { + if (file_cbfs_result == CBFS_FILE_NOT_FOUND) + printf("%s: %s\n", file_cbfs_error(), argv[2]); + else + printf("%s.\n", file_cbfs_error()); + return 1; + } + + printf("reading %s\n", file_cbfs_name(file)); + + size = file_cbfs_read(file, (void *)offset, count); + + printf("\n%ld bytes read\n", size); + + sprintf(buf, "%lX", size); + setenv("filesize", buf); + + return 0; +} + +U_BOOT_CMD( + cbfsload, 4, 0, do_cbfs_fsload, + "load binary file from a cbfs filesystem", + "<addr> <filename> [bytes]\n" + " - load binary file 'filename' from the cbfs to address 'addr'\n" +); + +int do_cbfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{ + const struct cbfs_cachenode *file = file_cbfs_get_first(); + int files = 0; + + if (!file) { + printf("%s.\n", file_cbfs_error()); + return 1; + } + + printf(" size type name\n"); + printf("------------------------------------------\n"); + while (file) { + u32 type = file_cbfs_type(file); + char *type_name = NULL; + const char *filename = file_cbfs_name(file); + + printf(" %8d", file_cbfs_size(file)); + + switch (type) { + case CBFS_TYPE_STAGE: + type_name = "stage"; + break; + case CBFS_TYPE_PAYLOAD: + type_name = "payload"; + break; + case CBFS_TYPE_OPTIONROM: + type_name = "option rom"; + break; + case CBFS_TYPE_BOOTSPLASH: + type_name = "boot splash"; + break; + case CBFS_TYPE_RAW: + type_name = "raw"; + break; + case CBFS_TYPE_VSA: + type_name = "vsa"; + break; + case CBFS_TYPE_MBI: + type_name = "mbi"; + break; + case CBFS_TYPE_MICROCODE: + type_name = "microcode"; + break; + case CBFS_COMPONENT_CMOS_DEFAULT: + type_name = "cmos default"; + break; + case CBFS_COMPONENT_CMOS_LAYOUT: + type_name = "cmos layout"; + break; + case -1UL: + type_name = "null"; + break; + } + if (type_name) + printf(" %16s", type_name); + else + printf(" %16d", type); + + if (filename[0]) + printf(" %s\n", filename); + else + printf(" %s\n", "(empty)"); + file_cbfs_get_next(&file); + files++; + } + + printf("\n%d file(s)\n\n", files); + return 0; +} + +U_BOOT_CMD( + cbfsls, 1, 1, do_cbfs_ls, + "list files", + " - list the files in the cbfs\n" +); + +int do_cbfs_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{ + const struct cbfs_header *header = file_cbfs_get_header(); + + if (!header) { + printf("%s.\n", file_cbfs_error()); + return 1; + } + + printf("\n"); + printf("CBFS version: %#x\n", header->version); + printf("ROM size: %#x\n", header->rom_size); + printf("Boot block size: %#x\n", header->boot_block_size); + printf("CBFS size: %#x\n", + header->rom_size - header->boot_block_size - header->offset); + printf("Alignment: %d\n", header->align); + printf("Offset: %#x\n", header->offset); + printf("\n"); + + return 0; +} + +U_BOOT_CMD( + cbfsinfo, 1, 1, do_cbfs_fsinfo, + "print information about filesystem", + " - print information about the cbfs filesystem\n" +); diff --git a/fs/Makefile b/fs/Makefile index 901e189..b4db606 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -22,6 +22,7 @@ # #
+subdirs-$(CONFIG_CMD_CBFS) += cbfs subdirs-$(CONFIG_CMD_CRAMFS) := cramfs subdirs-$(CONFIG_CMD_EXT4) += ext4 ifndef CONFIG_CMD_EXT4 diff --git a/fs/cbfs/Makefile b/fs/cbfs/Makefile new file mode 100644 index 0000000..2be8a68 --- /dev/null +++ b/fs/cbfs/Makefile @@ -0,0 +1,43 @@ +# +# 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)libcbfs.o + +COBJS-$(CONFIG_CMD_CBFS) := cbfs.o + +SRCS := $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS-y)) + +all: $(LIB) + +$(LIB): $(obj).depend $(OBJS) + $(call cmd_link_o_target, $(OBJS)) + + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c new file mode 100644 index 0000000..cae6d56 --- /dev/null +++ b/fs/cbfs/cbfs.c @@ -0,0 +1,339 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. + * + * 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 <cbfs.h> +#include <malloc.h> +#include <asm/byteorder.h> + +enum cbfs_result file_cbfs_result; + +const char *file_cbfs_error(void) +{ + switch (file_cbfs_result) { + case CBFS_SUCCESS: + return "Success"; + case CBFS_NOT_INITIALIZED: + return "CBFS not initialized"; + case CBFS_BAD_HEADER: + return "Bad CBFS header"; + case CBFS_BAD_FILE: + return "Bad CBFS file"; + case CBFS_FILE_NOT_FOUND: + return "File not found"; + default: + return "Unknown"; + } +} + + +static const u32 good_magic = 0x4f524243; +static const u8 good_file_magic[] = "LARCHIVE"; + + +static int initialized; +static struct cbfs_header cbfs_header; +static struct cbfs_cachenode *file_cache; + +/* Do endian conversion on the CBFS header structure. */ +static void swap_header(struct cbfs_header *dest, struct cbfs_header *src) +{ + dest->magic = be32_to_cpu(src->magic); + dest->version = be32_to_cpu(src->version); + dest->rom_size = be32_to_cpu(src->rom_size); + dest->boot_block_size = be32_to_cpu(src->boot_block_size); + dest->align = be32_to_cpu(src->align); + dest->offset = be32_to_cpu(src->offset); +} + +/* Do endian conversion on a CBFS file header. */ +static void swap_file_header(struct cbfs_fileheader *dest, + const struct cbfs_fileheader *src) +{ + memcpy(&dest->magic, &src->magic, sizeof(dest->magic)); + dest->len = be32_to_cpu(src->len); + dest->type = be32_to_cpu(src->type); + dest->checksum = be32_to_cpu(src->checksum); + dest->offset = be32_to_cpu(src->offset); +} + +/* + * Given a starting position in memory, scan forward, bounded by a size, and + * find the next valid CBFS file. No memory is allocated by this function. The + * caller is responsible for allocating space for the new file structure. + * + * @param start The location in memory to start from. + * @param size The size of the memory region to search. + * @param align The alignment boundaries to check on. + * @param newNode A pointer to the file structure to load. + * @param used A pointer to the count of of bytes scanned through, + * including the file if one is found. + * + * @return 1 if a file is found, 0 if one isn't. + */ +static int file_cbfs_next_file(u8 *start, u32 size, u32 align, + struct cbfs_cachenode *newNode, u32 *used) +{ + struct cbfs_fileheader header; + + *used = 0; + + while (size >= align) { + const struct cbfs_fileheader *fileHeader = + (const struct cbfs_fileheader *)start; + u32 name_len; + u32 step; + + /* Check if there's a file here. */ + if (memcmp(good_file_magic, &(fileHeader->magic), + sizeof(fileHeader->magic))) { + *used += align; + size -= align; + start += align; + continue; + } + + swap_file_header(&header, fileHeader); + if (header.offset < sizeof(const struct cbfs_cachenode *) || + header.offset > header.len) { + file_cbfs_result = CBFS_BAD_FILE; + return -1; + } + newNode->next = NULL; + newNode->type = header.type; + newNode->data = start + header.offset; + newNode->data_length = header.len; + name_len = header.offset - sizeof(struct cbfs_cachenode *); + newNode->name = (char *)fileHeader + + sizeof(struct cbfs_cachenode *); + newNode->name_length = name_len; + newNode->checksum = header.checksum; + + step = header.len; + if (step % align) + step = step + align - step % align; + + *used += step; + return 1; + } + return 0; +} + +/* Look through a CBFS instance and copy file metadata into regular memory. */ +static void file_cbfs_fill_cache(u8 *start, u32 size, u32 align) +{ + struct cbfs_cachenode *cache_node; + struct cbfs_cachenode *newNode; + struct cbfs_cachenode **cache_tail = &file_cache; + + /* Clear out old information. */ + cache_node = file_cache; + while (cache_node) { + struct cbfs_cachenode *oldNode = cache_node; + cache_node = cache_node->next; + free(oldNode); + } + file_cache = NULL; + + while (size >= align) { + int result; + u32 used; + + newNode = (struct cbfs_cachenode *) + malloc(sizeof(struct cbfs_cachenode)); + result = file_cbfs_next_file(start, size, align, + newNode, &used); + + if (result < 0) { + free(newNode); + return; + } else if (result == 0) { + free(newNode); + break; + } + *cache_tail = newNode; + cache_tail = &newNode->next; + + size -= used; + start += used; + } + file_cbfs_result = CBFS_SUCCESS; +} + +/* Get the CBFS header out of the ROM and do endian conversion. */ +static int file_cbfs_load_header(uintptr_t end_of_rom, + struct cbfs_header *header) +{ + struct cbfs_header *header_in_rom; + + header_in_rom = (struct cbfs_header *)(uintptr_t) + *(u32 *)(end_of_rom - 3); + swap_header(header, header_in_rom); + + if (header->magic != good_magic || header->offset > + header->rom_size - header->boot_block_size) { + file_cbfs_result = CBFS_BAD_HEADER; + return 1; + } + return 0; +} + +void file_cbfs_init(uintptr_t end_of_rom) +{ + u8 *start_of_rom; + initialized = 0; + + if (file_cbfs_load_header(end_of_rom, &cbfs_header)) + return; + + start_of_rom = (u8 *)(end_of_rom + 1 - cbfs_header.rom_size); + + file_cbfs_fill_cache(start_of_rom + cbfs_header.offset, + cbfs_header.rom_size, cbfs_header.align); + if (file_cbfs_result == CBFS_SUCCESS) + initialized = 1; +} + +const struct cbfs_header *file_cbfs_get_header(void) +{ + if (initialized) { + file_cbfs_result = CBFS_SUCCESS; + return &cbfs_header; + } else { + file_cbfs_result = CBFS_NOT_INITIALIZED; + return NULL; + } +} + +const struct cbfs_cachenode *file_cbfs_get_first(void) +{ + if (!initialized) { + file_cbfs_result = CBFS_NOT_INITIALIZED; + return NULL; + } else { + file_cbfs_result = CBFS_SUCCESS; + return file_cache; + } +} + +void file_cbfs_get_next(const struct cbfs_cachenode **file) +{ + if (!initialized) { + file_cbfs_result = CBFS_NOT_INITIALIZED; + file = NULL; + return; + } + + if (*file) + *file = (*file)->next; + file_cbfs_result = CBFS_SUCCESS; +} + +const struct cbfs_cachenode *file_cbfs_find(const char *name) +{ + struct cbfs_cachenode *cache_node = file_cache; + + if (!initialized) { + file_cbfs_result = CBFS_NOT_INITIALIZED; + return NULL; + } + + while (cache_node) { + if (!strcmp(name, cache_node->name)) + break; + cache_node = cache_node->next; + } + if (!cache_node) + file_cbfs_result = CBFS_FILE_NOT_FOUND; + else + file_cbfs_result = CBFS_SUCCESS; + + return cache_node; +} + +const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom, + const char *name) +{ + u8 *start; + u32 size; + u32 align; + static struct cbfs_cachenode node; + + if (file_cbfs_load_header(end_of_rom, &cbfs_header)) + return NULL; + + start = (u8 *)(end_of_rom + 1 - cbfs_header.rom_size); + size = cbfs_header.rom_size; + align = cbfs_header.align; + + while (size >= align) { + int result; + u32 used; + + result = file_cbfs_next_file(start, size, align, &node, &used); + + if (result < 0) + return NULL; + else if (result == 0) + break; + + if (!strcmp(name, node.name)) + return &node; + + size -= used; + start += used; + } + file_cbfs_result = CBFS_FILE_NOT_FOUND; + return NULL; +} + +const char *file_cbfs_name(const struct cbfs_cachenode *file) +{ + file_cbfs_result = CBFS_SUCCESS; + return file->name; +} + +u32 file_cbfs_size(const struct cbfs_cachenode *file) +{ + file_cbfs_result = CBFS_SUCCESS; + return file->data_length; +} + +u32 file_cbfs_type(const struct cbfs_cachenode *file) +{ + file_cbfs_result = CBFS_SUCCESS; + return file->type; +} + +long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer, + unsigned long maxsize) +{ + u32 size; + + size = file->data_length; + if (maxsize && size > maxsize) + size = maxsize; + + memcpy(buffer, file->data, size); + + file_cbfs_result = CBFS_SUCCESS; + return size; +} diff --git a/include/cbfs.h b/include/cbfs.h new file mode 100644 index 0000000..6ea3f35 --- /dev/null +++ b/include/cbfs.h @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. + * + * 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 __CBFS_H +#define __CBFS_H + +#include <compiler.h> +#include <linux/compiler.h> + +enum cbfs_result { + CBFS_SUCCESS = 0, + CBFS_NOT_INITIALIZED, + CBFS_BAD_HEADER, + CBFS_BAD_FILE, + CBFS_FILE_NOT_FOUND +}; + +enum cbfs_filetype { + CBFS_TYPE_STAGE = 0x10, + CBFS_TYPE_PAYLOAD = 0x20, + CBFS_TYPE_OPTIONROM = 0x30, + CBFS_TYPE_BOOTSPLASH = 0x40, + CBFS_TYPE_RAW = 0x50, + CBFS_TYPE_VSA = 0x51, + CBFS_TYPE_MBI = 0x52, + CBFS_TYPE_MICROCODE = 0x53, + CBFS_COMPONENT_CMOS_DEFAULT = 0xaa, + CBFS_COMPONENT_CMOS_LAYOUT = 0x01aa +}; + +struct cbfs_header { + u32 magic; + u32 version; + u32 rom_size; + u32 boot_block_size; + u32 align; + u32 offset; + u32 pad[2]; +} __packed; + +struct cbfs_fileheader { + u8 magic[8]; + u32 len; + u32 type; + u32 checksum; + u32 offset; +} __packed; + +struct cbfs_cachenode { + struct cbfs_cachenode *next; + u32 type; + void *data; + u32 data_length; + char *name; + u32 name_length; + u32 checksum; +} __packed; + +extern enum cbfs_result file_cbfs_result; + +/* + * Return a string describing the most recent error condition. + * + * @return A pointer to the constant string. + */ +const char *file_cbfs_error(void); + +/* + * Initialize the CBFS driver and load metadata into RAM. + * + * @param end_of_rom Points to the end of the ROM the CBFS should be read + * from. + */ +void file_cbfs_init(uintptr_t end_of_rom); + +/* + * Get the header structure for the current CBFS. + * + * @return A pointer to the constant structure, or NULL if there is none. + */ +const struct cbfs_header *file_cbfs_get_header(void); + +/* + * Get a handle for the first file in CBFS. + * + * @return A handle for the first file in CBFS, NULL on error. + */ +const struct cbfs_cachenode *file_cbfs_get_first(void); + +/* + * Get a handle to the file after this one in CBFS. + * + * @param file A pointer to the handle to advance. + */ +void file_cbfs_get_next(const struct cbfs_cachenode **file); + +/* + * Find a file with a particular name in CBFS. + * + * @param name The name to search for. + * + * @return A handle to the file, or NULL on error. + */ +const struct cbfs_cachenode *file_cbfs_find(const char *name); + + +/***************************************************************************/ +/* All of the functions below can be used without first initializing CBFS. */ +/***************************************************************************/ + +/* + * Find a file with a particular name in CBFS without using the heap. + * + * @param end_of_rom Points to the end of the ROM the CBFS should be read + * from. + * @param name The name to search for. + * + * @return A handle to the file, or NULL on error. + */ +const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom, + const char *name); + +/* + * Get the name of a file in CBFS. + * + * @param file The handle to the file. + * + * @return The name of the file, NULL on error. + */ +const char *file_cbfs_name(const struct cbfs_cachenode *file); + +/* + * Get the size of a file in CBFS. + * + * @param file The handle to the file. + * + * @return The size of the file, zero on error. + */ +u32 file_cbfs_size(const struct cbfs_cachenode *file); + +/* + * Get the type of a file in CBFS. + * + * @param file The handle to the file. + * + * @return The type of the file, zero on error. + */ +u32 file_cbfs_type(const struct cbfs_cachenode *file); + +/* + * Read a file from CBFS into RAM + * + * @param file A handle to the file to read. + * @param buffer Where to read it into memory. + * + * @return If positive or zero, the number of characters read. If negative, an + * error occurred. + */ +long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer, + unsigned long maxsize); + +#endif /* __CBFS_H */

On Fri, Oct 12, 2012 at 05:26:11PM -0700, Simon Glass wrote:
From: Gabe Black gabeblack@chromium.org
This change adds CBFS support and some commands to use it to u-boot. These commands are:
cbfsinit - Initialize CBFS support and pull all metadata into RAM. The end of the ROM is an optional parameter which defaults to the standard 0xffffffff and can be used to support multiple CBFSes in a system. The last one set up with cbfsinit is the one that will be used.
cbfsinfo - Print information from the CBFS header.
cbfsls - Print out the size, type, and name of all the files in the current CBFS. Recognized types are translated into symbolic names.
cbfsload - Load a file from CBFS into memory. Like the similar command for fat filesystems, you can optionally provide a maximum size.
Support for CBFS is compiled in when the CONFIG_CMD_CBFS option is specified.
The CBFS driver can also be used programmatically from within u-boot.
If u-boot needs something out of CBFS very early before the heap is configured, it won't be able to use the normal CBFS support which caches some information in memory it allocates from the heap. The cbfs_file_find_uncached function searches a CBFS instance without touching the heap.
Signed-off-by: Gabe Black gabeblack@google.com Signed-off-by: Stefan Reinauer reinauer@chromium.org Signed-off-by: Simon Glass sjg@chromium.org
I would like to see a follow-up enhancement adding a DocBook tmpl file for cbfs now that we have DocBook support, thanks!

Hi Tom,
On Mon, Oct 22, 2012 at 8:22 AM, Tom Rini trini@ti.com wrote:
On Fri, Oct 12, 2012 at 05:26:11PM -0700, Simon Glass wrote:
From: Gabe Black gabeblack@chromium.org
This change adds CBFS support and some commands to use it to u-boot. These commands are:
cbfsinit - Initialize CBFS support and pull all metadata into RAM. The end of the ROM is an optional parameter which defaults to the standard 0xffffffff and can be used to support multiple CBFSes in a system. The last one set up with cbfsinit is the one that will be used.
cbfsinfo - Print information from the CBFS header.
cbfsls - Print out the size, type, and name of all the files in the current CBFS. Recognized types are translated into symbolic names.
cbfsload - Load a file from CBFS into memory. Like the similar command for fat filesystems, you can optionally provide a maximum size.
Support for CBFS is compiled in when the CONFIG_CMD_CBFS option is specified.
The CBFS driver can also be used programmatically from within u-boot.
If u-boot needs something out of CBFS very early before the heap is configured, it won't be able to use the normal CBFS support which caches some information in memory it allocates from the heap. The cbfs_file_find_uncached function searches a CBFS instance without touching the heap.
Signed-off-by: Gabe Black gabeblack@google.com Signed-off-by: Stefan Reinauer reinauer@chromium.org Signed-off-by: Simon Glass sjg@chromium.org
I would like to see a follow-up enhancement adding a DocBook tmpl file for cbfs now that we have DocBook support, thanks!
OK I have sent a patch, although I have a few questions...
Regards, Simon
-- Tom

Dear Simon Glass,
In message 1350087972-1581-6-git-send-email-sjg@chromium.org you wrote:
From: Gabe Black gabeblack@chromium.org
This change adds CBFS support and some commands to use it to u-boot. These commands are:
...
--- /dev/null +++ b/common/cmd_cbfs.c @@ -0,0 +1,214 @@ +/*
- Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
- See file CREDITS for list of people who contributed to this
- project.
file CREDITS ? Please fix globally...
Is any of this code taken from any other project? If yes, then please attribute properly...
Best regards,
Wolfgang Denk

On Wed, Oct 31, 2012 at 11:41:20PM +0100, Wolfgang Denk wrote:
Dear Simon Glass,
In message 1350087972-1581-6-git-send-email-sjg@chromium.org you wrote:
From: Gabe Black gabeblack@chromium.org
This change adds CBFS support and some commands to use it to u-boot. These commands are:
...
--- /dev/null +++ b/common/cmd_cbfs.c @@ -0,0 +1,214 @@ +/*
- Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
- See file CREDITS for list of people who contributed to this
- project.
file CREDITS ? Please fix globally...
Is any of this code taken from any other project? If yes, then please attribute properly...
Sorry? U-Boot has a CREDITS file but only ~10% of the files reference it.

Hi,
On Wed, Oct 31, 2012 at 6:22 PM, Tom Rini trini@ti.com wrote:
On Wed, Oct 31, 2012 at 11:41:20PM +0100, Wolfgang Denk wrote:
Dear Simon Glass,
In message 1350087972-1581-6-git-send-email-sjg@chromium.org you wrote:
From: Gabe Black gabeblack@chromium.org
This change adds CBFS support and some commands to use it to u-boot. These commands are:
...
--- /dev/null +++ b/common/cmd_cbfs.c @@ -0,0 +1,214 @@ +/*
- Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
- See file CREDITS for list of people who contributed to this
- project.
file CREDITS ? Please fix globally...
Is any of this code taken from any other project? If yes, then please attribute properly...
Sorry? U-Boot has a CREDITS file but only ~10% of the files reference it.
Tom or Wolfgang, can you please explain what I should do here? I don't know what to do about the CREDITS line.
Regards, Simon
-- Tom

Dear Simon Glass,
In message CAPnjgZ2hD4ZgzM=0RpPSGr0-iOJTV+q40E3gYExEqXndkoPPxQ@mail.gmail.com you wrote:
--- /dev/null +++ b/common/cmd_cbfs.c @@ -0,0 +1,214 @@ +/*
- Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
- See file CREDITS for list of people who contributed to this
- project.
file CREDITS ? Please fix globally...
Is any of this code taken from any other project? If yes, then please attribute properly...
Sorry? U-Boot has a CREDITS file but only ~10% of the files reference it.
Yes, U-Boot has such a file, and I wonder if we should remove it. After all, all the credits are maintained in the git history of changes.
Tom or Wolfgang, can you please explain what I should do here? I don't know what to do about the CREDITS line.
To me the reference to a CREDITS file is reason to suspect that this code has not been written from scratch, but copied from some other project, which eventually had it's own CREDITS file.
I'm missing a reference to the origin of the code.
If this was indeed written from scratch, with no code borrowed from elsewhere, then please just drop these lines.
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Sat, Nov 3, 2012 at 8:04 AM, Wolfgang Denk wd@denx.de wrote:
Dear Simon Glass,
In message CAPnjgZ2hD4ZgzM=0RpPSGr0-iOJTV+q40E3gYExEqXndkoPPxQ@mail.gmail.com you wrote:
--- /dev/null +++ b/common/cmd_cbfs.c @@ -0,0 +1,214 @@ +/*
- Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
- See file CREDITS for list of people who contributed to this
- project.
file CREDITS ? Please fix globally...
Is any of this code taken from any other project? If yes, then please attribute properly...
Sorry? U-Boot has a CREDITS file but only ~10% of the files reference it.
Yes, U-Boot has such a file, and I wonder if we should remove it. After all, all the credits are maintained in the git history of changes.
Tom or Wolfgang, can you please explain what I should do here? I don't know what to do about the CREDITS line.
To me the reference to a CREDITS file is reason to suspect that this code has not been written from scratch, but copied from some other project, which eventually had it's own CREDITS file.
Yes, quite likely the boilerplate came from another U-Boot file.
I'm missing a reference to the origin of the code.
It was written from scratch by Gabe - it did not come from coreboot if that is what you as asking. I confirmed with him again yesterday.
If this was indeed written from scratch, with no code borrowed from elsewhere, then please just drop these lines.
OK, I will do this in my follow-up patch to add DocBook support. I did find a shorter message which some U-Boot files use at one point. I will try to find that again, and use it.
Regards, Simon
Best regards,
Wolfgang Denk
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de "Text processing has made it possible to right-justify any idea, even one which cannot be justified on any other grounds." -- J. Finnegan, USC.

Hi,
On Sat, Nov 3, 2012 at 2:11 PM, Simon Glass sjg@chromium.org wrote:
Hi Wolfgang,
On Sat, Nov 3, 2012 at 8:04 AM, Wolfgang Denk wd@denx.de wrote:
Dear Simon Glass,
In message CAPnjgZ2hD4ZgzM=0RpPSGr0-iOJTV+q40E3gYExEqXndkoPPxQ@mail.gmail.com you wrote:
--- /dev/null +++ b/common/cmd_cbfs.c @@ -0,0 +1,214 @@ +/*
- Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
- See file CREDITS for list of people who contributed to this
- project.
file CREDITS ? Please fix globally...
Is any of this code taken from any other project? If yes, then please attribute properly...
Sorry? U-Boot has a CREDITS file but only ~10% of the files reference it.
Yes, U-Boot has such a file, and I wonder if we should remove it. After all, all the credits are maintained in the git history of changes.
Tom or Wolfgang, can you please explain what I should do here? I don't know what to do about the CREDITS line.
To me the reference to a CREDITS file is reason to suspect that this code has not been written from scratch, but copied from some other project, which eventually had it's own CREDITS file.
Yes, quite likely the boilerplate came from another U-Boot file.
I'm missing a reference to the origin of the code.
It was written from scratch by Gabe - it did not come from coreboot if that is what you as asking. I confirmed with him again yesterday.
If this was indeed written from scratch, with no code borrowed from elsewhere, then please just drop these lines.
OK, I will do this in my follow-up patch to add DocBook support. I did find a shorter message which some U-Boot files use at one point. I will try to find that again, and use it.
Well I found a very short version:
* Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
but it is inaccurate. We could perhaps change it to:
* Use of this source code is governed by a BSD-style license that can be * found in the COPYING file.
or something similar? But so much of U-Boot already has the full version that I'm not sure this is a good idea. Here is the one I am using>
# 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
So for now I have sent a new patch that just takes out the CREDITS but leaves the rest of the text in. Please advise if something else is needed/preferable.
Regards, Simon
Best regards,
Wolfgang Denk
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de "Text processing has made it possible to right-justify any idea, even one which cannot be justified on any other grounds." -- J. Finnegan, USC.

Dear Simon Glass,
In message CAPnjgZ0STfp2UcFN4tMDPg_X-4VDW7gxOdsSCGsBq6sUM0oe7Q@mail.gmail.com you wrote:
Well I found a very short version:
- Use of this source code is governed by a BSD-style license that can be
- found in the LICENSE file.
but it is inaccurate. We could perhaps change it to:
- Use of this source code is governed by a BSD-style license that can be
- found in the COPYING file.
or something similar? But so much of U-Boot already has the full version that I'm not sure this is a good idea. Here is the one I am using>
# 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.
Note that this is the GPL, and _not_ any BSD-style license !
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Mon, Nov 5, 2012 at 11:27 PM, Wolfgang Denk wd@denx.de wrote:
Dear Simon Glass,
In message CAPnjgZ0STfp2UcFN4tMDPg_X-4VDW7gxOdsSCGsBq6sUM0oe7Q@mail.gmail.com you wrote:
Well I found a very short version:
- Use of this source code is governed by a BSD-style license that can be
- found in the LICENSE file.
but it is inaccurate. We could perhaps change it to:
- Use of this source code is governed by a BSD-style license that can be
- found in the COPYING file.
or something similar? But so much of U-Boot already has the full version that I'm not sure this is a good idea. Here is the one I am using>
# 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.
Note that this is the GPL, and _not_ any BSD-style license !
Yes. I've gone with the longer one, just removing the CREDITS. That seems to be the most common message in U-Boot.
Regards, Simon
Best regards,
Wolfgang Denk
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de Children begin by loving their parents. After a time they judge them. Rarely, if ever, do they forgive them. - Oscar Wilde

Dear Simon Glass,
In message CAPnjgZ1DbXwS=bgzLecoLM-V0785Zi6bytKTM=RP2EcnSkt4eA@mail.gmail.com you wrote:
Well I found a very short version:
- Use of this source code is governed by a BSD-style license that can be
- found in the LICENSE file.
but it is inaccurate. We could perhaps change it to:
- Use of this source code is governed by a BSD-style license that can be
- found in the COPYING file.
or something similar? But so much of U-Boot already has the full version that I'm not sure this is a good idea. Here is the one I am using>
# 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.
Note that this is the GPL, and _not_ any BSD-style license !
Yes. I've gone with the longer one, just removing the CREDITS. That seems to be the most common message in U-Boot.
You appear to miss the point. You switched the licensing model from BSD to GPL - not that I would complain about such a move, on contrary, but I wonder if this is intentional and agreed by the authors of the code?
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Tue, Nov 6, 2012 at 2:23 PM, Wolfgang Denk wd@denx.de wrote:
Dear Simon Glass,
In message CAPnjgZ1DbXwS=bgzLecoLM-V0785Zi6bytKTM=RP2EcnSkt4eA@mail.gmail.com you wrote:
Well I found a very short version:
- Use of this source code is governed by a BSD-style license that can be
- found in the LICENSE file.
but it is inaccurate. We could perhaps change it to:
- Use of this source code is governed by a BSD-style license that can be
- found in the COPYING file.
or something similar? But so much of U-Boot already has the full version that I'm not sure this is a good idea. Here is the one I am using>
# 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.
Note that this is the GPL, and _not_ any BSD-style license !
Yes. I've gone with the longer one, just removing the CREDITS. That seems to be the most common message in U-Boot.
You appear to miss the point. You switched the licensing model from BSD to GPL - not that I would complain about such a move, on contrary, but I wonder if this is intentional and agreed by the authors of the code?
Yes I am now completely lost :-)
Where have I changed the licensing model?
Your original request was to remove the CREDITS line I think. I have done that in this patch:
http://patchwork.ozlabs.org/patch/197314/
The above discussion about copyright message is separate to that. I was looking around the code base for a possible replacement (shorter) message because I thought that was what you were looking for. I found the BSD one, but have not changed any code to use it.
So yes, please can you explain what I am missing here?
Regards, Simon
Best regards,
Wolfgang Denk
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de The sight of death frightens them [Earthers]. -- Kras the Klingon, "Friday's Child", stardate 3497.2

Dear Simon,
In message CAPnjgZ0k58-JG+MxvKp=6JxThMPb8pzHp+xFpDnB8JCtamtGJQ@mail.gmail.com you wrote:
Yes I am now completely lost :-)
Me too.
Where have I changed the licensing model?
Your original request was to remove the CREDITS line I think. I have done that in this patch:
http://patchwork.ozlabs.org/patch/197314/
The above discussion about copyright message is separate to that. I
Ah... I understood it was part of your intended changes.
was looking around the code base for a possible replacement (shorter) message because I thought that was what you were looking for. I found the BSD one, but have not changed any code to use it.
So yes, please can you explain what I am missing here?
Maybe everything is clear to you, And I just did not understand. I just wanted to point out thatt he misc postings to this topic contained references to different licenses - starting from code under GPLv2+ metioning some BSD license to GPL again. If all this doesn't change the code, I suggest we ignore it all.
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Wed, Nov 7, 2012 at 4:38 AM, Wolfgang Denk wd@denx.de wrote:
Dear Simon,
In message CAPnjgZ0k58-JG+MxvKp=6JxThMPb8pzHp+xFpDnB8JCtamtGJQ@mail.gmail.com you wrote:
Yes I am now completely lost :-)
Me too.
Where have I changed the licensing model?
Your original request was to remove the CREDITS line I think. I have done that in this patch:
http://patchwork.ozlabs.org/patch/197314/
The above discussion about copyright message is separate to that. I
Ah... I understood it was part of your intended changes.
was looking around the code base for a possible replacement (shorter) message because I thought that was what you were looking for. I found the BSD one, but have not changed any code to use it.
So yes, please can you explain what I am missing here?
Maybe everything is clear to you, And I just did not understand. I just wanted to point out thatt he misc postings to this topic contained references to different licenses - starting from code under GPLv2+ metioning some BSD license to GPL again. If all this doesn't change the code, I suggest we ignore it all.
Sounds good. From my side it was just a discussion on the best license text to use.
Regards, Simon
Best regards,
Wolfgang Denk
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality. -- Albert Einstein

Enable Coreboot and EXT4 Filesystems on the coreboot board.
Signed-off-by: Simon Glass sjg@chromium.org --- include/configs/coreboot.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/include/configs/coreboot.h b/include/configs/coreboot.h index 0e89242..3df085b 100644 --- a/include/configs/coreboot.h +++ b/include/configs/coreboot.h @@ -92,6 +92,9 @@ #define CONFIG_MAC_PARTITION #define CONFIG_ISO_PARTITION /* Experimental */
+#define CONFIG_CMD_CBFS +#define CONFIG_CMD_EXT4 +#define CONFIG_CMD_EXT4_WRITE
/*----------------------------------------------------------------------- * Video Configuration

On Fri, Oct 12, 2012 at 05:26:12PM -0700, Simon Glass wrote:
Enable Coreboot and EXT4 Filesystems on the coreboot board.
Signed-off-by: Simon Glass sjg@chromium.org
cmd_ext4.c: In function 'do_ext4_write': cmd_ext4.c:110:3: error: format '%lu' expects type 'long unsigned int', but argument 4 has type 'int'
Is what I see with my toolchain.

Hi Tom,
On Mon, Oct 22, 2012 at 1:38 PM, Tom Rini trini@ti.com wrote:
On Fri, Oct 12, 2012 at 05:26:12PM -0700, Simon Glass wrote:
Enable Coreboot and EXT4 Filesystems on the coreboot board.
Signed-off-by: Simon Glass sjg@chromium.org
cmd_ext4.c: In function 'do_ext4_write': cmd_ext4.c:110:3: error: format '%lu' expects type 'long unsigned int', but argument 4 has type 'int'
Is what I see with my toolchain.
Hmm I thought I fixed the ext4 x86 warnings with my previous patch, but clearly not. I will take another look and perhaps come up with another patch.
Regards, Simon
-- Tom

On Fri, Oct 12, 2012 at 05:26:06PM -0700, Simon Glass wrote:
From: Gabe Black gabeblack@chromium.org
The size of an LBA type changes depending on this option. We need to use a different printf() string in each case, so create a define for this.
Signed-off-by: Gabe Black gabeblack@chromium.org Signed-off-by: Simon Glass sjg@chromium.org
Except for part 5 of 7, this series is applied to u-boot/master, but please address the problem I reported on part 7.
participants (6)
-
Marek Vasut
-
Simon Glass
-
Stefan Reinauer
-
Stephen Warren
-
Tom Rini
-
Wolfgang Denk