#include <zlib.h>
+#ifdef CONFIG_ZSTD
+#include <zstd.h>
+#include <zstd_errors.h>
+#endif
+
static int roms_loaded;
/* return the size or -1 if error */
return 0;
}
- if (strcmp(header->compression_type, "gzip") != 0) {
- fprintf(stderr,
- "unable to handle EFI zboot image with \"%.*s\" compression\n",
- (int)sizeof(header->compression_type) - 1,
- header->compression_type);
- return -1;
- }
-
ploff = ldl_le_p(&header->payload_offset);
plsize = ldl_le_p(&header->payload_size);
}
data = g_malloc(max_bytes);
- bytes = gunzip(data, max_bytes, *buffer + ploff, plsize);
+
+ if (strcmp(header->compression_type, "gzip") == 0) {
+ bytes = gunzip(data, max_bytes, *buffer + ploff, plsize);
+#ifdef CONFIG_ZSTD
+ } else if (strcmp(header->compression_type, "zstd") == 0) {
+ size_t ret = ZSTD_decompress(data, max_bytes, *buffer + ploff, plsize);
+ bytes = ZSTD_isError(ret) ? -1 : (ssize_t) ret;
+#endif
+ } else {
+ fprintf(stderr,
+ "unable to handle EFI zboot image with \"%.*s\" compression\n",
+ (int)sizeof(header->compression_type) - 1,
+ header->compression_type);
+ return -1;
+ }
+
if (bytes < 0) {
fprintf(stderr, "failed to decompress EFI zboot image\n");
return -1;