Add license and license header.

Apache 2.0! There's a dumb script to help with adding headers and
catching files that are missing headers.

Change-Id: Ic4db85b617aa82e5e201ae4bd2e5aff6a029b1b3
diff --git a/build/BUILD.gn b/build/BUILD.gn
index 52793dd..ecc413d 100644
--- a/build/BUILD.gn
+++ b/build/BUILD.gn
@@ -1,3 +1,17 @@
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 import("//build/arch/common.gni")
 import("//build/arch/aarch64.gni")  # TODO: remove when no dependency on arch_aarch64_pl011_base_address
 
diff --git a/build/arch/aarch64.gni b/build/arch/aarch64.gni
index 54775e3..f9df8f2 100644
--- a/build/arch/aarch64.gni
+++ b/build/arch/aarch64.gni
@@ -1,3 +1,17 @@
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 declare_args() {
   # Whether to include the PrimeCell UART (PL011) driver.
   arch_aarch64_use_pl011 = false
diff --git a/build/arch/common.gni b/build/arch/common.gni
index e4d3378..ca2e285 100644
--- a/build/arch/common.gni
+++ b/build/arch/common.gni
@@ -1,3 +1,17 @@
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 declare_args() {
   # The specific CPU that runs the architecture.
   arch_cpu = ""
diff --git a/build/image/convert_to_binary.py b/build/image/convert_to_binary.py
index 2935ec8..aa6e79f 100644
--- a/build/image/convert_to_binary.py
+++ b/build/image/convert_to_binary.py
@@ -1,4 +1,20 @@
 #!/usr/bin/env python
+#
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#!/usr/bin/env python
 """Convert a file to binary format.
 
 Calls objcopy to convert a file into raw binary format.
diff --git a/build/image/extract_offsets.py b/build/image/extract_offsets.py
index c52d01b..e0a2b4a 100644
--- a/build/image/extract_offsets.py
+++ b/build/image/extract_offsets.py
@@ -1,4 +1,19 @@
 #!/usr/bin/env python
+#
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 """Extract embedded offsets from an object file.
 
 We let the compiler calculate the offsets it is going to use and have those
diff --git a/build/image/generate_initrd.py b/build/image/generate_initrd.py
index 28e1680..5e89e63 100644
--- a/build/image/generate_initrd.py
+++ b/build/image/generate_initrd.py
@@ -1,4 +1,19 @@
 #!/usr/bin/env python
+#
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 """Generate an initial RAM disk for the hypervisor.
 
 Packages the VMs, initrds for the VMs and the list of secondary VMs (vms.txt)
diff --git a/build/image/generate_offsets.gni b/build/image/generate_offsets.gni
index 74f3c1b..cce64bd 100644
--- a/build/image/generate_offsets.gni
+++ b/build/image/generate_offsets.gni
@@ -1,3 +1,17 @@
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 # Calculates offsets of fields in C structures for use in assembly.
 template("generate_offsets") {
   # There are 3 targets involved:
diff --git a/build/image/image.gni b/build/image/image.gni
index 464bd30..b1b1895 100644
--- a/build/image/image.gni
+++ b/build/image/image.gni
@@ -1,3 +1,17 @@
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 import("//build/arch/common.gni")
 
 # Build image, link to an ELF file then convert to plain binary.
diff --git a/build/license.py b/build/license.py
new file mode 100644
index 0000000..bce6f34
--- /dev/null
+++ b/build/license.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+#
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Add license header to source files.
+
+If the file doesn't have the license header, add it with the appropriate comment
+style.
+"""
+
+import argparse
+import sys
+
+
+apache2 = """{comment} Copyright 2018 Google LLC
+{comment}
+{comment} Licensed under the Apache License, Version 2.0 (the "License");
+{comment} you may not use this file except in compliance with the License.
+{comment} You may obtain a copy of the License at
+{comment}
+{comment}     https://www.apache.org/licenses/LICENSE-2.0
+{comment}
+{comment} Unless required by applicable law or agreed to in writing, software
+{comment} distributed under the License is distributed on an "AS IS" BASIS,
+{comment} WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+{comment} See the License for the specific language governing permissions and
+{comment} limitations under the License."""
+
+def Main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument("file")
+    parser.add_argument("--style", choices=["c", "hash"], required=True)
+    args = parser.parse_args()
+    header = "/*\n" if args.style == "c" else ""
+    header += apache2.format(comment=" *" if args.style == "c" else "#")
+    header += "\n */" if args.style == "c" else ""
+    header += "\n\n"
+    with open(args.file, "r") as f:
+        contents = f.read()
+        if header in contents:
+            return
+    with open(args.file, "w") as f:
+        f.write(header)
+        f.write(contents)
+
+if __name__ == "__main__":
+    sys.exit(Main())
diff --git a/build/toolchain/arch/BUILD.gn b/build/toolchain/arch/BUILD.gn
index 8bfb538..6ce6207 100644
--- a/build/toolchain/arch/BUILD.gn
+++ b/build/toolchain/arch/BUILD.gn
@@ -1,3 +1,17 @@
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 # Target toolchain specific build arguments.
 declare_args() {
   # Build with a specific compiler version e.g. when building with clang, set
diff --git a/build/toolchain/host/BUILD.gn b/build/toolchain/host/BUILD.gn
index 7382097..ed1e510 100644
--- a/build/toolchain/host/BUILD.gn
+++ b/build/toolchain/host/BUILD.gn
@@ -1,3 +1,17 @@
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 # Host toolchain specific build arguments.
 declare_args() {
   # Build with a specific compiler version e.g. when building with clang, set