Skip to content

Commit

Permalink
ARM: images: use piggydata
Browse files Browse the repository at this point in the history
The way we assemble the multi images on ARM is rather complicated and
error prone. We currently cat the compressed barebox image behind the
PBL executable and need some magic to obtain the size of the payload and
also have to do tricks to reliably get a pointer to the compressed
image.

This patch switches over to compile the compressed payload into the PBL
image itself which has proven to work for the single PBL case and for
the ARM Linux Kernel aswell.

The goal is to unify the single PBL and the multi PBL cases together in
the future to get an easier startup path for ARM.

This patch has been tested on the i.MX53 QSB, i.MX53 Vincell, Beaglebone
black (both MLO and 2nd stage) and a Phytec phyFLEX i.MX6 board.

SoCFPGA Arria10 has also be changed slightly with this patch. We used to
generate a single image (barebox-socfpga-achilles.img) which was
used as xload image and full image. We now instead generate two images:
barebox-socfpga-achilles-xload.img and barebox-socfpga-achilles.img, the
former loaded by the ROM and the latter loaded by the xload image.

Signed-off-by: Sascha Hauer <[email protected]>
  • Loading branch information
saschahauer committed Dec 3, 2018
1 parent 4cd2237 commit 5a1a5ed
Show file tree
Hide file tree
Showing 20 changed files with 539 additions and 589 deletions.
15 changes: 7 additions & 8 deletions arch/arm/boards/reflex-achilles/lowlevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,17 @@ static noinline void achilles_start(void)
arria10_start_image(barebox);
}

ENTRY_FUNCTION(start_socfpga_achilles_xload, r0, r1, r2)
{
arm_cpu_lowlevel_init();
arm_setup_stack(ARRIA10_OCRAM_ADDR + SZ_256K - 32);
achilles_start();
}

