-
Notifications
You must be signed in to change notification settings - Fork 349
[TEST] New NOTE section for BYT #2808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
091cd24
sof: Add fw_metadata section
ktrzcinx af1d000
ext_manifest: Define extended manifest structures in firmware
ktrzcinx 6bb6c12
rimage: Mark const args in elf_find_section()
ktrzcinx 6248bb9
rimage: Create extended manifest
ktrzcinx c0b0991
ext_manifest: Include firmware version
ktrzcinx e8ddac8
file_simple
ktrzcinx ce0c0a5
fixup! sof: Add fw_metadata section
ktrzcinx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ add_executable(rimage | |
| hash.c | ||
| pkcs1_5.c | ||
| manifest.c | ||
| ext_manifest.c | ||
| elf.c | ||
| rimage.c | ||
| ) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // | ||
ktrzcinx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Copyright(c) 2020 Intel Corporation. All rights reserved. | ||
| // | ||
| // Author: Karol Trzcinski <karolx.trzcinski@linux.intel.com> | ||
|
|
||
| #include <stdlib.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include "kernel/ext_manifest.h" | ||
| #include "ext_manifest.h" | ||
| #include "ipc/info.h" | ||
| #include "rimage.h" | ||
|
|
||
| const struct ext_man_header ext_man_template = { | ||
| .magic = EXT_MAN_MAGIC_NUMBER, | ||
| .header_version = EXT_MAN_VERSION, | ||
| .header_size = sizeof(struct ext_man_header), | ||
| .full_size = 0, /* runtime variable */ | ||
| }; | ||
|
|
||
| static int ext_man_open_file(struct image *image) | ||
| { | ||
| /* open extended manifest outfile for writing */ | ||
| sprintf(image->out_ext_man_file, "%s.xman", image->out_file); | ||
| unlink(image->out_ext_man_file); | ||
|
|
||
| image->out_ext_man_fd = fopen(image->out_ext_man_file, "wb"); | ||
| if (!image->out_ext_man_fd) { | ||
| fprintf(stderr, "error: unable to open %s for writing %d\n", | ||
| image->out_ext_man_file, errno); | ||
| return errno; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static struct module *ext_man_get_module(struct image *image) | ||
| { | ||
| struct module *module; | ||
| int i; | ||
|
|
||
| for (i = image->num_modules > 1 ? 1 : 0; i < image->num_modules; i++) { | ||
| module = &image->module[i]; | ||
|
|
||
| if (elf_find_section(image, module, ".fw_metadata") > 0) | ||
| return module; | ||
| } | ||
|
|
||
| return NULL; | ||
| } | ||
|
|
||
| static int ext_man_validate(uint32_t section_size, const void *section_data) | ||
| { | ||
| uint8_t *sbuf = (uint8_t *)section_data; | ||
| struct ext_man_elem_header head; | ||
| uint32_t offset = 0; | ||
|
|
||
| /* copy each head to local struct to omit memory align issues */ | ||
| while (offset < section_size) { | ||
| memcpy(&head, &sbuf[offset], sizeof(head)); | ||
| fprintf(stdout, "Extended manifest found module, type: 0x%04X size: 0x%04X (%4d) offset: 0x%04X\n", | ||
| head.type, head.elem_size, head.elem_size, offset); | ||
| if (head.elem_size == 0 || head.elem_size % EXT_MAN_ALIGN) { | ||
| fprintf(stderr, | ||
| "error: invalid extended manifest element size\n"); | ||
| return -EINVAL; | ||
| } | ||
| offset += head.elem_size; | ||
| } | ||
|
|
||
| /* sum of packets size != section size */ | ||
| if (offset != section_size) { | ||
| fprintf(stderr, | ||
| "error: fw_metadata section is inconsistent, section size: 0x%04X != 0x%04X sum of packets size\n", | ||
| section_size, offset); | ||
| return -EINVAL; | ||
| } else { | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| static int ext_man_build(const struct image *image, const struct module *module, | ||
| struct ext_man_header **dst_buff) | ||
| { | ||
| struct ext_man_header ext_man; | ||
| const Elf32_Shdr *section; | ||
| uint8_t *buffer = NULL; | ||
| int fw_metadata_index; | ||
| size_t offset; | ||
| size_t read; | ||
| int ret = 0; | ||
|
|
||
| /* find .fw_metadata section */ | ||
| fw_metadata_index = elf_find_section(image, module, ".fw_metadata"); | ||
| if (fw_metadata_index < 0) { | ||
| fprintf(stderr, "error: unable to find .fw_metadata section: %d\n", | ||
| fw_metadata_index); | ||
| ret = fw_metadata_index; | ||
| goto out; | ||
| } | ||
| section = &module->section[fw_metadata_index]; | ||
|
|
||
| /* fill ext_man, size aligned to 4 to avoid unaligned accesses */ | ||
| memcpy(&ext_man, &ext_man_template, sizeof(struct ext_man_header)); | ||
| ext_man.full_size = ext_man.header_size; | ||
| ext_man.full_size += section->size; | ||
| if (ext_man.full_size % 4) { | ||
| fprintf(stderr, | ||
| "error: extended manifest size must be aligned to 4\n"); | ||
| ret = -EINVAL; | ||
| goto out; | ||
| } | ||
|
|
||
| /* alloc buffer for ext_man */ | ||
| buffer = calloc(1, ext_man.full_size); | ||
| if (!buffer) { | ||
| ret = -ENOMEM; | ||
| goto out; | ||
| } | ||
|
|
||
| /* fill buffer with ext_man header and section content */ | ||
| memcpy(buffer, &ext_man, ext_man.header_size); | ||
| offset = ext_man.header_size; | ||
|
|
||
| fseek(module->fd, section->off, SEEK_SET); | ||
| read = fread(buffer + offset, 1, section->size, module->fd); | ||
| if (read != section->size) { | ||
| fprintf(stderr, | ||
| "error: can't read fw_metadata section %d\n", | ||
| -errno); | ||
| free(buffer); | ||
| ret = -errno; | ||
| } | ||
|
|
||
| *dst_buff = (struct ext_man_header *)buffer; | ||
|
|
||
| out: | ||
| return ret; | ||
| } | ||
|
|
||
| int ext_man_write(struct image *image) | ||
| { | ||
| struct ext_man_header *ext_man = NULL; | ||
| struct module *module; | ||
| int count; | ||
| int ret; | ||
|
|
||
| module = ext_man_get_module(image); | ||
| if (!module) { | ||
| fprintf(stderr, "error: firmware metadata section not found\n"); | ||
| ret = -EINVAL; | ||
| goto out; | ||
| } | ||
|
|
||
| ret = ext_man_open_file(image); | ||
| if (ret) | ||
| goto out; | ||
|
|
||
| ret = ext_man_build(image, module, &ext_man); | ||
| if (ret) | ||
| goto out; | ||
|
|
||
| /* validate metadata section */ | ||
| ret = ext_man_validate(ext_man->full_size - ext_man->header_size, | ||
| (char *)ext_man + ext_man->header_size); | ||
| if (ret) { | ||
| ret = -errno; | ||
| goto out; | ||
| } | ||
|
|
||
| /* write extended metadata to file */ | ||
| count = fwrite(ext_man, 1, ext_man->full_size, image->out_ext_man_fd); | ||
|
|
||
| if (count != ext_man->full_size) { | ||
| fprintf(stderr, | ||
| "error: can't write extended manifest to file %d\n", | ||
| -errno); | ||
| ret = -errno; | ||
| goto out; | ||
| } | ||
|
|
||
| fprintf(stdout, "Extended manifest saved to file %s size 0x%04X (%d) bytes\n\n", | ||
| image->out_ext_man_file, ext_man->full_size, | ||
| ext_man->full_size); | ||
|
|
||
| out: | ||
| if (ext_man) | ||
| free(ext_man); | ||
| if (image->out_ext_man_fd) | ||
| fclose(image->out_ext_man_fd); | ||
| return ret; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* SPDX-License-Identifier: BSD-3-Clause | ||
| * | ||
| * Copyright(c) 2020 Intel Corporation. All rights reserved. | ||
| * | ||
| * Author: Karol Trzcinski <karolx.trzcinski@linux.intel.com> | ||
| */ | ||
|
|
||
| /* | ||
| * Extended manifest is a place to store metadata about firmware, known during | ||
| * compilation time - for example firmware version or used compiler. | ||
| * Given information are read on host side before firmware startup. | ||
| * This part of output binary is not signed. | ||
| * | ||
| * To add new content to ext_man, in firmware code define struct which starts | ||
| * with ext_man_elem_head followed by usage dependent content and place whole | ||
| * struct in "fw_metadata" section. Moreover kernel code should be modified to | ||
| * properly read new packet. | ||
| * | ||
| * Extended manifest designed to be extensible. In header there is a field which | ||
| * describe header length, so after appending some data to header then it can be | ||
| * easily skipped by device with older version of this header. | ||
| * From other side, unknown ext_man elements should be just skipped by host, | ||
| * to be backward compatible. Field ext_man_elem_header.elem_size should be | ||
| * used in such a situation. | ||
| */ | ||
|
|
||
| #ifndef __EXT_MAN_H__ | ||
| #define __EXT_MAN_H__ | ||
|
|
||
| #include "rimage.h" | ||
|
|
||
| int ext_man_write(struct image *image); | ||
|
|
||
| #endif /* __EXT_MAN_H__ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.