0

I'm trying to build a bare metal hypervisor for raspberry pi 4 and I have cros-compile the proejct. I need to statically link libfdt library.

I have an existing Makefile for my project(Makefile):

ARMGNU ?= aarch64-linux-gnu

COPS = -Wall -nostdlib -nostartfiles -ffreestanding -Iinclude 
ASMOPS = -Iinclude 

BUILD_DIR = build
SRC_DIR = src

all : kernel8.img

clean :
    rm -rf $(BUILD_DIR) *.img 

$(BUILD_DIR)/%_c.o: $(SRC_DIR)/%.c
    mkdir -p $(@D)
    $(ARMGNU)-gcc $(COPS) -MMD -c $< -o $@

$(BUILD_DIR)/%_s.o: $(SRC_DIR)/%.S
    $(ARMGNU)-gcc $(ASMOPS) -MMD -c $< -o $@

C_FILES = $(wildcard $(SRC_DIR)/*.c)
ASM_FILES = $(wildcard $(SRC_DIR)/*.S)
OBJ_FILES = $(C_FILES:$(SRC_DIR)/%.c=$(BUILD_DIR)/%_c.o)
OBJ_FILES += $(ASM_FILES:$(SRC_DIR)/%.S=$(BUILD_DIR)/%_s.o)

DEP_FILES = $(OBJ_FILES:%.o=%.d)
-include $(DEP_FILES)

kernel8.img: $(SRC_DIR)/linker.ld $(OBJ_FILES)
    $(ARMGNU)-ld -T $(SRC_DIR)/linker.ld -o $(BUILD_DIR)/kernel8.elf  $(OBJ_FILES)
    $(ARMGNU)-objcopy $(BUILD_DIR)/kernel8.elf -O binary el2-kernel.img

Here's libfdt's Makefile (Makefile.libfdt):

# Makefile.libfdt
#
# This is not a complete Makefile of itself.  Instead, it is designed to
# be easily embeddable into other systems of Makefiles.
#
LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1
LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h
LIBFDT_VERSION = version.lds
LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \
    fdt_addresses.c fdt_overlay.c acpi.c
LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)

How will I be able to statically link libfdt to my project?

  • "How will I be able to statically link libfdt to my project?" - Is your problem is **linking** or **creating** a libfdt static library? For **link**, just add libfdt library into the linker's command line (the one started with `$(ARMGNU)-ld`). If you don't know how to **create** a static library with Makefile, then there is a LOT of examples in the internet. E.g. [that answer](https://stackoverflow.com/a/31421842/3440745). – Tsyvarev Jan 28 '22 at 12:19
  • @Tsyvarev Thank you. I will first need to compile the libfdt and then link it statically with the existing Makefile. Makefile.libfdt above says that it is embeddable Makefile, but I can't figure out to embed the Makefile.libfdt with existing Makefile. – Mushahid Hussain Jan 28 '22 at 12:31
  • Variable `LIBFDT_SRCS` contains all sources of the libfdt library. There are plenty ways for create a library from that sources. See e.g. [that question](https://stackoverflow.com/questions/27942565/makefile-to-compile-lists-of-source-files) and its answers. – Tsyvarev Jan 28 '22 at 12:39
  • Question requires previous research. there are already plenty of solutions on internet – PerroNoob Feb 07 '22 at 14:38

0 Answers0