ENTRY_FUNCTION(start_socfpga_achilles, r0, r1, r2)
{
void *fdt;

if (get_pc() > ARRIA10_OCRAM_ADDR) {
arm_cpu_lowlevel_init();

arm_setup_stack(ARRIA10_OCRAM_ADDR + SZ_256K - 32);

achilles_start();
}

fdt = __dtb_socfpga_arria10_achilles_start + get_runtime_offset();

barebox_arm_entry(0x0, SZ_2G + SZ_1G, fdt);
Expand Down
1 change: 0 additions & 1 deletion arch/arm/cpu/sections.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ char __bss_start[0] __attribute__((section(".__bss_start")));
char __bss_stop[0] __attribute__((section(".__bss_stop")));
char __image_start[0] __attribute__((section(".__image_start")));
char __image_end[0] __attribute__((section(".__image_end")));
uint32_t __image_end_marker[1] __attribute__((section(".__image_end_marker"))) = { 0xdeadbeef };
18 changes: 7 additions & 11 deletions arch/arm/cpu/uncompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,21 @@
unsigned long free_mem_ptr;
unsigned long free_mem_end_ptr;

extern unsigned char input_data[];
extern unsigned char input_data_end[];

void __noreturn barebox_multi_pbl_start(unsigned long membase,
unsigned long memsize, void *boarddata)
{
uint32_t pg_len, uncompressed_len;
void __noreturn (*barebox)(unsigned long, unsigned long, void *);
unsigned long endmem = membase + memsize;
unsigned long barebox_base;
uint32_t *image_end;
void *pg_start;
void *pg_start, *pg_end;
unsigned long pc = get_pc();

image_end = (void *)__image_end_marker + global_variable_offset();
pg_start = input_data + global_variable_offset();
pg_end = input_data_end + global_variable_offset();

if (IS_ENABLED(CONFIG_PBL_RELOCATABLE)) {
/*
Expand All @@ -62,14 +65,7 @@ void __noreturn barebox_multi_pbl_start(unsigned long membase,
relocate_to_adr(membase);
}

/*
* image_end is the image_end_marker defined above. It is the last location
* in the executable. Right after the executable the build process adds
* the size of the appended compressed binary followed by the compressed
* binary itself.
*/
pg_start = image_end + 2;
pg_len = *(image_end + 1);
pg_len = pg_end - pg_start;
uncompressed_len = get_unaligned((const u32 *)(pg_start + pg_len - 4));

if (IS_ENABLED(CONFIG_RELOCATABLE))
Expand Down
1 change: 0 additions & 1 deletion arch/arm/include/asm/sections.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ extern char __dynsym_start[];
extern char __dynsym_end[];
extern char __exceptions_start[];
extern char __exceptions_stop[];
extern uint32_t __image_end_marker[];

#endif

Expand Down
6 changes: 3 additions & 3 deletions arch/arm/lib/pbl.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ SECTIONS
{
. = BASE;

.image_start : { *(.__image_start) }

PRE_IMAGE

. = ALIGN(4);
Expand Down Expand Up @@ -91,9 +93,7 @@ SECTIONS
}
__piggydata_end = .;

. = ALIGN(4);
.image_end : { *(.__image_end_marker) }
__image_end = .;
.image_end : { *(.__image_end) }

_barebox_image_size = __image_end - BASE;
_barebox_pbl_size = __bss_start - BASE;
Expand Down
21 changes: 1 addition & 20 deletions arch/arm/mach-imx/xload-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,6 @@

int imx_image_size(void)
{
uint32_t *image_end = (void *)__image_end;
uint32_t payload_len, pbl_len, imx_header_len, sizep;
void *pg_start;

pg_start = image_end + 1;

/* i.MX header is 4k */
imx_header_len = SZ_4K;

/* The length of the PBL image */
pbl_len = __image_end - _text;

sizep = 4;

/* The length of the payload is appended directly behind the PBL */
payload_len = *(image_end);

pr_debug("%s: payload_len: 0x%08x pbl_len: 0x%08x\n",
__func__, payload_len, pbl_len);

return imx_header_len + pbl_len + sizep + payload_len;
return barebox_image_size + SZ_4K;
}
2 changes: 0 additions & 2 deletions images/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
*.pbl
*.pblx.*
*.pblx
*.pblb
*.img
*.imximg
Expand Down
44 changes: 17 additions & 27 deletions images/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
# encapsulated in SoC (or SoC boot type) specific image formats.
#
# The basic idea here is that we generate a single barebox main binary. This
# is compressed and prepended with a self extractor, generated as barebox.x.
# barebox.x is then prepended with different board specific pbls. The pbls
# is compressed and included into a board specific PBL image. The PBL images
# are generally named after their entrypoints. So a pcm038 specific pbl will
# generate the following files:
#
# start_imx27_pcm038.pbl - The ELF file, linked with the entrypoint start_imx27_pcm038
# start_imx27_pcm038.pblb - The raw binary of the above.
# start_imx27_pcm038.pblx - The pblb appended with barebox.x
# start_imx27_pcm038.pbl.map - The linker map file
# start_imx27_pcm038.pbl.s - the disassembled ELF, generated with:
# make images/start_imx27_pcm038.pbl.s
Expand All @@ -25,21 +23,21 @@
#
# For CONFIG_MACH_FREESCALE_MX51_PDK build barebox-imx51-babbage.img
#
## FILE_barebox-imx51-babbage.img = start_imx51_babbage.pblx.imximg
## FILE_barebox-imx51-babbage.img = start_imx51_babbage.pblb.imximg
#
# barebox-imx51-babbage.img should be generated (copied) from
# start_imx51_babbage.pblx.imximg. This copy process is only done so that we
# start_imx51_babbage.pblb.imximg. This copy process is only done so that we
# can generate images with a sane name. So what we really need for this
# board is a i.MX specific image, a .imximg
#
## CFG_start_imx51_babbage.pblx.imximg = $(board)/freescale-mx51-pdk/flash-header.imxcfg
## CFG_start_imx51_babbage.pblb.imximg = $(board)/freescale-mx51-pdk/flash-header.imxcfg
#
# The .imximg can be generated from a .pblx using a rule specified in Makefile.imx.
# The .imximg can be generated from a .pblb using a rule specified in Makefile.imx.
# The configfile needed for this image is specified with CFG_<filename> = <configfile>
#
## pblx-$(CONFIG_MACH_FREESCALE_MX51_PDK) += start_imx51_babbage
## pblb-$(CONFIG_MACH_FREESCALE_MX51_PDK) += start_imx51_babbage
#
# For this image we need a pblx (self extracting barebox binary) with
# For this image we need a pblb (self extracting barebox binary) with
# start_imx51_babbage as entrypoint. start_imx51_babbage will be used
# both as entrypoint and as filename
#
Expand All @@ -57,27 +55,18 @@ quiet_cmd_elf__ ?= LD $@
cmd_elf__ ?= $(LD) $(LDFLAGS_barebox) --gc-sections -pie \
-e $(2) -Map $@.map $(LDFLAGS_$(@F)) -o $@ \
-T $(pbl-lds) \
--start-group $(barebox-pbl-common) --end-group
--start-group $(barebox-pbl-common) $(obj)/piggy.o --end-group

PBL_CPPFLAGS += -fdata-sections -ffunction-sections

$(obj)/%.pbl: $(pbl-lds) $(barebox-pbl-common) FORCE
piggy_o := piggy.$(suffix_y).o

$(obj)/%.pbl: $(pbl-lds) $(barebox-pbl-common) $(obj)/piggy.o FORCE
$(call if_changed,elf__,$(*F))

$(obj)/%.pblb: $(obj)/%.pbl FORCE
$(call if_changed,objcopy_bin,$(*F))

quiet_cmd_pblx ?= PBLX $@
cmd_pblx ?= cat $(obj)/$(patsubst %.pblx,%.pblb,$(2)) > $@; \
$(call size_append, $(obj)/barebox.z) >> $@; \
cat $(obj)/barebox.z >> $@; \
$(objtree)/scripts/fix_size -f $@

$(obj)/%.pblx: $(obj)/%.pblb $(obj)/barebox.z FORCE
$(call if_changed,pblx,$(@F))
$(call cmd,check_file_size,$@,$(CONFIG_BAREBOX_MAX_PBLX_SIZE))


$(obj)/%.s: $(obj)/% FORCE
$(call if_changed,disasm)

Expand All @@ -87,6 +76,8 @@ suffix_$(CONFIG_IMAGE_COMPRESSION_LZ4) = lz4
suffix_$(CONFIG_IMAGE_COMPRESSION_XZKERN) = xzkern
suffix_$(CONFIG_IMAGE_COMPRESSION_NONE) = comp_copy

$(obj)/piggy.o: $(obj)/barebox.z FORCE

# barebox.z - compressed barebox binary
# ----------------------------------------------------------------
$(obj)/barebox.z: $(obj)/../barebox.bin FORCE
Expand Down Expand Up @@ -115,10 +106,9 @@ include $(srctree)/images/Makefile.vexpress
include $(srctree)/images/Makefile.at91

targets += $(image-y) pbl.lds barebox.x barebox.z
targets += $(patsubst %,%.pblx,$(pblx-y))
targets += $(patsubst %,%.pblb,$(pblx-y))
targets += $(patsubst %,%.pbl,$(pblx-y))
targets += $(patsubst %,%.s,$(pblx-y))
targets += $(patsubst %,%.pblb,$(pblb-y))
targets += $(patsubst %,%.pbl,$(pblb-y))
targets += $(patsubst %,%.s,$(pblb-y))
targets += $(foreach m, $(image-y), $(FILE_$(m)))

SECONDARY: $(addprefix $(obj)/,$(targets))
Expand All @@ -143,7 +133,7 @@ $(flash-link): $(link-dest) FORCE
$(flash-list): $(image-y-path)
@for i in $^; do echo $$i; done > $@

clean-files := *.pbl *.pblb *.pblx *.map start_*.imximg *.img barebox.z start_*.kwbimg \
clean-files := *.pbl *.pblb *.map start_*.imximg *.img barebox.z start_*.kwbimg \
start_*.kwbuartimg *.socfpgaimg *.mlo *.t20img *.t20img.cfg *.t30img \
*.t30img.cfg *.t124img *.t124img.cfg *.mlospi *.mlo *.mxsbs *.mxssd \
start_*.simximg start_*.usimximg *.imx-sram-img
Expand Down
Loading

0 comments on commit 5a1a5ed

Please sign in to comment.