Skip to content

Commit

Permalink
rimage: Introduce ALIGN_UP macro
Browse files Browse the repository at this point in the history
Created ALIGN_UP macro to simplify calculations.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
  • Loading branch information
softwarecki committed Nov 28, 2023
1 parent 19006e6 commit 9bbda46
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions tools/rimage/src/include/rimage/misc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdint.h>

#define DIV_ROUND_UP(val, div) (((val) + (div) - 1) / (div))
#define ALIGN_UP(val, align) (((val) + (align) - 1) & ~((align) - 1))

/**
* Reverses the order of bytes in the array
Expand Down
10 changes: 2 additions & 8 deletions tools/rimage/src/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,7 @@ static int man_module_create(struct image *image, struct manifest_module *module
}

/* round module end upto nearest page */
if (image->image_end % MAN_PAGE_SIZE) {
image->image_end = (image->image_end / MAN_PAGE_SIZE) + 1;
image->image_end *= MAN_PAGE_SIZE;
}
image->image_end = ALIGN_UP(image->image_end, MAN_PAGE_SIZE);

out:
fprintf(stdout, " Total pages text %d data %d bss %d module file limit: 0x%x\n\n",
Expand Down Expand Up @@ -498,10 +495,7 @@ static int man_module_create_reloc(struct image *image, struct manifest_module *
image->image_end = module->foffset + module->file.elf.file_size;

/* round module end up to nearest page */
if (image->image_end % MAN_PAGE_SIZE) {
image->image_end = (image->image_end / MAN_PAGE_SIZE) + 1;
image->image_end *= MAN_PAGE_SIZE;
}
image->image_end = ALIGN_UP(image->image_end, MAN_PAGE_SIZE);

fprintf(stdout, " Total pages text %d data %d bss %d module file limit: 0x%x\n\n",
man_module->segment[SOF_MAN_SEGMENT_TEXT].flags.r.length,
Expand Down
6 changes: 3 additions & 3 deletions tools/rimage/src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <rimage/elf_file.h>
#include <rimage/file_utils.h>
#include <rimage/rimage.h>

#include <rimage/misc_utils.h>

int module_read_section(const struct module *module, const struct module_section *section,
void *buffer, const size_t size)
Expand Down Expand Up @@ -252,10 +252,10 @@ static void sections_info_add(struct module_sections_info *info, struct module_s
*/
static void sections_info_finalize(struct module_sections_info *info)
{
info->file_size = info->end - info->start;
size_t size = (info->end > info->start) ? info->end - info->start : 0;

/* file sizes round up to nearest page */
info->file_size = (info->file_size + MAN_PAGE_SIZE - 1) & ~(MAN_PAGE_SIZE - 1);
info->file_size = ALIGN_UP(size, MAN_PAGE_SIZE);
}

/**
Expand Down
9 changes: 4 additions & 5 deletions tools/rimage/src/plat_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <rimage/rimage.h>
#include <rimage/manifest.h>
#include <rimage/plat_auth.h>
#include <rimage/misc_utils.h>

void ri_adsp_meta_data_create_v1_8(struct image *image, int meta_start_offset,
int meta_end_offset)
Expand Down Expand Up @@ -52,7 +53,7 @@ void ri_plat_ext_data_create(struct image *image)
fprintf(stdout, " auth: completing authentication manifest\n");

part->length = meta->comp_desc[0].limit_offset - MAN_DESC_OFFSET_V1_8;
part->length += MAN_PAGE_SIZE - (part->length % MAN_PAGE_SIZE);
part->length = ALIGN_UP(part->length, MAN_PAGE_SIZE);

/* do this here atm */
desc->header.preload_page_count = part->length / MAN_PAGE_SIZE;
Expand All @@ -69,10 +70,9 @@ void ri_plat_ext_data_create_v2_5(struct image *image)
fprintf(stdout, " auth: completing authentication manifest\n");

size = meta->comp_desc[0].limit_offset - MAN_DESC_OFFSET_V1_8;
size += MAN_PAGE_SIZE - (size % MAN_PAGE_SIZE);

/* do this here atm */
desc->header.preload_page_count = size / MAN_PAGE_SIZE;
desc->header.preload_page_count = DIV_ROUND_UP(size, MAN_PAGE_SIZE);
ext->size = image->image_end;
}

Expand All @@ -87,8 +87,7 @@ void ri_plat_ext_data_create_ace_v1_5(struct image *image)
fprintf(stdout, " auth: completing authentication manifest\n");

size = meta->comp_desc[0].limit_offset - MAN_DESC_OFFSET_V1_8;
size += MAN_PAGE_SIZE - (size % MAN_PAGE_SIZE);

desc->header.preload_page_count = size / MAN_PAGE_SIZE;
desc->header.preload_page_count = DIV_ROUND_UP(size, MAN_PAGE_SIZE);
ext->size = image->image_end;
}

0 comments on commit 9bbda46

Please sign in to comment.