Import of the watch repository from Pebble

This commit is contained in:
Matthieu Jeanson 2024-12-12 16:43:03 -08:00 committed by Katharine Berry
commit 3b92768480
10334 changed files with 2564465 additions and 0 deletions

View file

@ -0,0 +1,137 @@
# Copyright 2024 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
#
# http://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 binascii
from waflib import Task, TaskGen, Utils, Node, Errors
class binary_header(Task.Task):
"""
Create a header file containing an array with contents from a binary file.
"""
def run(self):
if getattr(self.generator, 'hex', False):
# Input file is hexadecimal ASCII characters with whitespace
text = self.inputs[0].read(
encoding=getattr(self.generator, 'encoding', 'ISO8859-1'))
# Strip all whitespace so that binascii is happy
text = ''.join(text.split())
code = binascii.unhexlify(text)
else:
code = self.inputs[0].read('rb')
array_name = getattr(self.generator, 'array_name', None)
if not array_name:
array_name = re.sub(r'[^A-Za-z0-9]', '_', self.inputs[0].name)
output = ['#pragma once', '#include <stdint.h>']
output += ['static const uint8_t %s[] = {' % array_name]
line = []
for n, b in enumerate(code):
line += ['0x%.2x,' % ord(b)]
if n % 16 == 15:
output += [''.join(line)]
line = []
if line:
output += [''.join(line)]
output += ['};', '']
self.outputs[0].write(
'\n'.join(output),
encoding=getattr(self.generator, 'encoding', 'ISO8859-1'))
self.generator.bld.raw_deps[self.uid()] = self.dep_vars = 'array_name'
if getattr(self.generator, 'chmod', None):
os.chmod(self.outputs[0].abspath(), self.generator.chmod)
@TaskGen.feature('binary_header')
@TaskGen.before_method('process_source', 'process_rule')
def process_binary_header(self):
"""
Define a transformation that substitutes the contents of *source* files to
*target* files::
def build(bld):
bld(
features='binary_header',
source='foo.bin',
target='foo.auto.h',
array_name='s_some_array'
)
bld(
features='binary_header',
source='bar.hex',
target='bar.auto.h',
hex=True
)
If the *hex* parameter is True, the *source* files are read in an ASCII
hexadecimal format, where each byte is represented by a pair of hexadecimal
digits with optional whitespace. If *hex* is False or not specified, the
file is treated as a raw binary file.
The name of the array variable defaults to the source file name with all
characters that are invaid C identifiers replaced with underscores. The name
can be explicitly specified by setting the *array_name* parameter.
This method overrides the processing by
:py:meth:`waflib.TaskGen.process_source`.
"""
src = Utils.to_list(getattr(self, 'source', []))
if isinstance(src, Node.Node):
src = [src]
tgt = Utils.to_list(getattr(self, 'target', []))
if isinstance(tgt, Node.Node):
tgt = [tgt]
if len(src) != len(tgt):
raise Errors.WafError('invalid number of source/target for %r' % self)
for x, y in zip(src, tgt):
if not x or not y:
raise Errors.WafError('null source or target for %r' % self)
a, b = None, None
if isinstance(x, str) and isinstance(y, str) and x == y:
a = self.path.find_node(x)
b = self.path.get_bld().make_node(y)
if not os.path.isfile(b.abspath()):
b.sig = None
b.parent.mkdir()
else:
if isinstance(x, str):
a = self.path.find_resource(x)
elif isinstance(x, Node.Node):
a = x
if isinstance(y, str):
b = self.path.find_or_declare(y)
elif isinstance(y, Node.Node):
b = y
if not a:
raise Errors.WafError('could not find %r for %r' % (x, self))
has_constraints = False
tsk = self.create_task('binary_header', a, b)
for k in ('after', 'before', 'ext_in', 'ext_out'):
val = getattr(self, k, None)
if val:
has_constraints = True
setattr(tsk, k, val)
tsk.before = [k for k in ('c', 'cxx') if k in Task.classes]
self.source = []

View file

@ -0,0 +1,26 @@
# Copyright 2024 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
#
# http://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.
"""
Define a __FILE_NAME__ macro to expand to the filename of the C/C++ source,
stripping the other path components.
"""
from waflib.TaskGen import feature, after_method
@feature('c')
@after_method('create_compiled_task')
def file_name_c_define(self):
for task in self.tasks:
task.env.append_value(
'DEFINES', '__FILE_NAME__="%s"' % task.inputs[0].name)

