Skip to content

Commit 5e6a988

Browse files
committed
Add yaml schema and validator
Closes: #41 Signed-off-by: Neil Armstrong <[email protected]>
1 parent 494b048 commit 5e6a988

File tree

2 files changed

+212
-0
lines changed

2 files changed

+212
-0
lines changed

schema.yaml

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
"$schema": https://json-schema.org/draft/2020-12/schema#
2+
title: CDBA Configuration Schema
3+
type: object
4+
properties:
5+
devices:
6+
type: array
7+
items:
8+
type: object
9+
properties:
10+
board:
11+
description: board identifier to be used by cdba client
12+
type: string
13+
14+
name:
15+
description: board pretty name to be printed by cdba client when querying boards
16+
type: string
17+
18+
description:
19+
description: board verbose description for reference
20+
type: string
21+
22+
console:
23+
description: console TTY device path
24+
$ref: "#/$defs/device_path"
25+
26+
fastboot:
27+
description: fastboot id
28+
type: string
29+
pattern: "^[0-9a-f]{8}$"
30+
31+
fastboot_set_active:
32+
description: run fastboot set active before each boot, slot can be selected
33+
oneOf:
34+
- type: boolean
35+
- enum:
36+
- a
37+
- b
38+
39+
broken_fastboot_boot:
40+
description: Is fastboot boot broken, in this case boot is flashed and board is rebooted
41+
type: boolean
42+
43+
usb_always_on:
44+
description: mark USB as always on
45+
type: boolean
46+
47+
fastboot_key_timeout:
48+
description: timeout of the fastbook key press
49+
type: integer
50+
minimum: 1
51+
52+
cdba:
53+
description: CDB Assist device path
54+
$ref: "#/$defs/device_path"
55+
56+
voltage:
57+
description: CDB Assist voltage in microvolt
58+
type: integer
59+
60+
conmux:
61+
description: conmux service string
62+
type: string
63+
64+
external:
65+
description: path to the program that handles board power, usb and key controls
66+
type: string
67+
68+
ppps_path:
69+
description: USB device name, like 2-2:1.0/2-2-port2
70+
type: string
71+
72+
ppps3_path:
73+
description: USB device name, like 2-2:1.0/2-2-port2
74+
type: string
75+
76+
qcomlt_debug_board:
77+
description: Qlt Debug Board control tty device path
78+
$ref: "#/$defs/device_path"
79+
80+
alpaca:
81+
description: Alpaca board control device path
82+
$ref: "#/$defs/device_path"
83+
84+
users:
85+
description: User access allowance for the board
86+
type: array
87+
uniqueItems: true
88+
minItems: 1
89+
items:
90+
type: string
91+
92+
ftdi_gpio:
93+
description: GPIO control over FTDI chip
94+
oneOf:
95+
- type: string
96+
# <libftdi description>;[<interface>[;<gpios>...]]
97+
# - libftdi description: ftdi_usb_open_string() formats
98+
# - interface: A, B, C or D (default A)
99+
# - gpios: type,id,polarity
100+
# - type: POWER, FASTBOOT_KEY, POWER_KEY or USB_DISCONNECT
101+
# - id: 0, 1, 2, 3, 4, 5, 6 or 7
102+
# - polarity: ACTIVE_HIGH or ACTIVE_LOW
103+
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})?$"
104+
deprecated: true
105+
106+
- type: object
107+
properties:
108+
vendor:
109+
type: string
110+
pattern: "^0x[0-9a-fA-F]{4}$"
111+
product:
112+
type: string
113+
pattern: "^0x[0-9a-fA-F]{4}$"
114+
serial:
115+
type: string
116+
pattern: "^FT[0-9a-zA-Z]{6}"
117+
index:
118+
type: integer
119+
minimin: 0
120+
devicenode:
121+
$ref: "#/$defs/device_path"
122+
patternProperties:
123+
"^power|fastboot_key|power_key|usb_disconnect|output_enable$":
124+
$ref: "#/$defs/ftdi_gpio"
125+
126+
dependentRequired:
127+
index:
128+
- product
129+
- vendor
130+
serial:
131+
- product
132+
- vendor
133+
134+
local_gpio:
135+
description: Local GPIO
136+
type: object
137+
unevaluatedItems: false
138+
patternProperties:
139+
"^power|fastboot_key|power_key|usb_disconnect$":
140+
$ref: "#/$defs/local_gpio"
141+
required:
142+
- board
143+
- name
144+
145+
additionalProperties: false
146+
147+
required:
148+
- devices
149+
150+
additionalProperties: false
151+
152+
$defs:
153+
device_path:
154+
type: string
155+
pattern: "^/dev/.*$"
156+
157+
ftdi_gpio:
158+
type: object
159+
properties:
160+
interface:
161+
enum:
162+
- A
163+
- B
164+
- C
165+
- D
166+
line:
167+
type: integer
168+
minimum: 0
169+
maximum: 7
170+
active_low:
171+
type: boolean
172+
required:
173+
- interface
174+
- line
175+
176+
local_gpio:
177+
type: object
178+
properties:
179+
chip:
180+
type: string
181+
pattern: "^gpiochip[0-9]+$"
182+
line:
183+
type: integer
184+
minimum: 0
185+
active_low:
186+
type: boolean
187+
required:
188+
- chip
189+
- line

validate.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import os
2+
import sys
3+
import argparse
4+
import json
5+
import jsonschema
6+
import ruamel.yaml
7+
8+
if __name__ == "__main__":
9+
ap = argparse.ArgumentParser()
10+
ap.add_argument("cfg", help="Filename YAML input file")
11+
ap.add_argument('-s', '--schema', help="schema file")
12+
args = ap.parse_args()
13+
14+
yaml = ruamel.yaml.YAML(typ='safe')
15+
yaml.allow_duplicate_keys = False
16+
17+
with open(args.schema, 'r', encoding='utf-8') as f:
18+
schema = yaml.load(f.read())
19+
20+
with open(args.cfg, 'r', encoding='utf-8') as f:
21+
cfg = yaml.load(f.read())
22+
23+
jsonschema.validate(cfg, schema=schema)

0 commit comments

Comments
 (0)