Skip to content

Commit

Permalink
Update build procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
semlanik authored and Alexey Edelev committed Nov 27, 2014
1 parent d532927 commit a2c1022
Show file tree
Hide file tree
Showing 57 changed files with 507 additions and 108 deletions.
10 changes: 0 additions & 10 deletions .gitignore

This file was deleted.

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 <amery@geeks.cl>
# Copyright (C) 2012,2013 Henrik Nordstrom <henrik@henriknordstrom.net>
# Copyright (C) 2013 Patrick Wood <patrickhwood@gmail.com>
# Copyright (C) 2013 Pat Wood <Pat.Wood@efi.com>
# Copyright (C) 2012 Alejandro Mery <amery@geeks.cl>
# Copyright (C) 2012,2013 Henrik Nordstrom <henrik@henriknordstrom.net>
# Copyright (C) 2013 Patrick Wood <patrickhwood@gmail.com>
# Copyright (C) 2013 Pat Wood <Pat.Wood@efi.com>
# Copyright (C) 2014 Alexey Edelev <semlanik@gmail.com>
#
# 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): FORCE
$(MAKE) -C tools/$@
tools:$(TOOLS)

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

clean:
@rm -vf $(TOOLS) $(MISC_TOOLS) *.o *.elf *.sunxi *.bin *.nm *.orig
$(CROSS_TOOLS):FORCE
$(MAKE) -C tools/$@
cross-tools:$(CROSS_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 <semlanik@gmail.com>
#
# 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 <semlanik@gmail.com>
#
# 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 <semlanik@gmail.com>
#
# 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_MATCHID=0x1094
sun4i_MATCHID=0x1008
sun5i_MATCHID=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,,$@))_MATCHID)
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 <semlanik@gmail.com>
#
# 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 <semlanik@gmail.com>
#
# 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 <semlanik@gmail.com>
#
# 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.
26 changes: 26 additions & 0 deletions baremetal/jtag-loop/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (C) 2014 Alexey Edelev <semlanik@gmail.com>
#
# 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 = jtag-loop.elf
TARGETS = jtag-loop.bin
EXTRA_DEPS = jtag-loop.sunxi

SOURCES = jtag-loop.c
LDSCRIPT = jtag-loop.lds
include ../baremetal.rules
jtag-loop.sunxi: jtag-loop.bin
-if $$(which mksunxiboot); then mksunxiboot $^ $@; fi
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a2c1022

Please sign in to comment.