[LINUX] Lesen Sie etwas mehr Arch / Arm / Boot / Compressed / Makefile

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/compressed/Makefile?h=master

Lesen Sie den Inhalt des Makefiles. Lassen Sie den fdt-Teil weg, an dem Sie nicht interessiert sind.

TEXT-Bereichseinstellungen usw.

arch/arm/boot/compressed/Makefile


# SPDX-License-Identifier: GPL-2.0
#
# linux/arch/arm/boot/compressed/Makefile
#
# create a compressed vmlinuz image from the original vmlinux
#

OBJS		=
AFLAGS_head.o += -DTEXT_OFFSET=$(TEXT_OFFSET)

Dies bedeutet, dass beim Erstellen von head.o die Option TEXT_OFFSET hinzugefügt wird.

TEXT_OFFSET $ (TEXT_OFFSET) ist in arch / arm / Makefile definiert.

arch/arm/Makefile


# Text offset. This list is sorted numerically by address in order to
# provide a means to avoid/resolve conflicts in multi-arch kernels.
textofs-y	:= 0x00008000
# We don't want the htc bootloader to corrupt kernel during resume
textofs-$(CONFIG_PM_H1940)      := 0x00108000
# SA1111 DMA bug: we don't want the kernel to live in precious DMA-able memory
ifeq ($(CONFIG_ARCH_SA1100),y)
textofs-$(CONFIG_SA1111) := 0x00208000
endif
textofs-$(CONFIG_ARCH_IPQ40XX) := 0x00208000
textofs-$(CONFIG_ARCH_MSM8X60) := 0x00208000
textofs-$(CONFIG_ARCH_MSM8960) := 0x00208000
textofs-$(CONFIG_ARCH_MESON) := 0x00208000
textofs-$(CONFIG_ARCH_AXXIA) := 0x00308000

(Weggelassen)

TEXT_OFFSET := $(textofs-y)

Code, der tatsächlich als Kernel verarbeitet wird (head. * / Misc. * / Decompress. *)

arch/arm/boot/compressed/Makefile


HEAD	= head.o
OBJS	+= misc.o decompress.o

head.S Dies ist die Logik des komprimierten Linux-Kernel-Erweiterungsabschnitts.

Machen Sie verschiedene Dinge, aber rufen Sie decompress_kernel auf.

arch/arm/boot/compressed/head.S


/*
 * The C runtime environment should now be setup sufficiently.
 * Set up some pointers, and start decompressing.
 *   r4  = kernel execution address
 *   r7  = architecture ID
 *   r8  = atags pointer
 */
		mov	r0, r4
		mov	r1, sp			@ malloc space above stack
		add	r2, sp, #0x10000	@ 64k max
		mov	r3, r7
		bl	decompress_kernel

misc.S Der Hauptteil von decompress_kernel () wird beschrieben.

Tatsächlich wird daraus do_decompress () aufgerufen.

arch/arm/boot/compressed/misc.c


void
decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
		unsigned long free_mem_ptr_end_p,
		int arch_id)
{
	int ret;

	output_data		= (unsigned char *)output_start;
	free_mem_ptr		= free_mem_ptr_p;
	free_mem_end_ptr	= free_mem_ptr_end_p;
	__machine_arch_type	= arch_id;

	arch_decomp_setup();

	putstr("Uncompressing Linux...");
	ret = do_decompress(input_data, input_data_end - input_data,
			    output_data, error);
	if (ret)
		error("decompressor returned an error");
	else
		putstr(" done, booting the kernel.\n");
}

decompress.S

Der Teil, der durch Aufrufen von __decompress () jedes Komprimierungsmoduls dekomprimiert werden soll.

arch/arm/boot/compressed/decompress.c


#ifdef CONFIG_KERNEL_GZIP
#include "../../../../lib/decompress_inflate.c"
#endif

#ifdef CONFIG_KERNEL_LZO
#include "../../../../lib/decompress_unlzo.c"
#endif

