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

Reorganize folder structure, improve build procedure #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 17 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
fexc
bin2fex
fex2bin
bootinfo
fel
pio
nand-part
meminfo
*.o
*.elf
*.swp
tools/bootinfo/bootinfo
tools/fel/fel
tools/fexc/bin2fex
tools/fexc/fecx
tools/fexc/fex2bin
tools/nand_part/nand-part
tools/phoenix_info/phoenix_info
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these dropped? Won't binaries / .o start showing on git status now?

tools/pio/pio
baremetal/boot_head/boot_head_sun3i.bin
baremetal/boot_head/boot_head_sun4i.bin
baremetal/boot_head/boot_head_sun5i.bin
baremetal/fel-copy/fel-copy.bin
baremetal/fel-pio/fel-pio.bin
baremetal/fel-pio/fel-pio.nm
baremetal/fel-sdboot/fel-sdboot.bin
baremetal/jtag-loop/jtag-loop.bin
139 changes: 44 additions & 95 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright (C) 2012 Alejandro Mery <[email protected]>
# Copyright (C) 2012,2013 Henrik Nordstrom <[email protected]>
# Copyright (C) 2013 Patrick Wood <[email protected]>
# Copyright (C) 2013 Pat Wood <[email protected]>
# Copyright (C) 2012 Alejandro Mery <[email protected]>
# Copyright (C) 2012,2013 Henrik Nordstrom <[email protected]>
# Copyright (C) 2013 Patrick Wood <[email protected]>
# Copyright (C) 2013 Pat Wood <[email protected]>
# Copyright (C) 2014 Alexey Edelev <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -10,111 +11,59 @@
#
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.

CC = gcc
CFLAGS = -g -O0 -Wall -Wextra
CFLAGS += -std=c99 -D_POSIX_C_SOURCE=200112L
CFLAGS += -Iinclude/
PWD=$(shell pwd)
.PHONY:tools baremetal

TOOLS = fexc bin2fex fex2bin bootinfo fel pio
TOOLS += nand-part
TOOLS = \
bootinfo \
fel \
nand_part \
fexc \
phoenix_info \
pio

MISC_TOOLS = phoenix_info
CROSS_TOOLS = \
meminfo

CROSS_COMPILE ?= arm-none-eabi-
BAREMETAL = \
boot_head \
fel-sdboot \
jtag-loop \
fel-pio \
fel-copy

.PHONY: all clean

all: $(TOOLS)
tools:$(TOOLS)
$(TOOLS): FORCE
$(MAKE) -C tools/$@

misc: $(MISC_TOOLS)
baremetal:$(BAREMETAL)
$(BAREMETAL): FORCE
$(MAKE) -C baremetal/$@

clean:
@rm -vf $(TOOLS) $(MISC_TOOLS) *.o *.elf *.sunxi *.bin *.nm *.orig
cross-tools:$(CROSS_TOOLS)
$(CROSS_TOOLS):FORCE
$(MAKE) -C tools/$@

tools-clean:
for d in $(TOOLS); do $(MAKE) -C tools/$$d clean; done

$(TOOLS): Makefile common.h
baremetal-clean:
for d in $(BAREMETAL); do $(MAKE) -C baremetal/$$d clean; done

fex2bin bin2fex: fexc
ln -s $< $@
cross-tools-clean:
for d in $(CROSS_TOOLS); do $(MAKE) -C tools/$$d clean; done

fexc: fexc.h script.h script.c \
script_uboot.h script_uboot.c \
script_bin.h script_bin.c \
script_fex.h script_fex.c
tools-install:
for d in $(TOOLS); do $(MAKE) -C tools/$$d install; done

LIBUSB = libusb-1.0
LIBUSB_CFLAGS = `pkg-config --cflags $(LIBUSB)`
LIBUSB_LIBS = `pkg-config --libs $(LIBUSB)`
tools-uninstall:
for d in $(TOOLS); do $(MAKE) -C tools/$$d uninstall; done

fel: fel.c
$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS) $(LIBUSB_LIBS)

