1--------------------------------------------------------------------------
2-- Copyright (c) 2016, ETH Zurich.
3-- All rights reserved.
4--
5-- This file is distributed under the terms in the attached LICENSE file.
6-- If you do not find this file, copies can be found by writing to:
7-- ETH Zurich D-INFK, CAB F.78, Universitaetstr. 6, CH-8092 Zurich.
8-- Attn: Systems Group.
9--
10-- Hakefile for Pandaboard USB boot utility
11--
12--------------------------------------------------------------------------
13
14let arch = "armv7"
15    opts = options arch
16
17    aboot_cfiles = [
18        "arch/omap4/serial.c",
19        "arch/omap4/clock.c",
20        "arch/omap4/sdram.c",
21        "arch/omap4/gpmc.c",
22        "arch/omap4/gpio.c",
23        "arch/omap4/id.c",
24        "arch/omap4/rom_usb.c",
25        "libc/printf.c",
26        "libc/strlen.c",
27        "libc/memset.c",
28        "libc/memcpy.c",
29        "libc/raise.c",
30        "aboot.c",
31        "board_panda.c",
32        "misc.c"
33        ]
34
35    aboot_sfiles = [
36        "arch/omap4/start.S",
37        "trusted.S"
38        ]
39
40    aboot_objs = [ objectFilePath opts f | f <- aboot_cfiles ++ aboot_sfiles ]
41
42    aboot_base = "0x40309000"
43
44    compileFileForTarget src =
45        Rule [
46            Str Config.arm_cc,
47            Str "-g", Str "-Os", Str "-Wall", Str "-Werror",
48            Str "-march=armv7-a", Str "-mcpu=cortex-a9",
49            Str "-fno-builtin", Str "-ffreestanding",
50            Str "-I", NoDep SrcTree "src" "include",
51            Str "-include config_panda.h",
52            Str "-Wa,-march=armv7-a+sec",
53            Str "-c", In SrcTree "src" src,
54            Str "-o", Out "armv7" (objectFilePath opts src)
55        ]
56
57    compileForTarget files = Rules [ compileFileForTarget f | f <- files ]
58in [
59    compileNativeC "mkheader" ["mkheader.c"] [] [] [],
60    compileNativeC "bin2c"    ["bin2c.c"]    [] [] [],
61
62    compileForTarget aboot_cfiles,
63    compileForTarget aboot_sfiles,
64
65    Rule ([ Str Config.arm_cc,
66            Str "-static",
67            NStr "-T", In SrcTree "src" "aboot.lds",
68            Str ("-Wl,-Ttext="++aboot_base),
69            Str "-Wl,--build-id=none",
70            Str "-fno-builtin", Str "-nostdlib"
71          ]
72          ++
73          [ In BuildTree arch o | o <- aboot_objs ] ++
74          [ Str "-lgcc", Str "-o", Out arch "aboot" ]),
75
76    Rule ([ Str Config.arm_objcopy,
77            Str "--gap-fill=0xee", Str "-O binary",
78            In BuildTree arch "aboot",
79            Out arch "aboot.bin" ]),
80    Rule ([ In BuildTree "tools" "/bin/mkheader",
81            Str aboot_base, 
82            Str "`wc -c", In BuildTree arch "aboot.bin", Str "`",
83            Str ">", Out arch "aboot.hdr" ]),
84    Rule ([ Str "cat",
85            In BuildTree arch "aboot.hdr",
86            In BuildTree arch "aboot.bin",
87            Str ">", Out arch "aboot.ift" ]),
88    Rule ([ In BuildTree "tools" "/bin/bin2c", Str "aboot",
89            Str "<", In BuildTree arch "aboot.bin",
90            Str ">", Out arch "2ndstage.c" ]),
91    Rule ([ Str nativeCCompiler,
92            Str "-c", In BuildTree arch "2ndstage.c",
93            Str "-o", Out arch "2ndstage.o" ]),
94
95    Rule ([ Str nativeCCompiler,
96            Str "-g", Str "-O2", Str "-Wall", Str "-Werror",
97            Str "-o", Out "tools" "/bin/usbboot",
98            Str "-I/usr/include/libusb-1.0",
99            Str "-I/usr/include/freebsd",
100            Str "-I", NoDep SrcTree "src" "include",
101            Str "-I", NoDep BuildTree "root" "/",
102            In SrcTree "src" "usbboot.c",
103            In BuildTree arch "2ndstage.o",
104            Str "-lusb-1.0", Str "-lelf-freebsd", Str "-lrt",
105            Dep BuildTree arch $ mackerelDevHdrPath "omap/omap44xx_boot"
106          ])
107]
108