#ifdef CONFIG_KERNEL_LZMA
#include "../../../../lib/decompress_unlzma.c"
#endif

#ifdef CONFIG_KERNEL_XZ
#define memmove memmove
#define memcpy memcpy
#include "../../../../lib/decompress_unxz.c"
#endif

#ifdef CONFIG_KERNEL_LZ4
#include "../../../../lib/decompress_unlz4.c"
#endif

int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x))
{
	return __decompress(input, len, NULL, NULL, output, 0, NULL, error);
}

Zum Beispiel für lz4:

lib/decompress_unlz4.c


#ifdef PREBOOT
STATIC int INIT __decompress(unsigned char *buf, long in_len,
                  long (*fill)(void*, unsigned long),
                  long (*flush)(void*, unsigned long),
                  unsigned char *output, long out_len,
                  long *posp,
                  void (*error)(char *x)
    )
{
    return unlz4(buf, in_len - 4, fill, flush, output, posp, error);
}
#endif

Zeichenausgabe für das Debuggen

arch/arm/boot/compressed/Makefile


ifeq ($(CONFIG_DEBUG_UNCOMPRESS),y)
OBJS	+= debug.o
endif
FONTC	= $(srctree)/lib/fonts/font_acorn_8x8.c

Ich denke, font_acorn_8x8.c wird nur für Eicheln verwendet ...

DEBUG_UNCOMPRESS

DEBUG_UNCOMPRESS ist in KConfig.debug definiert.

Diese Option betrifft die Ausgabe des Dekomprimierers auf dem Multiplattform-Kernel. Normalerweise ist der Dekomprimierer nicht für Multiplattform-Kernel geeignet. Weil ich nicht weiß, wohin ich den Dekompressorausgang senden soll.

Wenn diese Option aktiviert ist, wird sie von den Ausgabemitteln DEBUG_LL wiederverwendet.

Sie können es also debuggen.

arch/arm/Kconfig.debug


config DEBUG_UNCOMPRESS
	bool "Enable decompressor debugging via DEBUG_LL output"
	depends on ARCH_MULTIPLATFORM || PLAT_SAMSUNG || ARM_SINGLE_ARMV7M
	depends on DEBUG_LL && !DEBUG_OMAP2PLUS_UART && \
		     (!DEBUG_TEGRA_UART || !ZBOOT_ROM) && \
		     !DEBUG_BRCMSTB_UART
	help
	  This option influences the normal decompressor output for
	  multiplatform kernels.  Normally, multiplatform kernels disable
	  decompressor output because it is not possible to know where to
	  send the decompressor output.

	  When this option is set, the selected DEBUG_LL output method
	  will be re-used for normal decompressor output on multiplatform
	  kernels.

debug.S

debug.s wird für die Implementierung von putc () verwendet. Wenn CONFIG_DEBUG_SEMIHOSTING deaktiviert ist, druckt adduart / waituart / senduart / busyuart die Zeichen auf der Konsole.

arm/boot/compressed/debug.S


/* SPDX-License-Identifier: GPL-2.0 */
#include <linux/linkage.h>
#include <asm/assembler.h>

#ifndef CONFIG_DEBUG_SEMIHOSTING

#include CONFIG_DEBUG_LL_INCLUDE

ENTRY(putc)
	addruart r1, r2, r3
	waituart r3, r1
	senduart r0, r1
	busyuart r3, r1
	mov	 pc, lr
ENDPROC(putc)

#else
(Weggelassen)

string library

string.c ist eine Teilmenge wie memcpu / memmove / strlen / strnlen. Voraussichtlich eingebaut, damit sich der Dekompressor unabhängig bewegen kann, wenn er sich bewegt.

arch/arm/boot/compressed/Makefile


# string library code (-Os is enforced to keep it much smaller)
OBJS		+= string.o
CFLAGS_string.o	:= -Os

string.c

