Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix asm-offset headers (re)generation; Generate binary with debug symbols #329

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ ACPICA_INSTALL := $(shell [ -d $(ACPICA_DEST_DIR)/source ] ||
endif

ASM_OFFSETS_C := asm-offsets.c
ASM_OFFSETS_S := asm-offsets.s
ASM_OFFSETS_H := asm-offsets.h
ASM_OFFSETS_SH := $(KTF_ROOT)/tools/asm-offsets/asm-offsets.sh

SOURCES := $(shell find . -name \*.c -and -not -name $(ASM_OFFSETS_C))
Expand All @@ -160,6 +158,9 @@ ASM_SOURCES := $(shell find . -name \*.S)
ASM_OFFSETS := $(shell find . -name $(ASM_OFFSETS_C))
LINK_SCRIPT := $(shell find . -name \*.ld)

ASM_OFFSETS_S := $(ASM_OFFSETS:.c=.s)
ASM_OFFSETS_H := $(addprefix include/,$(ASM_OFFSETS:.c=.h))

minipli-oss marked this conversation as resolved.
Show resolved Hide resolved
SYMBOLS_NAME := symbols
SYMBOLS_TOOL := symbols.py
SYMBOLS_DIR := tools/symbols
Expand All @@ -184,19 +185,20 @@ endif
$(PREP_LINK_SCRIPT) : $(LINK_SCRIPT)
$(VERBOSE) $(CC) $(AFLAGS) -E -P -C -x c $< -o $@

$(TARGET): $(OBJS) $(PREP_LINK_SCRIPT)
$(TARGET_DEBUG): $(OBJS) $(PREP_LINK_SCRIPT)
@echo "LD " $@
$(VERBOSE) $(LD) -T $(PREP_LINK_SCRIPT) -o $@ $(OBJS) $(PFMLIB_LINKER_FLAGS)
@echo "GEN " $(SYMBOLS_NAME).S
$(VERBOSE) $(NM) -p --format=posix $(TARGET) | $(PYTHON) $(SYMBOLS_DIR)/$(SYMBOLS_TOOL)
$(VERBOSE) $(NM) -p --format=posix $@ | $(PYTHON) $(SYMBOLS_DIR)/$(SYMBOLS_TOOL)
@echo "CC " $(SYMBOLS_NAME).S
$(VERBOSE) $(CC) -c -o $(SYMBOLS_NAME).o $(AFLAGS) $(SYMBOLS_NAME).S
$(VERBOSE) rm -rf $(SYMBOLS_NAME).S
@echo "LD " $(TARGET) $(SYMBOLS_NAME).o
@echo "LD " $@ $(SYMBOLS_NAME).o
$(VERBOSE) $(LD) -T $(PREP_LINK_SCRIPT) -o $@ $(OBJS) $(PFMLIB_LINKER_FLAGS) $(SYMBOLS_NAME).o

$(TARGET): $(TARGET_DEBUG)
@echo "STRIP"
$(VERBOSE) $(OBJCOPY) --only-keep-debug $(TARGET) $(TARGET_DEBUG)
$(VERBOSE) $(STRIP) $(STRIP_OPTS) $(TARGET)
$(VERBOSE) $(STRIP) $(STRIP_OPTS) -o $@ $<

$(PFMLIB_ARCHIVE): $(PFMLIB_TARBALL)
@echo "UNTAR libpfm"
Expand All @@ -217,10 +219,12 @@ $(PFMLIB_ARCHIVE): $(PFMLIB_TARBALL)
@echo "CC " $@
$(VERBOSE) $(CC) -c -o $@ $(CFLAGS) $<

$(ASM_OFFSETS_H): $(ASM_OFFSETS)
@echo "GEN" include/$(shell dirname $<)/$(ASM_OFFSETS_H)
$(VERBOSE) $(CC) $(CFLAGS) -S -g0 -o $(KTF_ROOT)/$(shell dirname $<)/$(ASM_OFFSETS_S) $<
$(VERBOSE) $(ASM_OFFSETS_SH) $(KTF_ROOT)/$(shell dirname $<)/$(ASM_OFFSETS_S) $(KTF_ROOT)/include/$(shell dirname $<)/$(ASM_OFFSETS_H)
$(ASM_OFFSETS_S): $(ASM_OFFSETS)
$(VERBOSE) $(CC) $(CFLAGS) -S -g0 -o $@ $<

$(ASM_OFFSETS_H): $(ASM_OFFSETS_S)
@echo "GEN" $@
$(VERBOSE) $(ASM_OFFSETS_SH) $< $@

DEPFILES := $(OBJS:.o=.d)
-include $(wildcard $(DEPFILES))
Expand All @@ -236,11 +240,10 @@ clean:
$(VERBOSE) find $(KTF_ROOT) -name \*.xz -delete
$(VERBOSE) find $(KTF_ROOT) -name cscope.\* -delete
$(VERBOSE) find $(KTF_ROOT) -maxdepth 1 \( -name tags -or -name TAGS \) -delete
$(VERBOSE) find $(KTF_ROOT) -name $(ASM_OFFSETS_S) -delete
$(VERBOSE) find $(KTF_ROOT) -name $(ASM_OFFSETS_H) -delete
$(VERBOSE) find $(PFMLIB_DIR) -mindepth 1 ! -name $(PFMLIB_NAME)-$(PFMLIB_VER).tar.gz -delete
$(VERBOSE) $(RM) -f $(ASM_OFFSETS_H) $(ASM_OFFSETS_S)
$(VERBOSE) $(RM) -rf $(ACPICA_DEST_DIR)/source
$(VERBOSE) $(RM) -f $(TARGET_DEBUG)
$(VERBOSE) $(RM) -f $(TARGET_DEBUG) $(TARGET)
$(VERBOSE) $(RM) -rf $(GRUB_DIR)

# Check whether we can use kvm for qemu
Expand Down Expand Up @@ -268,18 +271,18 @@ QEMU_PARAMS += $(QEMU_PARAMS_NOGFX)

QEMU_PARAMS_DEBUG := -s -S &

ISO_FILE := boot.iso
ISO_FILE := ktf.iso

ifneq ($(SYSTEM), LINUX)
$(ISO_FILE): dockerboot.iso
$(ISO_FILE): docker${ISO_FILE}
else
$(ISO_FILE): $(TARGET)
@echo "GEN ISO" $(ISO_FILE)
$(VERBOSE) $(GRUB_FILE) --is-x86-multiboot2 $(TARGET) || { echo "Multiboot not supported"; exit 1; }
$(VERBOSE) $(GRUB_FILE) --is-x86-multiboot2 $< || { echo "Multiboot not supported"; exit 1; }
$(VERBOSE) $(RM) -rf $(GRUB_DIR) && mkdir -p $(GRUB_DIR)/grub
$(VERBOSE) cp $(TARGET) $(GRUB_DIR)/
$(VERBOSE) cp $< $(GRUB_DIR)/
$(VERBOSE) cp $(GRUB_CONFIG) $(GRUB_DIR)/grub/grub.cfg
$(VERBOSE) $(XZ) -q -f $(GRUB_DIR)/$(TARGET)
$(VERBOSE) $(XZ) -q -f $(GRUB_DIR)/$<
$(VERBOSE) $(GRUB_MKRESCUE) --install-modules="$(GRUB_MODULES)" --fonts=no --compress=xz -o $(ISO_FILE) grub &> /dev/null
endif

Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ Some more features are in the making. Check out the issues.
The quick start is to run the following commands. The content of the file tests/test.c
will be executed. Note, the last command will block.

Build a boot.iso from scratch, in the docker container.
Build a ktf.iso from scratch, in the docker container.

```
make clean
make docker:boot.iso
make docker:ktf.iso
```

Boot the resulting image:
Expand Down Expand Up @@ -66,17 +66,17 @@ make docker:all

* Native
```
make boot.iso
make ktf.iso
```

* Docker

```
make docker:boot.iso
make docker:ktf.iso
```

The `make` command generates the `kernel64.bin` multiboot-compatible ELF file, that you can directly boot with QEMU.
The `make boot.iso` command takes the `kernel64.bin`, places it in `grub/boot/` directory hierarchy and generates a `boot.iso`
The `make ktf.iso` command takes the `kernel64.bin`, places it in `grub/boot/` directory hierarchy and generates a `ktf.iso`
out of the `grub/` (using `grub/boot/grub/grub.cfg` as a default GRUB config).

#### Fedora
Expand Down Expand Up @@ -127,7 +127,7 @@ memory=1024

serial= [ 'file:/tmp/kernel.log', 'pty' ]

disk = [ '/home/user/boot.iso,,hdc,cdrom' ]
disk = [ '/home/user/ktf.iso,,hdc,cdrom' ]

on_reboot = "destroy"

Expand Down Expand Up @@ -223,4 +223,3 @@ and we're actively sharing ideas, bugs and anything related to KTF there. Feel f
![GitHub](https://img.shields.io/github/license/awslabs/ktf)

This project is licensed under the BSD 2-Clause License.

4 changes: 2 additions & 2 deletions tools/ci/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# This script builds the project's boot.iso file in the docker environment
# This script builds the project's ktf.iso file in the docker environment
set -e

COMPILER=$1
Expand All @@ -16,4 +16,4 @@ cd "$SCRIPTDIR"/../..

# Build project in docker
make clean V=1
make docker:boot.iso V=1 CC=$COMPILER
make docker:ktf.iso V=1 CC=$COMPILER
4 changes: 2 additions & 2 deletions tools/ci/launch-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# This script builds the project's boot.iso file in the docker environment and
# This script builds the project's ktf.iso file in the docker environment and
# next launches a test and checks for a successful timeout.
set -e

Expand All @@ -18,7 +18,7 @@ cd "$SCRIPTDIR"/../..
# Build project in docker
echo "Building project from scratch"
make clean V=1
make UNITTEST=1 docker:boot.iso V=1 CC=$COMPILER
make UNITTEST=1 docker:ktf.iso V=1 CC=$COMPILER

# Use QEMU to launch the guest
echo "Launching KTF"
Expand Down
2 changes: 1 addition & 1 deletion tools/xen_config/config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ memory=1024

serial= [ 'file:/tmp/kernel.log', 'pty' ]

disk = [ '/home/user/boot.iso,,hdc,cdrom' ]
disk = [ '/home/user/ktf.iso,,hdc,cdrom' ]

on_reboot = "destroy"

Expand Down
Loading