From patchwork Sun Jul 15 02:44:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Domenico Andreoli X-Patchwork-Id: 1198351 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 12F03DF28C for ; Sun, 15 Jul 2012 02:55:56 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SqEvd-0000gE-C5; Sun, 15 Jul 2012 02:51:25 +0000 Received: from mail-we0-f177.google.com ([74.125.82.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SqEqd-0008VK-4C for linux-arm-kernel@lists.infradead.org; Sun, 15 Jul 2012 02:46:33 +0000 Received: by weyr3 with SMTP id r3so3441831wey.36 for ; Sat, 14 Jul 2012 19:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:user-agent:date:from:to:cc:subject:references :content-disposition; bh=DXKSugLxoOEBHgNYoE0B1whAGtGy+JW4ubPd9+ab8E8=; b=koO9LC5hrmVQZ2Mng/wasyIuTKIeD+/PBfivZuWOxZ8JNmgbqcv00Hwt/oIMB6lSN5 dQKu9Ad6HhBvjw1165ykBes7ZemaWK9aBJIMWAYPduNKjA8jCLkOnEaPXx9kCvtXBMku /PpYJjX3JgthIqpK7fgcxXqgsna+zO74d68tAcEAlk0cJeGjytt4ysi7e1AbQbslYmkK kURxqBSNGg5HqZ5hd+ActFGwOWJl8ROx05na1zbTmY6QcnJQjJNs7a0NMGCh6MXNVrTw z3JstjIgd6oQK4A4TRd1zSg9avlSRutPoHS7OCYH5OJ1PauYi+61snAGC7SzKnUaxrUt fbOQ== Received: by 10.216.131.22 with SMTP id l22mr3173125wei.96.1342320369784; Sat, 14 Jul 2012 19:46:09 -0700 (PDT) Received: from raptus.dandreoli.com (178-85-163-250.dynamic.upc.nl. [178.85.163.250]) by mx.google.com with ESMTPS id df4sm13060207wib.4.2012.07.14.19.46.08 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 14 Jul 2012 19:46:09 -0700 (PDT) Received: by raptus.dandreoli.com (Postfix, from userid 1000) id D58D737B9FF; Sun, 15 Jul 2012 04:46:08 +0200 (CEST) Message-Id: <20120715024608.575065131@gmail.com> User-Agent: quilt/0.60-1 Date: Sun, 15 Jul 2012 04:44:10 +0200 From: Domenico Andreoli To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH 02/12] ARM: kernel -> decompressor relocation handling References: <20120715024408.747946928@gmail.com> Content-Disposition: inline; filename=decomp-arch-reloc.patch X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (cavokz[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Domenico Andreoli , Russell King - ARM Linux , Arnd Bergmann X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Domenico Andreoli This is the machinery used to bring code & data from the kernel to the decompressor. This is effectively a relocation and it's done by hand, using objcopy, specific ELF sections and some care in handling pointers and strings. Signed-off-by: Domenico Andreoli --- arch/arm/boot/Makefile | 10 +++++++- arch/arm/boot/compressed/Makefile | 2 +- arch/arm/boot/compressed/arch.c | 38 ++++++++++++++++++++++++++++++++ arch/arm/boot/compressed/arch.h | 22 +++++++++++++++++++ arch/arm/boot/compressed/vmlinux.lds.in | 9 ++++++++ arch/arm/kernel/vmlinux.lds.S | 16 +++++++++++++ 6 files changed, 95 insertions(+), 2 deletions(-) Index: b/arch/arm/boot/Makefile =================================================================== --- a/arch/arm/boot/Makefile +++ b/arch/arm/boot/Makefile @@ -48,7 +48,15 @@ $(obj)/Image: vmlinux FORCE $(call if_changed,objcopy) @echo ' Kernel: $@ is ready' -$(obj)/compressed/vmlinux: $(obj)/Image FORCE +OBJCOPYFLAGS_arch_reloc.o = -O elf32-littlearm \ + -j .text.decomp \ + -j .init.decomp.data \ + -j .init.decomp.tags \ + -j .ARM.attributes +$(obj)/compressed/arch_reloc.o: vmlinux FORCE + $(call if_changed,objcopy) + +$(obj)/compressed/vmlinux: $(obj)/Image $(obj)/compressed/arch_reloc.o FORCE $(Q)$(MAKE) $(build)=$(obj)/compressed $@ $(obj)/zImage: $(obj)/compressed/vmlinux FORCE Index: b/arch/arm/boot/compressed/Makefile =================================================================== --- a/arch/arm/boot/compressed/Makefile +++ b/arch/arm/boot/compressed/Makefile @@ -23,7 +23,7 @@ endif AFLAGS_head.o += -DTEXT_OFFSET=$(TEXT_OFFSET) HEAD = head.o -OBJS += misc.o decompress.o +OBJS += misc.o decompress.o arch.o arch_reloc.o FONTC = $(srctree)/drivers/video/console/font_acorn_8x8.c # string library code (-Os is enforced to keep it much smaller) Index: b/arch/arm/boot/compressed/vmlinux.lds.in =================================================================== --- a/arch/arm/boot/compressed/vmlinux.lds.in +++ b/arch/arm/boot/compressed/vmlinux.lds.in @@ -30,6 +30,9 @@ SECTIONS _start = .; *(.start) *(.text) + . = ALIGN(4); + __decomp_text_begin = .; + *(.text.decomp) *(.text.*) *(.fixup) *(.gnu.warning) @@ -39,6 +42,12 @@ SECTIONS .rodata : { *(.rodata) *(.rodata.*) + . = ALIGN(4); + __decomp_tags_begin = .; + *(.init.decomp.tags) + __decomp_tags_end = .; + __decomp_data_begin = .; + *(.init.decomp.data) } .piggydata : { *(.piggydata) Index: b/arch/arm/kernel/vmlinux.lds.S =================================================================== --- a/arch/arm/kernel/vmlinux.lds.S +++ b/arch/arm/kernel/vmlinux.lds.S @@ -111,6 +111,11 @@ SECTIONS *(.got) /* Global offset table */ ARM_CPU_KEEP(PROC_INFO) } + .text.decomp : { + __decomp_text_begin = .; + LONG(__decomp_text_begin) + *(.arch.text.decomp) + } RO_DATA(PAGE_SIZE) @@ -150,6 +155,17 @@ SECTIONS *(.arch.info.init) __arch_info_end = .; } + .init.decomp.tags : { + __decomp_tags_begin = .; + *(.arch.tags.decomp) + __decomp_tags_end = .; + } + .init.decomp.data : { + __decomp_data_begin = .; + LONG(__decomp_data_begin) + *(.arch.data.decomp) + __decomp_data_end = .; + } .init.tagtable : { __tagtable_begin = .; *(.taglist.init) Index: b/arch/arm/boot/compressed/arch.c =================================================================== --- /dev/null +++ b/arch/arm/boot/compressed/arch.c @@ -0,0 +1,38 @@ +/* + * Decompressor arch specific stuff + * + * Copyright (C) 2012 Domenico Andreoli + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include + +#include "arch.h" + +/* defined in the linker script */ +extern void *__decomp_text_begin; +extern void *__decomp_data_begin; + +const void *fix_text_ptr(const void *p) +{ + if (!p) + return NULL; + + return ((void *) &__decomp_text_begin) + (p - __decomp_text_begin); +} + +const void *fix_data_ptr(const void *p) +{ + if (!p) + return NULL; + + return ((void *) &__decomp_data_begin) + (p - __decomp_data_begin); +} Index: b/arch/arm/boot/compressed/arch.h =================================================================== --- /dev/null +++ b/arch/arm/boot/compressed/arch.h @@ -0,0 +1,22 @@ +/* + * Common definitions used in the decompressor arch stuff + * + * Copyright (C) 2012 Domenico Andreoli + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef ARM_BOOT_COMPRESSED_ARCH_H +#define ARM_BOOT_COMPRESSED_ARCH_H + +const void *fix_text_ptr(const void *p); +const void *fix_data_ptr(const void *p); + +#endif /* ARM_BOOT_COMPRESSED_ARCH_H */