Der Inhalt ist eine Implementierung einer vereinfachten Version der in string.h definierten Funktion.

arch/arm/boot/compressed/string.c


void *memcpy(void *__dest, __const void *__src, size_t __n)
{
	int i = 0;
	unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;

	for (i = __n >> 3; i > 0; i--) {
		*d++ = *s++;
		*d++ = *s++;
		*d++ = *s++;
		*d++ = *s++;
		*d++ = *s++;
		*d++ = *s++;
		*d++ = *s++;
		*d++ = *s++;
	}

	if (__n & 1 << 2) {
		*d++ = *s++;
		*d++ = *s++;
		*d++ = *s++;
		*d++ = *s++;
	}

	if (__n & 1 << 1) {
		*d++ = *s++;
		*d++ = *s++;
	}

	if (__n & 1)
		*d++ = *s++;

	return __dest;
}

VIRT_EXT

arch/arm/boot/compressed/Makefile


ifeq ($(CONFIG_ARM_VIRT_EXT),y)
OBJS		+= hyp-stub.o
endif

ARM_VIRT_EXT

arch/arm/mm/Kconfig


config ARM_VIRT_EXT
    bool
    default y if CPU_V7
    help
      Enable the kernel to make use of the ARM Virtualization
      Extensions to install hypervisors without run-time firmware
      assistance.

      A compliant bootloader is required in order to make maximum
      use of this feature.  Refer to Documentation/arm/booting.rst for
      details.

GCOV/KCOV

Die Debugging-Funktion wurde deaktiviert.

arch/arm/boot/compressed/Makefile


GCOV_PROFILE		:= n

# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
KCOV_INSTRUMENT		:= n

Modellabhängiges Teil

Dieser Bereich ist modellabhängig und wird daher weggelassen.

arch/arm/boot/compressed/Makefile


#
# Architecture dependencies
#
ifeq ($(CONFIG_ARCH_ACORN),y)
OBJS		+= ll_char_wr.o font.o
endif

<Ausgelassen>

Adressspezifikation (ZTEXTADDR / ZBSSADDR)

arch/arm/boot/compressed/Makefile


#
# We now have a PIC decompressor implementation.  Decompressors running
# from RAM should not define ZTEXTADDR.  Decompressors running directly
# from ROM or Flash must define ZTEXTADDR (preferably via the config)
# FIXME: Previous assignment to ztextaddr-y is lost here. See SHARK
ifeq ($(CONFIG_ZBOOT_ROM),y)
ZTEXTADDR	:= $(CONFIG_ZBOOT_ROM_TEXT)
ZBSSADDR	:= $(CONFIG_ZBOOT_ROM_BSS)
else
ZTEXTADDR	:= 0
ZBSSADDR	:= ALIGN(8)
endif

CPPFLAGS_vmlinux.lds := -DTEXT_START="$(ZTEXTADDR)" -DBSS_START="$(ZBSSADDR)"

Bestätigung der Komprimierungsmethode

Geben Sie das in KConfig angegebene Komprimierungsformat an.

arch/arm/boot/compressed/Makefile



compress-$(CONFIG_KERNEL_GZIP) = gzip
compress-$(CONFIG_KERNEL_LZO)  = lzo
compress-$(CONFIG_KERNEL_LZMA) = lzma
compress-$(CONFIG_KERNEL_XZ)   = xzkern
compress-$(CONFIG_KERNEL_LZ4)  = lz4

fdt Teil (weggelassen)

arch/arm/boot/compressed/Makefile



# Borrowed libfdt files for the ATAG compatibility mode
<Ausgelassen>

Einstellungen für Ziel- / Bereinigungsdateien für Make

arch/arm/boot/compressed/Makefile


targets       := vmlinux vmlinux.lds piggy_data piggy.o \
		 lib1funcs.o ashldi3.o bswapsdi2.o \
		 head.o $(OBJS)

clean-files += piggy_data lib1funcs.S ashldi3.S bswapsdi2.S \
		$(libfdt) $(libfdt_hdrs) hyp-stub.S

KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING

ifeq ($(CONFIG_FUNCTION_TRACER),y)
ORIG_CFLAGS := $(KBUILD_CFLAGS)
KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
endif

fdt teil 2 (weggelassen)

Es scheint noch früh zu sein, Stack-Protector-Strong zu verwenden.

arch/arm/boot/compressed/Makefile


# -fstack-protector-strong triggers protection checks in this code,
# but it is being used too early to link to meaningful stack_chk logic.
nossp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector
CFLAGS_atags_to_fdt.o := $(nossp-flags-y)
<Ausgelassen>

BSS-Größenspezifikation.

Es scheint, dass es zwischen \ _ \ _ bss_start und \ _ \ _ bss_stop berechnet wird. Es wird Linker als Option mitgeteilt.

arch/arm/boot/compressed/Makefile


# Supply kernel BSS size to the decompressor via a linker symbol.
KBSS_SZ = $(shell echo $$(($$($(NM) $(obj)/../../../../vmlinux | \
		sed -n -e 's/^\([^ ]*\) [AB] __bss_start$$/-0x\1/p' \
		       -e 's/^\([^ ]*\) [AB] __bss_stop$$/+0x\1/p') )) )
LDFLAGS_vmlinux = --defsym _kernel_bss_size=$(KBSS_SZ)
# Supply ZRELADDR to the decompressor via a linker symbol.
ifneq ($(CONFIG_AUTO_ZRELADDR),y)
LDFLAGS_vmlinux += --defsym zreladdr=$(ZRELADDR)
endif

Andere Einstellungen beim Verknüpfen von vmlinux

arch/arm/boot/compressed/Makefile


ifeq ($(CONFIG_CPU_ENDIAN_BE8),y)
LDFLAGS_vmlinux += --be8
endif
# Report unresolved symbol references
LDFLAGS_vmlinux += --no-undefined
# Delete all temporary local symbols
LDFLAGS_vmlinux += -X
# Next argument is a linker script
LDFLAGS_vmlinux += -T

Korrespondenz für nicht vorhandene Anweisungen.

Bereitstellung von Code, der darauf vorbereitet ist, mit nicht vorhandenen Funktionen in Konflikt zu geraten.

arch/arm/boot/compressed/Makefile


# For __aeabi_uidivmod
lib1funcs = $(obj)/lib1funcs.o

$(obj)/lib1funcs.S: $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.S
	$(call cmd,shipped)

# For __aeabi_llsl
ashldi3 = $(obj)/ashldi3.o

$(obj)/ashldi3.S: $(srctree)/arch/$(SRCARCH)/lib/ashldi3.S
	$(call cmd,shipped)

# For __bswapsi2, __bswapdi2
bswapsdi2 = $(obj)/bswapsdi2.o

$(obj)/bswapsdi2.S: $(srctree)/arch/$(SRCARCH)/lib/bswapsdi2.S
	$(call cmd,shipped)

lib1funcs.S Es scheint eine Divisionsoptimierungsroutine zu sein.

https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html

Die folgenden Funktionen usw. sind enthalten.

Runtime Function: int __divsi3 (int a, int b) Runtime Function: long __divdi3 (long a, long b) Runtime Function: long long __divti3 (long long a, long long b)   These functions return the quotient of the signed division of a and b.

arch/arm/lib/lib1funcs.S


/*
 * linux/arch/arm/lib/lib1funcs.S: Optimized ARM division routines
 *
 * Author: Nicolas Pitre <[email protected]>
 *   - contributed to gcc-3.4 on Sep 30, 2003
 *   - adapted for the Linux kernel on Oct 2, 2003
 */

ashldi3.S/bswapsdi2.S https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html

Hier finden Sie eine Beschreibung der Funktion.

Runtime Function: int __ashlsi3 (int a, int b) Runtime Function: long __ashldi3 (long a, int b) Runtime Function: long long __ashlti3 (long long a, int b)   These functions return the result of shifting a left by b bits.

