Skip to content

Commit

Permalink
tools/imagetool: remove linker script
Browse files Browse the repository at this point in the history
Commit a93648d introduced linker generated
lists for imagetool which is the base for some host tools (mkimage, dumpimage,
et al.).  Unfortunately some host tool chains do not support the used type of
linker scripts. Therefore this commit broke these host-tools for them, namely
FreeBSD and Darwin (OS/X).

This commit tries to fix this. In order to have a clean distinction between host
and embedded code space we need to introduce our own linker generated list
instead of re-using the available linker_lists.h provided functionality.  So we
copy the implementation used in linux kernel script/mod/file2alias.c which has
the very same problem (cause it is a host tool). This code also comes with an
abstraction for Mach-O binary format used in Darwin systems.

Signed-off-by: Andreas Bießmann <[email protected]>
Cc: Guilherme Maciel Ferreira <[email protected]>
  • Loading branch information
Andreas Bießmann authored and trini committed Feb 16, 2015
1 parent 312aca4 commit 1fddd7b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 55 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ os_x_before = $(shell if [ $(DARWIN_MAJOR_VERSION) -le $(1) -a \
HOSTCC = $(call os_x_before, 10, 5, "cc", "gcc")
HOSTCFLAGS += $(call os_x_before, 10, 4, "-traditional-cpp")
HOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress")

# since Lion (10.7) ASLR is on by default, but we use linker generated lists
# in some host tools which is a problem then ... so disable ASLR for these
# tools
HOSTLDFLAGS += $(call os_x_before, 10, 7, "", "-Xlinker -no_pie")
endif

# Decide whether to build built-in, modular, or both.
Expand Down
2 changes: 0 additions & 2 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ HOSTLOADLIBES_dumpimage := $(HOSTLOADLIBES_mkimage)
HOSTLOADLIBES_fit_info := $(HOSTLOADLIBES_mkimage)
HOSTLOADLIBES_fit_check_sign := $(HOSTLOADLIBES_mkimage)

HOSTLDFLAGS += -T $(srctree)/tools/imagetool.lds

hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl
hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
HOSTCFLAGS_mkexynosspl.o := -pedantic
Expand Down
35 changes: 17 additions & 18 deletions tools/imagetool.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

struct image_type_params *imagetool_get_type(int type)
{
struct image_type_params *curr;
struct image_type_params *start = ll_entry_start(
struct image_type_params, image_type);
struct image_type_params *end = ll_entry_end(
struct image_type_params, image_type);
struct image_type_params **curr;
INIT_SECTION(image_type);

struct image_type_params **start = __start_image_type;
struct image_type_params **end = __stop_image_type;

for (curr = start; curr != end; curr++) {
if (curr->check_image_type) {
if (!curr->check_image_type(type))
return curr;
if ((*curr)->check_image_type) {
if (!(*curr)->check_image_type(type))
return *curr;
}
}
return NULL;
Expand All @@ -34,29 +34,28 @@ int imagetool_verify_print_header(
struct image_tool_params *params)
{
int retval = -1;
struct image_type_params *curr;
struct image_type_params **curr;
INIT_SECTION(image_type);

struct image_type_params *start = ll_entry_start(
struct image_type_params, image_type);
struct image_type_params *end = ll_entry_end(
struct image_type_params, image_type);
struct image_type_params **start = __start_image_type;
struct image_type_params **end = __stop_image_type;

for (curr = start; curr != end; curr++) {
if (curr->verify_header) {
retval = curr->verify_header((unsigned char *)ptr,
if ((*curr)->verify_header) {
retval = (*curr)->verify_header((unsigned char *)ptr,
sbuf->st_size, params);

if (retval == 0) {
/*
* Print the image information if verify is
* successful
*/
if (curr->print_header) {
curr->print_header(ptr);
if ((*curr)->print_header) {
(*curr)->print_header(ptr);
} else {
fprintf(stderr,
"%s: print_header undefined for %s\n",
params->cmdname, curr->name);
params->cmdname, (*curr)->name);
}
break;
}
Expand Down
56 changes: 45 additions & 11 deletions tools/imagetool.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
#include <unistd.h>
#include <u-boot/sha1.h>

/* define __KERNEL__ in order to get the definitions
* required by the linker list. This is probably not
* the best way to do this */
#ifndef __KERNEL__
#define __KERNEL__
#include <linker_lists.h>
#undef __KERNEL__
#endif /* __KERNEL__ */

#include "fdt_host.h"

#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
Expand Down Expand Up @@ -194,6 +185,46 @@ int imagetool_save_subimage(

void pbl_load_uboot(int fd, struct image_tool_params *mparams);

#define ___cat(a, b) a ## b
#define __cat(a, b) ___cat(a, b)

/* we need some special handling for this host tool running eventually on
* Darwin. The Mach-O section handling is a bit different than ELF section
* handling. The differnces in detail are:
* a) we have segments which have sections
* b) we need a API call to get the respective section symbols */
#if defined(__MACH__)
#include <mach-o/getsect.h>

#define INIT_SECTION(name) do { \
unsigned long name ## _len; \
char *__cat(pstart_, name) = getsectdata("__TEXT", \
#name, &__cat(name, _len)); \
char *__cat(pstop_, name) = __cat(pstart_, name) + \
__cat(name, _len); \
__cat(__start_, name) = (void *)__cat(pstart_, name); \
__cat(__stop_, name) = (void *)__cat(pstop_, name); \
} while (0)
#define SECTION(name) __attribute__((section("__TEXT, " #name)))

struct image_type_params **__start_image_type, **__stop_image_type;
#else
#define INIT_SECTION(name) /* no-op for ELF */
#define SECTION(name) __attribute__((section(#name)))

/* We construct a table of pointers in an ELF section (pointers generally
* go unpadded by gcc). ld creates boundary syms for us. */
extern struct image_type_params *__start_image_type[], *__stop_image_type[];
#endif /* __MACH__ */

#if !defined(__used)
# if __GNUC__ == 3 && __GNUC_MINOR__ < 3
# define __used __attribute__((__unused__))
# else
# define __used __attribute__((__used__))
# endif
#endif

#define U_BOOT_IMAGE_TYPE( \
_id, \
_name, \
Expand All @@ -208,7 +239,8 @@ void pbl_load_uboot(int fd, struct image_tool_params *mparams);
_fflag_handle, \
_vrec_header \
) \
ll_entry_declare(struct image_type_params, _id, image_type) = { \
static struct image_type_params __cat(image_type_, _id) = \
{ \
.name = _name, \
.header_size = _header_size, \
.hdr = _header, \
Expand All @@ -220,6 +252,8 @@ void pbl_load_uboot(int fd, struct image_tool_params *mparams);
.check_image_type = _check_image_type, \
.fflag_handle = _fflag_handle, \
.vrec_header = _vrec_header \
}
}; \
static struct image_type_params *SECTION(image_type) __used \
__cat(image_type_ptr_, _id) = &__cat(image_type_, _id)

#endif /* _IMAGETOOL_H_ */
24 changes: 0 additions & 24 deletions tools/imagetool.lds

This file was deleted.

0 comments on commit 1fddd7b

Please sign in to comment.