cbfs: Support reading compression information
authorSimon Glass <sjg@chromium.org>
Mon, 15 Mar 2021 05:00:16 +0000 (18:00 +1300)
committerSimon Glass <sjg@chromium.org>
Sat, 27 Mar 2021 00:59:37 +0000 (13:59 +1300)
CBFS now supports compressed filed. Add support for reading this
information so that the correct decompression can be applied. The
decompression itself is not implemented in CBFS.

Signed-off-by: Simon Glass <sjg@chromium.org>
fs/cbfs/cbfs.c
include/cbfs.h

index 9e534d1..443a148 100644 (file)
@@ -91,6 +91,7 @@ static int fill_node(struct cbfs_cachenode *node, void *start,
                     struct cbfs_fileheader *header)
 {
        uint name_len;
+       uint offset;
 
        /* Check the header is large enough */
        if (header->offset < sizeof(struct cbfs_fileheader))
@@ -104,6 +105,27 @@ static int fill_node(struct cbfs_cachenode *node, void *start,
        node->name = start + sizeof(struct cbfs_fileheader);
        node->name_length = name_len;
        node->attr_offset = header->attributes_offset;
+       node->comp_algo = CBFS_COMPRESS_NONE;
+       node->decomp_size = 0;
+
+       for (offset = node->attr_offset; offset < header->offset;) {
+               const struct cbfs_file_attribute *attr;
+               uint tag, len;
+
+               attr = start + offset;
+               tag = be32_to_cpu(attr->tag);
+               len = be32_to_cpu(attr->len);
+               if (tag == CBFS_FILE_ATTR_TAG_COMPRESSION) {
+                       struct cbfs_file_attr_compression *comp;
+
+                       comp = start + offset;
+                       node->comp_algo = be32_to_cpu(comp->compression);
+                       node->decomp_size =
+                               be32_to_cpu(comp->decompressed_size);
+               }
+
+               offset += len;
+       }
 
        return 0;
 }
index 055edba..ae94f1d 100644 (file)
@@ -75,6 +75,15 @@ struct cbfs_fileheader {
        char filename[];
 } __packed;
 
+/**
+ * These are standard values for the known compression alogrithms that coreboot
+ * knows about for stages and payloads.  Of course, other CBFS users can use
+ * whatever values they want, as long as they understand them.
+ */
+#define CBFS_COMPRESS_NONE  0
+#define CBFS_COMPRESS_LZMA  1
+#define CBFS_COMPRESS_LZ4   2
+
 /*
  * Depending on how the header was initialized, it may be backed with 0x00 or
  * 0xff, so support both
@@ -119,6 +128,8 @@ struct cbfs_cachenode {
        u32 data_length;
        u32 name_length;
        u32 attr_offset;
+       u32 comp_algo;
+       u32 decomp_size;
 };
 
 /**