Runtime Function: int32_t __bswapsi2 (int32_t a) Runtime Function: int64_t __bswapdi2 (int64_t a)   These functions return the a byteswapped.

Überprüfen Sie das Symbol.

"Die folgenden Symbole dürfen nicht im lokalen / privaten Bereich liegen", sagte er.

arch/arm/boot/compressed/Makefile



# We need to prevent any GOTOFF relocs being used with references
# to symbols in the .bss section since we cannot relocate them
# independently from the rest at run time.  This can be achieved by
# ensuring that no private .bss symbols exist, as global symbols
# always have a GOT entry which is what we need.
# The .data section is already discarded by the linker script so no need
# to bother about it here.
check_for_bad_syms = \
bad_syms=$$($(NM) $@ | sed -n 's/^.\{8\} [bc] \(.*\)/\1/p') && \
[ -z "$$bad_syms" ] || \
  ( echo "following symbols must have non local/private scope:" >&2; \
    echo "$$bad_syms" >&2; false )

ZRELADDR-bezogene Prüfung

Wenn ZRELADDR nicht gesetzt ist und AUTO_ZRELADDR nicht gesetzt ist, werde ich wütend?

arch/arm/boot/compressed/Makefile


check_for_multiple_zreladdr = \
if [ $(words $(ZRELADDR)) -gt 1 -a "$(CONFIG_AUTO_ZRELADDR)" = "" ]; then \
	echo 'multiple zreladdrs: $(ZRELADDR)'; \
	echo 'This needs CONFIG_AUTO_ZRELADDR to be set'; \
	false; \
fi

EFI-kompatibel

(Ohne Interesse weggelassen)

arch/arm/boot/compressed/Makefile


efi-obj-$(CONFIG_EFI_STUB) := $(objtree)/drivers/firmware/efi/libstub/lib.a

Wie mache ich vmlinux! !! (Dies ist die letzte Zeile)

arch/arm/boot/compressed/Makefile


$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.o \
		$(addprefix $(obj)/, $(OBJS)) $(lib1funcs) $(ashldi3) \
		$(bswapsdi2) $(efi-obj-y) FORCE
	@$(check_for_multiple_zreladdr)
	$(call if_changed,ld)
	@$(check_for_bad_syms)

Bild komprimieren

compress-y enthält den Kompressor, der in der Form compress- $ (CONFIG_KERNEL_XXXX) = CMD angegeben ist. Verwenden Sie diese Option, um Image in piggy_data zu konvertieren

arch/arm/boot/compressed/Makefile



$(obj)/piggy_data: $(obj)/../Image FORCE
	$(call if_changed,$(compress-y))

$(obj)/piggy.o: $(obj)/piggy_data

piggy.S

Ich habe piggy_data als Binärdaten importiert.

arch/arm/boot/compressed/piggy.S


/* SPDX-License-Identifier: GPL-2.0 */
	.section .piggydata, "a"
	.globl	input_data
input_data:
	.incbin	"arch/arm/boot/compressed/piggy_data"
	.globl	input_data_end
input_data_end:

Geben Sie danach verschiedene Optionen an

arch/arm/boot/compressed/Makefile



CFLAGS_font.o := -Dstatic=

$(obj)/font.c: $(FONTC)
	$(call cmd,shipped)

AFLAGS_hyp-stub.o := -Wa,-march=armv7-a

$(obj)/hyp-stub.S: $(srctree)/arch/$(SRCARCH)/kernel/hyp-stub.S
	$(call cmd,shipped)

Recommended Posts

Lesen Sie etwas mehr Arch / Arm / Boot / Compressed / Makefile
Lesen Sie arch / arm / oprofile / common.c
Ein bisschen mehr über FIFO
Ein wenig mehr Details zur Einschlussnotation von Python
Python-Ausnahmebehandlung etwas bequemer