nand-part: nand-part-main.c nand-part.c nand-part-a10.h nand-part-a20.h
$(CC) $(CFLAGS) -c -o nand-part-main.o nand-part-main.c
$(CC) $(CFLAGS) -c -o nand-part-a10.o nand-part.c -D A10
$(CC) $(CFLAGS) -c -o nand-part-a20.o nand-part.c -D A20
$(CC) $(LDFLAGS) -o $@ nand-part-main.o nand-part-a10.o nand-part-a20.o $(LIBS)

%: %.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS)

fel-pio.bin: fel-pio.elf fel-pio.nm
$(CROSS_COMPILE)objcopy -O binary fel-pio.elf fel-pio.bin

fel-pio.elf: fel-pio.c fel-pio.lds
$(CROSS_COMPILE)gcc -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder fel-pio.c -nostdlib -o fel-pio.elf -T fel-pio.lds

fel-pio.nm: fel-pio.elf
$(CROSS_COMPILE)nm fel-pio.elf | grep -v " _" >fel-pio.nm

jtag-loop.elf: jtag-loop.c jtag-loop.lds
$(CROSS_COMPILE)gcc -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder jtag-loop.c -nostdlib -o jtag-loop.elf -T jtag-loop.lds -Wl,-N

jtag-loop.bin: jtag-loop.elf
$(CROSS_COMPILE)objcopy -O binary jtag-loop.elf jtag-loop.bin

jtag-loop.sunxi: jtag-loop.bin
mksunxiboot jtag-loop.bin jtag-loop.sunxi

fel-sdboot.elf: fel-sdboot.c fel-sdboot.lds
$(CROSS_COMPILE)gcc -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder fel-sdboot.c -nostdlib -o fel-sdboot.elf -T fel-sdboot.lds -Wl,-N

fel-sdboot.bin: fel-sdboot.elf
$(CROSS_COMPILE)objcopy -O binary fel-sdboot.elf fel-sdboot.bin

fel-sdboot.sunxi: fel-sdboot.bin
mksunxiboot fel-sdboot.bin fel-sdboot.sunxi

boot_head_sun3i.elf: boot_head_sun3i.S boot_head_sun3i.lds
$(CROSS_COMPILE)gcc -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder boot_head.S -nostdlib -o boot_head_sun3i.elf -T boot_head.lds -Wl,-N -DMACHID=0x1094

boot_head_sun3i.bin: boot_head_sun3i.elf
$(CROSS_COMPILE)objcopy -O binary boot_head_sun3i.elf boot_head_sun3i.bin

boot_head_sun4i.elf: boot_head.S boot_head.lds
$(CROSS_COMPILE)gcc -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder boot_head.S -nostdlib -o boot_head_sun4i.elf -T boot_head.lds -Wl,-N -DMACHID=0x1008

boot_head_sun4i.bin: boot_head_sun4i.elf
$(CROSS_COMPILE)objcopy -O binary boot_head_sun4i.elf boot_head_sun4i.bin

boot_head_sun5i.elf: boot_head.S boot_head.lds
$(CROSS_COMPILE)gcc -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder boot_head.S -nostdlib -o boot_head_sun5i.elf -T boot_head.lds -Wl,-N -DMACHID=0x102A

boot_head_sun5i.bin: boot_head_sun5i.elf
$(CROSS_COMPILE)objcopy -O binary boot_head_sun5i.elf boot_head_sun5i.bin

bootinfo: bootinfo.c

meminfo: meminfo.c
$(CROSS_COMPILE)gcc -g -O0 -Wall -static -o $@ $^

.gitignore: Makefile
@for x in $(TOOLS) '*.o' '*.swp'; do \
echo "$$x"; \
done > $@
FORCE:
12 changes: 9 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ phoenix_info:

meminfo:
Tool for reading DRAM settings from registers. Compiled as a
static binary for use on android and other OSes. To build this,
get a toolchain, and run:
make CROSS_COMPILE=arm-linux-gnueabihf- meminfo
static binary for use on android and other OSes.

