Returns true if decompressing was successful and it looks like a kernel. */
| 36 | |
| 37 | /* Returns true if decompressing was successful and it looks like a kernel. */ |
| 38 | static bool decompress_kernel_header(const struct fit_image_node *node) |
| 39 | { |
| 40 | /* Partially decompress to get text_offset. Can't check for errors. */ |
| 41 | scratch.canary = SCRATCH_CANARY_VALUE; |
| 42 | switch (node->compression) { |
| 43 | case CBFS_COMPRESS_NONE: |
| 44 | memcpy(scratch.raw, node->data, sizeof(scratch.raw)); |
| 45 | break; |
| 46 | case CBFS_COMPRESS_LZMA: |
| 47 | ulzman(node->data, node->size, |
| 48 | scratch.raw, sizeof(scratch.raw)); |
| 49 | break; |
| 50 | case CBFS_COMPRESS_LZ4: |
| 51 | ulz4fn(node->data, node->size, |
| 52 | scratch.raw, sizeof(scratch.raw)); |
| 53 | break; |
| 54 | default: |
| 55 | printk(BIOS_ERR, "Unsupported compression algorithm!\n"); |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | /* Should never happen, but if it does we'll want to know. */ |
| 60 | if (scratch.canary != SCRATCH_CANARY_VALUE) |
| 61 | die("ERROR: Partial decompression ran over scratchbuf!\n"); |
| 62 | |
| 63 | if (scratch.header.magic != KERNEL_HEADER_MAGIC) { |
| 64 | printk(BIOS_ERR, "Invalid kernel magic: %#.8x\n != %#.8x\n", |
| 65 | scratch.header.magic, KERNEL_HEADER_MAGIC); |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Prior to v3.17, the endianness of text_offset was not specified. In |
| 71 | * these cases image_size is zero and text_offset is 0x80000 in the |
| 72 | * endianness of the kernel. Where image_size is non-zero image_size is |
| 73 | * little-endian and must be respected. Where image_size is zero, |
| 74 | * text_offset can be assumed to be 0x80000. |
| 75 | */ |
| 76 | if (!scratch.header.image_size) |
| 77 | scratch.header.text_offset = cpu_to_le64(0x80000); |
| 78 | |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | static size_t get_kernel_size(const struct fit_image_node *node) |
| 83 | { |