View file

@ -0,0 +1,45 @@
# Copyright 2024 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
#
# http://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 re
import waflib.Context
import waflib.Logs
def get_git_revision(ctx):
try:
tag = ctx.cmd_and_log(['git', 'describe'], quiet=waflib.Context.BOTH).strip()
commit = ctx.cmd_and_log(['git', 'rev-parse', '--short', 'HEAD'], quiet=waflib.Context.BOTH).strip()
timestamp = ctx.cmd_and_log(['git', 'log', '-1', '--format=%ct', 'HEAD'], quiet=waflib.Context.BOTH).strip()
except Exception:
waflib.Logs.warn('get_git_version: unable to determine git revision')
tag, commit, timestamp = ("?", "?", "1")
# Validate that git tag follows the required form:
# See https://github.com/pebble/tintin/wiki/Firmware,-PRF-&-Bootloader-Versions
# Note: version_regex.groups() returns sequence ('0', '0', '0', 'suffix'):
version_regex = re.search("^v(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:(?:-)(.+))?$", tag)
if version_regex:
# Get version numbers from version_regex.groups() sequence and replace None values with 0
# e.g. v2-beta11 => ('2', None, None, 'beta11') => ('2', '0', '0')
version = [x if x else '0' for x in version_regex.groups()[:3]]
else:
waflib.Logs.warn('get_git_revision: Invalid git tag! '
'Must follow this form: `v0[.0[.0]][-suffix]`')
version = ['0', '0', '0', 'unknown']
return {'TAG': tag,
'COMMIT': commit,
'TIMESTAMP': timestamp,
'MAJOR_VERSION': version[0],
'MINOR_VERSION': version[1],
'PATCH_VERSION': version[2]}

View file

@ -0,0 +1,28 @@
# Copyright 2024 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
#
# http://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.
from waflib import Utils, Errors
from waflib.TaskGen import after, feature
@after('apply_link')
@feature('cprogram', 'cshlib')
def process_ldscript(self):
if not getattr(self, 'ldscript', None) or self.env.CC_NAME != 'gcc':
return
node = self.path.find_resource(self.ldscript)
if not node:
raise Errors.WafError('could not find %r' % self.ldscript)
self.link_task.env.append_value('LINKFLAGS', '-T%s' % node.abspath())
self.link_task.dep_nodes.append(node)

View file

@ -0,0 +1,67 @@
#!/usr/bin/python
# Copyright 2024 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
#
# http://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.
# Grygoriy Fuchedzhy 2010
"""
Support for converting linked targets to ihex, srec or binary files using
objcopy. Use the 'objcopy' feature in conjuction with the 'cc' or 'cxx'
feature. The 'objcopy' feature uses the following attributes:
objcopy_bfdname Target object format name (eg. ihex, srec, binary).
Defaults to ihex.
objcopy_target File name used for objcopy output. This defaults to the
target name with objcopy_bfdname as extension.
objcopy_install_path Install path for objcopy_target file. Defaults to ${PREFIX}/fw.
objcopy_flags Additional flags passed to objcopy.
"""
from waflib.Utils import def_attrs
from waflib import Task
from waflib.TaskGen import feature, after_method
class objcopy(Task.Task):
run_str = '${OBJCOPY} -O ${TARGET_BFDNAME} ${OBJCOPYFLAGS} ${SRC} ${TGT}'
color = 'CYAN'
@feature('objcopy')
@after_method('apply_link')
def objcopy(self):
def_attrs(self,
objcopy_bfdname = 'ihex',
objcopy_target = None,
objcopy_install_path = "${PREFIX}/firmware",
objcopy_flags = '')
link_output = self.link_task.outputs[0]
if not self.objcopy_target:
self.objcopy_target = link_output.change_ext('.' + self.objcopy_bfdname).name
task = self.create_task('objcopy',
src=link_output,
tgt=self.path.find_or_declare(self.objcopy_target))
task.env.append_unique('TARGET_BFDNAME', self.objcopy_bfdname)
try:
task.env.append_unique('OBJCOPYFLAGS', getattr(self, 'objcopy_flags'))
except AttributeError:
pass
if self.objcopy_install_path:
self.bld.install_files(self.objcopy_install_path,
task.outputs[0],
env=task.env.derive())
def configure(ctx):
objcopy = ctx.find_program('objcopy', var='OBJCOPY', mandatory=True)