Build instructions:
To build host sunxi-tools:
make tools [CC=<compiler> CFLAGS=<cflags>]
To build target sunxi-tools:
make cross-tools CROSS_COMPILE=<arm compiler> [CC=<compiler> CFLAGS=<cflags>]
To build sunxi core processor tools:
make baremetal CROSS_COMPILE=<arm compiler> [CC=<compiler> CFLAGS=<cflags> OBJCOPY=<object copy tool> NM=<name mapper tool>]

This software is licensed under the terms of GPLv2+ as defined by the
Free Software Foundation, details can be read in the COPYING file.
23 changes: 23 additions & 0 deletions baremetal/baremetal.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (C) 2014 Alexey Edelev <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

CC ?= gcc
OBJCOPY ?= objcopy
NM ?= nm
CROSS_COMPILE ?= arm-none-gnueabi-
override CFLAGS := $(CFLAGS) -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder -nostdlib
override CC := $(CROSS_COMPILE)$(CC)
override OBJCOPY := $(CROSS_COMPILE)$(OBJCOPY)
override NM := $(CROSS_COMPILE)$(NM)
28 changes: 28 additions & 0 deletions baremetal/baremetal.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2014 Alexey Edelev <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

.DEFAULT: all

all: $(TARGETS) $(EXTRA_DEPS)

$(ELFS): $(SOURCES) $(LDSCRIPT)
$(CC) $(CFLAGS) $(SOURCES) -o $@ -T $(LDSCRIPT) -Wl,-N $(DEFINES)

$(TARGETS): $(ELFS)
$(OBJCOPY) -O binary $(subst .bin,.elf,$@) $@

clean:
rm -f $(ELFS)
rm -f $(TARGETS)
32 changes: 32 additions & 0 deletions baremetal/boot_head/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2014 Alexey Edelev <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

include ../baremetal.env

sun3i_MACHID=0x1094
sun4i_MACHID=0x1008
sun5i_MACHID=0x102A

BOOT_HEADS = boot_head_sun3i \
boot_head_sun4i \
boot_head_sun5i

ELFS = $(addsuffix .elf, $(BOOT_HEADS))
TARGETS = $(addsuffix .bin, $(BOOT_HEADS))

SOURCES = boot_head.S
LDSCRIPT = boot_head.lds
DEFINES=-DMACHID=$($(subst boot_head_,,$(subst .elf,,$@))_MACHID)
include ../baremetal.rules
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions baremetal/fel-copy/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (C) 2014 Alexey Edelev <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

include ../baremetal.env

.DEFAULT: all

all: fel-copy.bin

fel-copy.bin: fel-copy.o
$(OBJCOPY) -O binary fel-copy.o fel-copy.bin

fel-copy.o:
$(CC) $(CFLAGS) -c fel-copy.c -o fel-copy.o

clean:
rm -f fel-copy.bin fel-copy.o
File renamed without changes.
27 changes: 27 additions & 0 deletions baremetal/fel-pio/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (C) 2014 Alexey Edelev <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

include ../baremetal.env

ELFS = fel-pio.elf
TARGETS = fel-pio.bin
EXTRA_DEPS = fel-pio.nm

SOURCES = fel-pio.c
LDSCRIPT = fel-pio.lds

include ../baremetal.rules
fel-pio.nm: fel-pio.elf
$(NM) $^ | grep -v " _" >$@
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions baremetal/fel-sdboot/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (C) 2014 Alexey Edelev <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

include ../baremetal.env

ELFS = fel-sdboot.elf
TARGETS = fel-sdboot.bin

SOURCES = fel-sdboot.c
LDSCRIPT = fel-sdboot.lds
EXTRA_DEPS = fel-sdboot.sunxi
include ../baremetal.rules

fel-sdboot.sunxi: fel-sdboot.bin
-if $$(which mksunxiboot); then mksunxiboot $^ $@; fi
File renamed without changes.
File renamed without changes.
Loading