Commit 1fddd7b63c69b8da40b5dc737db0382f473f9644

Authored by Andreas Bießmann
Committed by Tom Rini
1 parent 312aca4e69

tools/imagetool: remove linker script

Commit a93648d197df48fa46dd55f925ff70468bd81c71 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 <andreas.devel@googlemail.com>
Cc: Guilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>

Showing 5 changed files with 67 additions and 55 deletions Side-by-side Diff

... ... @@ -281,6 +281,11 @@
281 281 HOSTCC = $(call os_x_before, 10, 5, "cc", "gcc")
282 282 HOSTCFLAGS += $(call os_x_before, 10, 4, "-traditional-cpp")
283 283 HOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress")
  284 +
  285 +# since Lion (10.7) ASLR is on by default, but we use linker generated lists
  286 +# in some host tools which is a problem then ... so disable ASLR for these
  287 +# tools
  288 +HOSTLDFLAGS += $(call os_x_before, 10, 7, "", "-Xlinker -no_pie")
284 289 endif
285 290  
286 291 # Decide whether to build built-in, modular, or both.
... ... @@ -128,8 +128,6 @@
128 128 HOSTLOADLIBES_fit_info := $(HOSTLOADLIBES_mkimage)
129 129 HOSTLOADLIBES_fit_check_sign := $(HOSTLOADLIBES_mkimage)
130 130  
131   -HOSTLDFLAGS += -T $(srctree)/tools/imagetool.lds
132   -
133 131 hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl
134 132 hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
135 133 HOSTCFLAGS_mkexynosspl.o := -pedantic
... ... @@ -12,16 +12,16 @@
12 12  
13 13 struct image_type_params *imagetool_get_type(int type)
14 14 {
15   - struct image_type_params *curr;
16   - struct image_type_params *start = ll_entry_start(
17   - struct image_type_params, image_type);
18   - struct image_type_params *end = ll_entry_end(
19   - struct image_type_params, image_type);
  15 + struct image_type_params **curr;
  16 + INIT_SECTION(image_type);
20 17  
  18 + struct image_type_params **start = __start_image_type;
  19 + struct image_type_params **end = __stop_image_type;
  20 +
21 21 for (curr = start; curr != end; curr++) {
22   - if (curr->check_image_type) {
23   - if (!curr->check_image_type(type))
24   - return curr;
  22 + if ((*curr)->check_image_type) {
  23 + if (!(*curr)->check_image_type(type))
  24 + return *curr;
25 25 }
26 26 }
27 27 return NULL;
28 28  
29 29  
... ... @@ -34,16 +34,15 @@
34 34 struct image_tool_params *params)
35 35 {
36 36 int retval = -1;
37   - struct image_type_params *curr;
  37 + struct image_type_params **curr;
  38 + INIT_SECTION(image_type);
38 39  
39   - struct image_type_params *start = ll_entry_start(
40   - struct image_type_params, image_type);
41   - struct image_type_params *end = ll_entry_end(
42   - struct image_type_params, image_type);
  40 + struct image_type_params **start = __start_image_type;
  41 + struct image_type_params **end = __stop_image_type;
43 42  
44 43 for (curr = start; curr != end; curr++) {
45   - if (curr->verify_header) {
46   - retval = curr->verify_header((unsigned char *)ptr,
  44 + if ((*curr)->verify_header) {
  45 + retval = (*curr)->verify_header((unsigned char *)ptr,
47 46 sbuf->st_size, params);
48 47  
49 48 if (retval == 0) {
50 49  
... ... @@ -51,12 +50,12 @@
51 50 * Print the image information if verify is
52 51 * successful
53 52 */
54   - if (curr->print_header) {
55   - curr->print_header(ptr);
  53 + if ((*curr)->print_header) {
  54 + (*curr)->print_header(ptr);
56 55 } else {
57 56 fprintf(stderr,
58 57 "%s: print_header undefined for %s\n",
59   - params->cmdname, curr->name);
  58 + params->cmdname, (*curr)->name);
60 59 }
61 60 break;
62 61 }
... ... @@ -20,15 +20,6 @@
20 20 #include <unistd.h>
21 21 #include <u-boot/sha1.h>
22 22  
23   -/* define __KERNEL__ in order to get the definitions
24   - * required by the linker list. This is probably not
25   - * the best way to do this */
26   -#ifndef __KERNEL__
27   -#define __KERNEL__
28   -#include <linker_lists.h>
29   -#undef __KERNEL__
30   -#endif /* __KERNEL__ */
31   -
32 23 #include "fdt_host.h"
33 24  
34 25 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
... ... @@ -194,6 +185,46 @@
194 185  
195 186 void pbl_load_uboot(int fd, struct image_tool_params *mparams);
196 187  
  188 +#define ___cat(a, b) a ## b
  189 +#define __cat(a, b) ___cat(a, b)
  190 +
  191 +/* we need some special handling for this host tool running eventually on
  192 + * Darwin. The Mach-O section handling is a bit different than ELF section
  193 + * handling. The differnces in detail are:
  194 + * a) we have segments which have sections
  195 + * b) we need a API call to get the respective section symbols */
  196 +#if defined(__MACH__)
  197 +#include <mach-o/getsect.h>
  198 +
  199 +#define INIT_SECTION(name) do { \
  200 + unsigned long name ## _len; \
  201 + char *__cat(pstart_, name) = getsectdata("__TEXT", \
  202 + #name, &__cat(name, _len)); \
  203 + char *__cat(pstop_, name) = __cat(pstart_, name) + \
  204 + __cat(name, _len); \
  205 + __cat(__start_, name) = (void *)__cat(pstart_, name); \
  206 + __cat(__stop_, name) = (void *)__cat(pstop_, name); \
  207 + } while (0)
  208 +#define SECTION(name) __attribute__((section("__TEXT, " #name)))
  209 +
  210 +struct image_type_params **__start_image_type, **__stop_image_type;
  211 +#else
  212 +#define INIT_SECTION(name) /* no-op for ELF */
  213 +#define SECTION(name) __attribute__((section(#name)))
  214 +
  215 +/* We construct a table of pointers in an ELF section (pointers generally
  216 + * go unpadded by gcc). ld creates boundary syms for us. */
  217 +extern struct image_type_params *__start_image_type[], *__stop_image_type[];
  218 +#endif /* __MACH__ */
  219 +
  220 +#if !defined(__used)
  221 +# if __GNUC__ == 3 && __GNUC_MINOR__ < 3
  222 +# define __used __attribute__((__unused__))
  223 +# else
  224 +# define __used __attribute__((__used__))
  225 +# endif
  226 +#endif
  227 +
197 228 #define U_BOOT_IMAGE_TYPE( \
198 229 _id, \
199 230 _name, \
... ... @@ -208,7 +239,8 @@
208 239 _fflag_handle, \
209 240 _vrec_header \
210 241 ) \
211   - ll_entry_declare(struct image_type_params, _id, image_type) = { \
  242 + static struct image_type_params __cat(image_type_, _id) = \
  243 + { \
212 244 .name = _name, \
213 245 .header_size = _header_size, \
214 246 .hdr = _header, \
... ... @@ -220,7 +252,9 @@
220 252 .check_image_type = _check_image_type, \
221 253 .fflag_handle = _fflag_handle, \
222 254 .vrec_header = _vrec_header \
223   - }
  255 + }; \
  256 + static struct image_type_params *SECTION(image_type) __used \
  257 + __cat(image_type_ptr_, _id) = &__cat(image_type_, _id)
224 258  
225 259 #endif /* _IMAGETOOL_H_ */
tools/imagetool.lds
1   -/*
2   - * Copyright (c) 2011-2012 The Chromium OS Authors.
3   - * Use of this source code is governed by a BSD-style license that can be
4   - * found in the LICENSE file.
5   - *
6   - * SPDX-License-Identifier: GPL-2.0+
7   - */
8   -
9   -SECTIONS
10   -{
11   -
12   - . = ALIGN(4);
13   - .u_boot_list : {
14   - KEEP(*(SORT(.u_boot_list*)));
15   - }
16   -
17   - __u_boot_sandbox_option_start = .;
18   - _u_boot_sandbox_getopt : { *(.u_boot_sandbox_getopt) }
19   - __u_boot_sandbox_option_end = .;
20   -
21   - __bss_start = .;
22   -}
23   -
24   -INSERT BEFORE .data;