diff --git a/.github/workflows/yaml.yml b/.github/workflows/yaml.yml new file mode 100644 index 0000000..df0e82c --- /dev/null +++ b/.github/workflows/yaml.yml @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2021 Canonical Ltd. +# Copyright (c) 2023 Linaro Ltd +# Author: Krzysztof Kozlowski +# +# +# Loosely based on: https://github.com/linux-test-project/ltp +# https://github.com/linux-nfc/neard +# +name: "Yaml" +on: + pull_request: + push: + workflow_dispatch: + +jobs: + job: + name: Yaml + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + + container: + image: ubuntu:jammy + + steps: + - name: Git checkout + uses: actions/checkout@v3 + + - name: Install additional packages + run: | + export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true + apt update + apt install -y --no-install-recommends yamllint python3-jsonschema python3-ruamel.yaml + + - name: Lint samples + run: for file in config-samples/*; do yamllint $file; done + + - name: Check samples + run: for file in config-samples/*; do python3 ./validate.py -s schema.yaml $file; done diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..4abe9f0 --- /dev/null +++ b/.yamllint @@ -0,0 +1,39 @@ +extends: relaxed + +rules: + line-length: + # 80 chars should be enough, but don't fail if a line is longer + max: 110 + allow-non-breakable-words: true + level: warning + braces: + min-spaces-inside: 0 + max-spaces-inside: 1 + min-spaces-inside-empty: 0 + max-spaces-inside-empty: 0 + brackets: + min-spaces-inside: 0 + max-spaces-inside: 1 + min-spaces-inside-empty: 0 + max-spaces-inside-empty: 0 + colons: {max-spaces-before: 0, max-spaces-after: 1} + commas: {min-spaces-after: 1, max-spaces-after: 1} + comments: + require-starting-space: true + min-spaces-from-content: 1 + comments-indentation: disable + document-start: + present: true + empty-lines: + max: 3 + max-end: 1 + empty-values: + forbid-in-block-mappings: true + forbid-in-flow-mappings: true + hyphens: + max-spaces-after: 1 + indentation: + spaces: 2 + indent-sequences: true + check-multi-line-strings: false + trailing-spaces: false diff --git a/config-samples/sample1.yaml b/config-samples/sample1.yaml new file mode 100644 index 0000000..c7151b4 --- /dev/null +++ b/config-samples/sample1.yaml @@ -0,0 +1,13 @@ +--- +devices: + - board: myboard + name: "My Board" + description: | + My Awesome board + console: /dev/ttyABC0 + fastboot: cacafada + fastboot_set_active: a + fastboot_key_timeout: 2 + usb_always_on: false + cdba: /dev/serial/by-id/usb-CDBA-if00 + voltage: 1800 diff --git a/config-samples/sample10.yaml b/config-samples/sample10.yaml new file mode 100644 index 0000000..23cd168 --- /dev/null +++ b/config-samples/sample10.yaml @@ -0,0 +1,65 @@ +--- +devices: + - board: myboard + name: "My Board" + description: | + My Awesome board + console: /dev/ttyABC0 + fastboot: cacafada + ftdi_gpio: "s:0x0403:0x6011:FT7YWRL8;D;POWER,1,ACTIVE_LOW;FASTBOOT_KEY,0,ACTIVE_HIGH;POWER_KEY,3,ACTIVE_HIGH;USB_DISCONNECT,7,ACTIVE_LOW" + - board: myboard-2 + name: "My Board 2" + description: | + My Awesome board Number 2 + console: /dev/ttyABC1 + fastboot: cacafada + ftdi_gpio: "s:0x0403:0x6011:FT7YWRL8;D;POWER_KEY,3,ACTIVE_HIGH;POWER,1,ACTIVE_LOW;FASTBOOT_KEY,0,ACTIVE_HIGH" + - board: myboard-3 + name: "My Board 2" + description: | + My Awesome board Number 3 + console: /dev/ttyABC2 + fastboot: cacafada + ftdi_gpio: "s:0x0403:0x6011:FT7YWRL8;D;FASTBOOT_KEY,0,ACTIVE_HIGH;POWER,1,ACTIVE_LOW" + - board: myboard-4 + name: "My Board 2" + description: | + My Awesome board Number 4 + console: /dev/ttyABC3 + fastboot: cacafada + ftdi_gpio: "s:0x0403:0x6011:FT7YWRL8;D;POWER,1,ACTIVE_LOW" + - board: myboard-5 + name: "My Board 2" + description: | + My Awesome board Number 5 + console: /dev/ttyABC4 + fastboot: cacafada + ftdi_gpio: "s:0x0403:0x6011:FT7YWRL8;D" + - board: myboard-6 + name: "My Board 2" + description: | + My Awesome board Number 6 + console: /dev/ttyABC5 + fastboot: cacafada + ftdi_gpio: "s:0x0403:0x6011:FT7YWRL8" + - board: myboard-7 + name: "My Board 2" + description: | + My Awesome board Number 7 + console: /dev/ttyABC6 + fastboot: cacafada + ftdi_gpio: "i:0x0403:0x6011;D;POWER,1,ACTIVE_LOW;FASTBOOT_KEY,0,ACTIVE_HIGH;POWER_KEY,3,ACTIVE_HIGH;USB_DISCONNECT,7,ACTIVE_LOW" + - board: myboard-8 + name: "My Board 2" + description: | + My Awesome board Number 7 + console: /dev/ttyABC6 + fastboot: cacafada + ftdi_gpio: "i:0x0403:0x6011:0;D;POWER,1,ACTIVE_LOW;FASTBOOT_KEY,0,ACTIVE_HIGH;POWER_KEY,3,ACTIVE_HIGH;USB_DISCONNECT,7,ACTIVE_LOW" + - board: myboard-9 + name: "My Board 2" + description: | + My Awesome board Number 7 + console: /dev/ttyABC6 + fastboot: cacafada + ftdi_gpio: "d:/dev/bus/usb/006/001;D;POWER,1,ACTIVE_LOW;FASTBOOT_KEY,0,ACTIVE_HIGH;POWER_KEY,3,ACTIVE_HIGH;USB_DISCONNECT,7,ACTIVE_LOW" diff --git a/config-samples/sample2.yaml b/config-samples/sample2.yaml new file mode 100644 index 0000000..f2a5114 --- /dev/null +++ b/config-samples/sample2.yaml @@ -0,0 +1,12 @@ +--- +devices: + - board: myboard + name: "My Board" + description: | + My Awesome board + console: /dev/ttyABC0 + fastboot: cacafada + fastboot_set_active: b + fastboot_key_timeout: 2 + usb_always_on: false + conmux: /dev/serial/by-id/usb-CDBA-if00 diff --git a/config-samples/sample3.yaml b/config-samples/sample3.yaml new file mode 100644 index 0000000..50921e1 --- /dev/null +++ b/config-samples/sample3.yaml @@ -0,0 +1,12 @@ +--- +devices: + - board: myboard + name: "My Board" + description: | + My Awesome board + console: /dev/ttyABC0 + fastboot: cacafada + fastboot_set_active: true + fastboot_key_timeout: 2 + usb_always_on: false + external: /path/to/my/awesome/script.sh diff --git a/config-samples/sample4.yaml b/config-samples/sample4.yaml new file mode 100644 index 0000000..9e67b51 --- /dev/null +++ b/config-samples/sample4.yaml @@ -0,0 +1,13 @@ +--- +devices: + - board: myboard + name: "My Board" + description: | + My Awesome board + console: /dev/ttyABC0 + fastboot: cacafada + fastboot_set_active: true + fastboot_key_timeout: 2 + usb_always_on: false + ppps_path: 2-2:1.0/2-2-port2 + ppps3_path: 2-2:2.0/2-2-port2 diff --git a/config-samples/sample5.yaml b/config-samples/sample5.yaml new file mode 100644 index 0000000..e4c0771 --- /dev/null +++ b/config-samples/sample5.yaml @@ -0,0 +1,12 @@ +--- +devices: + - board: myboard + name: "My Board" + description: | + My Awesome board + console: /dev/ttyABC0 + fastboot: cacafada + fastboot_set_active: true + fastboot_key_timeout: 2 + usb_always_on: false + qcomlt_debug_board: /dev/serial/by-id/usb-DebugBoard-if00 diff --git a/config-samples/sample6.yaml b/config-samples/sample6.yaml new file mode 100644 index 0000000..f544d1b --- /dev/null +++ b/config-samples/sample6.yaml @@ -0,0 +1,12 @@ +--- +devices: + - board: myboard + name: "My Board" + description: | + My Awesome board + console: /dev/ttyABC0 + fastboot: cacafada + fastboot_set_active: true + fastboot_key_timeout: 2 + usb_always_on: false + alpaca: /dev/serial/by-id/usb-ALPACA-if00 diff --git a/config-samples/sample7.yaml b/config-samples/sample7.yaml new file mode 100644 index 0000000..7fc3ee0 --- /dev/null +++ b/config-samples/sample7.yaml @@ -0,0 +1,16 @@ +--- +devices: + - board: myboard + name: "My Board" + description: | + My Awesome board + console: /dev/ttyABC0 + fastboot: cacafada + fastboot_set_active: true + fastboot_key_timeout: 2 + usb_always_on: false + cdba: /dev/serial/by-id/usb-CDBA-if00 + voltage: 1800 + users: + - toto + - tata diff --git a/config-samples/sample8.yaml b/config-samples/sample8.yaml new file mode 100644 index 0000000..67c7427 --- /dev/null +++ b/config-samples/sample8.yaml @@ -0,0 +1,75 @@ +--- +devices: + - board: myboard + name: "My Board" + description: | + My Awesome board + console: /dev/ttyABC0 + fastboot: cacafada + ftdi_gpio: + vendor: "0x0403" + product: "0x6011" + serial: FT7YWRL8 + power_key: + interface: A + line: 2 + fastboot_key: + interface: A + line: 0 + active_low: true + power: + interface: A + line: 1 + active_low: true + - board: myboard-2 + name: "My Board 2" + description: | + My Awesome board Number 2 + console: /dev/ttyABC1 + fastboot: cacafada + ftdi_gpio: + vendor: "0x0403" + product: "0x6011" + index: 0 + power: + interface: B + line: 1 + active_low: true + fastboot_key: + interface: B + line: 0 + active_low: true + power_key: + interface: B + line: 2 + usb_disconnect: + interface: C + line: 7 + active_low: true + - board: myboard-3 + name: "My Board 3" + description: | + My Awesome board Number 3 + console: /dev/ttyABC1 + fastboot: cacafada + ftdi_gpio: + vendor: "0x0403" + product: "0x6011" + power_key: + interface: B + line: 2 + power: + interface: D + line: 1 + active_low: true + - board: myboard-4 + name: "My Board 4" + description: | + My Awesome board Number 4 + console: /dev/ttyABC1 + fastboot: cacafada + ftdi_gpio: + devicenode: /dev/bus/usb/006/001 + power: + interface: D + line: 6 diff --git a/config-samples/sample9.yaml b/config-samples/sample9.yaml new file mode 100644 index 0000000..8c9f582 --- /dev/null +++ b/config-samples/sample9.yaml @@ -0,0 +1,26 @@ +--- +devices: + - board: myboard + name: "My Board" + description: | + My Awesome board + console: /dev/ttyABC0 + fastboot: cacafada + fastboot_set_active: true + fastboot_key_timeout: 2 + local_gpio: + power: + chip: gpiochip0 + line: 7 + active_low: true + fastboot_key: + chip: gpiochip0 + line: 8 + active_low: true + power_key: + chip: gpiochip0 + line: 14 + active_low: true + usb_disconnect: + chip: gpiochip0 + line: 4 diff --git a/schema.yaml b/schema.yaml new file mode 100644 index 0000000..caf0860 --- /dev/null +++ b/schema.yaml @@ -0,0 +1,189 @@ +"$schema": https://json-schema.org/draft/2020-12/schema# +title: CDBA Configuration Schema +type: object +properties: + devices: + type: array + items: + type: object + properties: + board: + description: board identifier to be used by cdba client + type: string + + name: + description: board pretty name to be printed by cdba client when querying boards + type: string + + description: + description: board verbose description for reference + type: string + + console: + description: console TTY device path + $ref: "#/$defs/device_path" + + fastboot: + description: fastboot id + type: string + pattern: "^[0-9a-f]{8}$" + + fastboot_set_active: + description: run fastboot set active before each boot, slot can be selected + oneOf: + - type: boolean + - enum: + - a + - b + + broken_fastboot_boot: + description: Is fastboot boot broken, in this case boot is flashed and board is rebooted + type: boolean + + usb_always_on: + description: mark USB as always on + type: boolean + + fastboot_key_timeout: + description: timeout of the fastbook key press + type: integer + minimum: 1 + + cdba: + description: CDB Assist device path + $ref: "#/$defs/device_path" + + voltage: + description: CDB Assist voltage in microvolt + type: integer + + conmux: + description: conmux service string + type: string + + external: + description: path to the program that handles board power, usb and key controls + type: string + + ppps_path: + description: USB device name, like 2-2:1.0/2-2-port2 + type: string + + ppps3_path: + description: USB device name, like 2-2:1.0/2-2-port2 + type: string + + qcomlt_debug_board: + description: Qlt Debug Board control tty device path + $ref: "#/$defs/device_path" + + alpaca: + description: Alpaca board control device path + $ref: "#/$defs/device_path" + + users: + description: User access allowance for the board + type: array + uniqueItems: true + minItems: 1 + items: + type: string + + ftdi_gpio: + description: GPIO control over FTDI chip + oneOf: + - type: string + # ;[[;...]] + # - libftdi description: ftdi_usb_open_string() formats + # - interface: A, B, C or D (default A) + # - gpios: type,id,polarity + # - type: POWER, FASTBOOT_KEY, POWER_KEY or USB_DISCONNECT + # - id: 0, 1, 2, 3, 4, 5, 6 or 7 + # - polarity: ACTIVE_HIGH or ACTIVE_LOW + pattern: "^(d:/.*)|(i:0x[0-9a-fA-F]{4}:0x[0-9a-fA-F]{4}(:[0-9]+)?)|(s:0x[0-9a-fA-F]{4}:0x[0-9a-fA-F]{4}:FT[0-9a-zA-Z]{6})(;[A-D](;(POWER|FASTBOOT_KEY|POWER_KEY|USB_DISCONNECT),[0-7],(ACTIVE_HIGH|ACTIVE_LOW)){0,4})?$" + deprecated: true + + - type: object + properties: + vendor: + type: string + pattern: "^0x[0-9a-fA-F]{4}$" + product: + type: string + pattern: "^0x[0-9a-fA-F]{4}$" + serial: + type: string + pattern: "^FT[0-9a-zA-Z]{6}" + index: + type: integer + minimin: 0 + devicenode: + $ref: "#/$defs/device_path" + patternProperties: + "^power|fastboot_key|power_key|usb_disconnect|output_enable$": + $ref: "#/$defs/ftdi_gpio" + + dependentRequired: + index: + - product + - vendor + serial: + - product + - vendor + + local_gpio: + description: Local GPIO + type: object + unevaluatedItems: false + patternProperties: + "^power|fastboot_key|power_key|usb_disconnect$": + $ref: "#/$defs/local_gpio" + required: + - board + - name + + additionalProperties: false + +required: + - devices + +additionalProperties: false + +$defs: + device_path: + type: string + pattern: "^/dev/.*$" + + ftdi_gpio: + type: object + properties: + interface: + enum: + - A + - B + - C + - D + line: + type: integer + minimum: 0 + maximum: 7 + active_low: + type: boolean + required: + - interface + - line + + local_gpio: + type: object + properties: + chip: + type: string + pattern: "^gpiochip[0-9]+$" + line: + type: integer + minimum: 0 + active_low: + type: boolean + required: + - chip + - line diff --git a/validate.py b/validate.py new file mode 100644 index 0000000..e0dfc5b --- /dev/null +++ b/validate.py @@ -0,0 +1,23 @@ +import os +import sys +import argparse +import json +import jsonschema +import ruamel.yaml + +if __name__ == "__main__": + ap = argparse.ArgumentParser() + ap.add_argument("cfg", help="Filename YAML input file") + ap.add_argument('-s', '--schema', help="schema file") + args = ap.parse_args() + + yaml = ruamel.yaml.YAML(typ='safe') + yaml.allow_duplicate_keys = False + + with open(args.schema, 'r', encoding='utf-8') as f: + schema = yaml.load(f.read()) + + with open(args.cfg, 'r', encoding='utf-8') as f: + cfg = yaml.load(f.read()) + + jsonschema.validate(cfg, schema=schema)