mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-27 10:22:08 +00:00
Merge pull request #198 from Telecominfraproject/main_json_schema
Convert schema into JSON
This commit is contained in:
@@ -94,7 +94,10 @@ get_cfg:
|
||||
hash:
|
||||
cd ../utilities/checksums; ./hashes.sh $(shell pwd)/$(OUT) -ec
|
||||
|
||||
oc_connect1: $(OUT)/OpenCellular.bin
|
||||
gen_schema:
|
||||
cd ../utilities/schema; ./mk_schema.sh
|
||||
|
||||
oc_connect1: gen_schema $(OUT)/OpenCellular.bin
|
||||
|
||||
$(OUT)/%/compiler.opt $(OUT)/%/linker.cmd : %.cfg
|
||||
$(CONFIGURO) -c $(TOOLCHAIN) -t $(TARGET) -p $(PLATFORM) -r release $<
|
||||
|
||||
1105
firmware/ec/platform/oc-sdr/schema/auto_schema.c
Normal file
1105
firmware/ec/platform/oc-sdr/schema/auto_schema.c
Normal file
File diff suppressed because it is too large
Load Diff
38
firmware/ec/platform/oc-sdr/schema/auto_schema.h
Normal file
38
firmware/ec/platform/oc-sdr/schema/auto_schema.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
#ifndef _AUTO_SCHEMA_H
|
||||
#define _AUTO_SCHEMA_H
|
||||
|
||||
#include "common/inc/global/Framework.h"
|
||||
#include "common/inc/global/OC_CONNECT1.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_adt7481.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_dat-xxr5a-pp.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_debugi2c.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_debugmdio.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_debugmdio.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_debugocgpio.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_eeprom_cat24c04.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_eth_sw.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_fe-param.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_ina226.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_iridium.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_led.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_ltc4015.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_ltc4274.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_ltc4275.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_mac.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_powersource.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_rfpowermonitor.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_rfwatchdog.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_se98a.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_syncio.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_testmodule.h"
|
||||
#include "schema.h"
|
||||
|
||||
#endif /* _AUTO_SCHEMA_H */
|
||||
File diff suppressed because it is too large
Load Diff
895
firmware/ec/platform/oc-sdr/schema/sys_schema.json
Normal file
895
firmware/ec/platform/oc-sdr/schema/sys_schema.json
Normal file
@@ -0,0 +1,895 @@
|
||||
[
|
||||
{
|
||||
"name": "system",
|
||||
"driver_cfg": "gbc_spi_flash_memory",
|
||||
"ssHookSet": {
|
||||
"preInitFxn": "NULL",
|
||||
"postInitFxn": "sys_post_init"
|
||||
},
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"driver": "SYSTEMDRV",
|
||||
"driver_cfg": "gbc_gpp_gpioCfg",
|
||||
"components": [
|
||||
{
|
||||
"name": "eeprom_sid",
|
||||
"driver": "CAT24C04_gbc_sid",
|
||||
"driver_cfg": "eeprom_gbc_sid"
|
||||
},
|
||||
{
|
||||
"name": "eeprom_inv",
|
||||
"driver": "CAT24C04_gbc_inv",
|
||||
"driver_cfg": "eeprom_gbc_inv"
|
||||
},
|
||||
{
|
||||
"name": "eeprom_mac",
|
||||
"driver": "Driver_MAC"
|
||||
},
|
||||
{
|
||||
"name": "SPI_flash",
|
||||
"driver": "FLASHDRV",
|
||||
"driver_cfg": "gbc_spi_flash_memory"
|
||||
}
|
||||
],
|
||||
"commands": [
|
||||
{
|
||||
"name": "reset",
|
||||
"cb_cmd": "SYS_cmdReset"
|
||||
},
|
||||
{
|
||||
"name": "echo",
|
||||
"cb_cmd": "SYS_cmdEcho"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "power",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"components": [
|
||||
{
|
||||
"name": "powerSource",
|
||||
"driver": "PWRSRC",
|
||||
"driver_cfg": "gbc_pwr_powerSource",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "leadacid_sensor",
|
||||
"components": [
|
||||
{
|
||||
"name": "temp_sensor1",
|
||||
"driver": "SE98A",
|
||||
"driver_cfg": "gbc_pwr_lead_acid_ts",
|
||||
"factory_config": "fact_bc_se98a"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "leadacid",
|
||||
"components": [
|
||||
{
|
||||
"name": "battery",
|
||||
"driver": "LTC4015",
|
||||
"driver_cfg": "gbc_pwr_ext_bat_charger",
|
||||
"factory_config": "fact_leadAcid_cfg"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "lion",
|
||||
"components": [
|
||||
{
|
||||
"name": "battery",
|
||||
"driver": "LTC4015",
|
||||
"driver_cfg": "gbc_pwr_int_bat_charger",
|
||||
"factory_config": "fact_lithiumIon_cfg"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "pse",
|
||||
"driver": "LTC4274",
|
||||
"driver_cfg": "gbc_pwr_pse",
|
||||
"factory_config": "fact_ltc4274_cfg"
|
||||
},
|
||||
{
|
||||
"name": "pd",
|
||||
"driver": "LTC4275",
|
||||
"driver_cfg": "gbc_pwr_pd"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bms",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "ec",
|
||||
"components": [
|
||||
{
|
||||
"name": "temp_sensor1",
|
||||
"driver": "SE98A",
|
||||
"driver_cfg": "gbc_bms_ec_ts",
|
||||
"factory_config": "fact_ec_se98a_cfg"
|
||||
},
|
||||
{
|
||||
"name": "current_sensor1",
|
||||
"driver": "INA226",
|
||||
"driver_cfg": "gbc_bms_ec_ps_12v",
|
||||
"factory_config": "fact_ec_12v_ps_cfg"
|
||||
},
|
||||
{
|
||||
"name": "current_sensor2",
|
||||
"driver": "INA226",
|
||||
"driver_cfg": "gbc_bms_ec_ps_3p3v",
|
||||
"factory_config": "fact_ec_3v_ps_cfg"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "hci",
|
||||
"ssHookSet": {
|
||||
"preInitFxn": "HCI_Init",
|
||||
"postInitFxn": "NULL"
|
||||
},
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "led",
|
||||
"components": [
|
||||
{
|
||||
"name": "temp_sensor1",
|
||||
"driver": "SE98A",
|
||||
"driver_cfg": "led_hci_ts",
|
||||
"factory_config": "fact_led_se98a_cfg",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "fw",
|
||||
"driver": "HCI_LED",
|
||||
"driver_cfg": "led_hci_ioexp"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "buzzer",
|
||||
"driver_cfg": "gbc_hci_buzzer",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ethernet",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "port0",
|
||||
"driver": "ETH_SW",
|
||||
"driver_cfg": "gbc_eth_port0"
|
||||
},
|
||||
{
|
||||
"name": "port1",
|
||||
"driver": "ETH_SW",
|
||||
"driver_cfg": "gbc_eth_port1"
|
||||
},
|
||||
{
|
||||
"name": "port2",
|
||||
"driver": "ETH_SW",
|
||||
"driver_cfg": "gbc_eth_port2"
|
||||
},
|
||||
{
|
||||
"name": "port3",
|
||||
"driver": "ETH_SW",
|
||||
"driver_cfg": "gbc_eth_port3"
|
||||
},
|
||||
{
|
||||
"name": "port4",
|
||||
"driver": "ETH_SW",
|
||||
"driver_cfg": "gbc_eth_port4"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "obc",
|
||||
"ssHookSet": {
|
||||
"preInitFxn": "obc_pre_init",
|
||||
"postInitFxn": "NULL"
|
||||
},
|
||||
"driver_cfg": "sync_obc_gpiocfg",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "iridium",
|
||||
"driver": "OBC_Iridium",
|
||||
"driver_cfg": "obc_irridium"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "gpp",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "ap",
|
||||
"components": [
|
||||
{
|
||||
"name": "temp_sensor1",
|
||||
"driver": "SE98A",
|
||||
"driver_cfg": "gbc_gpp_ap_ts1",
|
||||
"factory_config": "fact_ap_se98a_ts1_cfg"
|
||||
},
|
||||
{
|
||||
"name": "temp_sensor2",
|
||||
"driver": "SE98A",
|
||||
"driver_cfg": "gbc_gpp_ap_ts2",
|
||||
"factory_config": "fact_ap_se98a_ts2_cfg"
|
||||
},
|
||||
{
|
||||
"name": "temp_sensor3",
|
||||
"driver": "SE98A",
|
||||
"driver_cfg": "gbc_gpp_ap_ts3",
|
||||
"factory_config": "fact_ap_se98a_ts3_cfg"
|
||||
},
|
||||
{
|
||||
"name": "current_sensor1",
|
||||
"driver": "INA226",
|
||||
"driver_cfg": "gbc_gpp_ap_ps",
|
||||
"factory_config": "fact_ap_3v_ps_cfg"
|
||||
}
|
||||
],
|
||||
"driver_cfg": "gbc_gpp_gpioCfg",
|
||||
"commands": [
|
||||
{
|
||||
"name": "reset",
|
||||
"cb_cmd": "GPP_ap_Reset"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "msata",
|
||||
"components": [
|
||||
{
|
||||
"name": "current_sensor1",
|
||||
"driver": "INA226",
|
||||
"driver_cfg": "gbc_gpp_msata_ps",
|
||||
"factory_config": "fact_msata_3v_ps_cfg"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"driver_cfg": "gbc_gpp_gpioCfg",
|
||||
"ssHookSet": {
|
||||
"preInitFxn": "gpp_pre_init",
|
||||
"postInitFxn": "gpp_post_init"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "sdr",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"components": [
|
||||
{
|
||||
"name": "current_sensor1",
|
||||
"driver": "INA226",
|
||||
"driver_cfg": "sdr_ps",
|
||||
"factory_config": "fact_sdr_3v_ps_cfg"
|
||||
},
|
||||
{
|
||||
"name": "eeprom",
|
||||
"driver_cfg": "eeprom_sdr_inv",
|
||||
"driver": "CAT24C04_sdr_inv"
|
||||
}
|
||||
],
|
||||
"driver_cfg": "sdr_gpioCfg",
|
||||
"commands": [
|
||||
{
|
||||
"name": "reset",
|
||||
"cb_cmd": "SDR_reset"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "fpga",
|
||||
"components": [
|
||||
{
|
||||
"name": "temp_sensor1",
|
||||
"driver": "ADT7481",
|
||||
"driver_cfg": "sdr_fpga_ts",
|
||||
"factory_config": "fact_sdr_fpga_adt7481_cfg"
|
||||
},
|
||||
{
|
||||
"name": "current_sensor1",
|
||||
"driver": "INA226",
|
||||
"driver_cfg": "sdr_fpga_ps",
|
||||
"factory_config": "fact_sdr_fpga_ps_cfg"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "fx3",
|
||||
"driver_cfg": "sdr_gpioCfg",
|
||||
"commands": [
|
||||
{
|
||||
"name": "reset",
|
||||
"cb_cmd": "SDR_fx3Reset"
|
||||
}
|
||||
],
|
||||
"postDisabled": "POST_DISABLED"
|
||||
}
|
||||
],
|
||||
"driver_cfg": "sdr_gpioCfg",
|
||||
"ssHookSet": {
|
||||
"preInitFxn": "SDR_Init",
|
||||
"postInitFxn": "NULL"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "rffe",
|
||||
"driver_cfg": "fe_rffecfg",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"components": [
|
||||
{
|
||||
"name": "eeprom",
|
||||
"driver": "CAT24C04_fe_inv",
|
||||
"driver_cfg": "eeprom_fe_inv"
|
||||
}
|
||||
],
|
||||
"driver_cfg": "sdr_gpioCfg",
|
||||
"commands": [
|
||||
{
|
||||
"name": "reset",
|
||||
"cb_cmd": "RFFE_reset"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ch1_sensor",
|
||||
"components": [
|
||||
{
|
||||
"name": "temp_sensor1",
|
||||
"driver": "ADT7481",
|
||||
"driver_cfg": "fe_ch1_ts",
|
||||
"factory_config": "fact_fe_ch1_adt7481_cfg"
|
||||
},
|
||||
{
|
||||
"name": "current_sensor1",
|
||||
"driver": "INA226",
|
||||
"driver_cfg": "fe_ch1_ps_5_7v",
|
||||
"factory_config": "fact_fe_ch1_ps_cfg"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ch2_sensor",
|
||||
"components": [
|
||||
{
|
||||
"name": "temp_sensor1",
|
||||
"driver": "ADT7481",
|
||||
"driver_cfg": "fe_ch2_ts",
|
||||
"factory_config": "fact_fe_ch2_adt7481_cfg"
|
||||
},
|
||||
{
|
||||
"name": "current_sensor1",
|
||||
"driver": "INA226",
|
||||
"driver_cfg": "fe_ch2_ps_5_7v",
|
||||
"factory_config": "fact_fe_ch2_ps_cfg"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ch1_fe",
|
||||
"driver_cfg": "fe_ch1_pwrcfg",
|
||||
"components": [
|
||||
{
|
||||
"name": "ch1_band",
|
||||
"driver": "FE_Param",
|
||||
"driver_cfg": "fe_ch1_bandcfg",
|
||||
"factory_config": "fact_ch1_band_cfg"
|
||||
},
|
||||
{
|
||||
"name": "watchdog",
|
||||
"driver": "RFFEWatchdog",
|
||||
"driver_cfg": "fe_ch1_watchdog"
|
||||
},
|
||||
{
|
||||
"name": "power",
|
||||
"driver": "RFPowerMonitor",
|
||||
"driver_cfg": "fe_ch1_ads7830"
|
||||
},
|
||||
{
|
||||
"name": "tx",
|
||||
"driver": "DATXXR5APP",
|
||||
"driver_cfg": "fe_ch1_gain",
|
||||
"factory_config": "fact_ch1_tx_gain_cfg"
|
||||
},
|
||||
{
|
||||
"name": "rx",
|
||||
"driver": "DATXXR5APP",
|
||||
"driver_cfg": "fe_ch1_lna",
|
||||
"factory_config": "fact_ch1_rx_gain_cfg"
|
||||
}
|
||||
],
|
||||
"commands": [
|
||||
{
|
||||
"name": "enable",
|
||||
"cb_cmd": "RFFE_enablePA"
|
||||
},
|
||||
{
|
||||
"name": "disable",
|
||||
"cb_cmd": "RFFE_disablePA"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ch2_fe",
|
||||
"driver_cfg": "fe_ch2_pwrcfg",
|
||||
"components": [
|
||||
{
|
||||
"name": "ch2_band",
|
||||
"driver": "FE_Param",
|
||||
"driver_cfg": "fe_ch2_bandcfg",
|
||||
"factory_config": "fact_ch2_band_cfg"
|
||||
},
|
||||
{
|
||||
"name": "watchdog",
|
||||
"driver": "RFFEWatchdog",
|
||||
"driver_cfg": "fe_ch2_watchdog"
|
||||
},
|
||||
{
|
||||
"name": "power",
|
||||
"driver": "RFPowerMonitor",
|
||||
"driver_cfg": "fe_ch2_ads7830"
|
||||
},
|
||||
{
|
||||
"name": "tx",
|
||||
"driver": "DATXXR5APP",
|
||||
"driver_cfg": "fe_ch2_gain",
|
||||
"factory_config": "fact_ch2_tx_gain_cfg"
|
||||
},
|
||||
{
|
||||
"name": "rx",
|
||||
"driver": "DATXXR5APP",
|
||||
"driver_cfg": "fe_ch2_lna",
|
||||
"factory_config": "fact_ch2_rx_gain_cfg"
|
||||
}
|
||||
],
|
||||
"commands": [
|
||||
{
|
||||
"name": "enable",
|
||||
"cb_cmd": "RFFE_enablePA"
|
||||
},
|
||||
{
|
||||
"name": "disable",
|
||||
"cb_cmd": "RFFE_disablePA"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"ssHookSet": {
|
||||
"preInitFxn": "rffe_pre_init",
|
||||
"postInitFxn": "rffe_post_init"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "sync",
|
||||
"driver_cfg": "sync_gpiocfg",
|
||||
"ssHookSet": {
|
||||
"preInitFxn": "SYNC_Init",
|
||||
"postInitFxn": "NULL"
|
||||
},
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"driver_cfg": "sync_gpiocfg",
|
||||
"commands": [
|
||||
{
|
||||
"name": "reset",
|
||||
"cb_cmd": "SYNC_reset"
|
||||
}
|
||||
],
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "gps",
|
||||
"driver_cfg": "sync_gpiocfg",
|
||||
"driver": "Sync_IO"
|
||||
},
|
||||
{
|
||||
"name": "sensor",
|
||||
"components": [
|
||||
{
|
||||
"name": "temp_sensor1",
|
||||
"driver": "ADT7481",
|
||||
"driver_cfg": "sync_gps_ts",
|
||||
"factory_config": "fact_sync_ts_cfg"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "testmodule",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"commands": [
|
||||
{
|
||||
"name": "reset",
|
||||
"cb_cmd": "TestMod_cmdReset"
|
||||
}
|
||||
],
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "2gsim",
|
||||
"driver": "Testmod_G510",
|
||||
"driver_cfg": "testModuleCfg"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "debug",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "I2C",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "bus0",
|
||||
"driver": "OC_I2C",
|
||||
"driver_cfg": "debug_I2C0",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "bus1",
|
||||
"driver": "OC_I2C",
|
||||
"driver_cfg": "debug_I2C1",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "bus2",
|
||||
"driver": "OC_I2C",
|
||||
"driver_cfg": "debug_I2C2",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "bus3",
|
||||
"driver": "OC_I2C",
|
||||
"driver_cfg": "debug_I2C3",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "bus4",
|
||||
"driver": "OC_I2C",
|
||||
"driver_cfg": "debug_I2C4",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "bus6",
|
||||
"driver": "OC_I2C",
|
||||
"driver_cfg": "debug_I2C6",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "bus7",
|
||||
"driver": "OC_I2C",
|
||||
"driver_cfg": "debug_I2C7",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "bus8",
|
||||
"driver": "OC_I2C",
|
||||
"driver_cfg": "debug_I2C8",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ec",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PA",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pa",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PB",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pb",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PC",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pc",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PD",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pd",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PE",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pe",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PF",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pf",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PG",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pg",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PH",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_ph",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PJ",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pj",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PK",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pk",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PL",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pl",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PM",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pm",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PN",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pn",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PP",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pn",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "PQ",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_ec_gpio_pq",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "gbc",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "ioexpanderx70",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_gbc_ioexpanderx70"
|
||||
},
|
||||
{
|
||||
"name": "ioexpanderx71",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_gbc_ioexpanderx71"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "sdr",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "ioexpanderx1E",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_sdr_ioexpanderx1E"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "fe",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "ioexpanderx18",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_sdr_ioexpanderx1E"
|
||||
},
|
||||
{
|
||||
"name": "ioexpanderx1C",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_fe_ioexpanderx1C"
|
||||
},
|
||||
{
|
||||
"name": "ioexpanderx1B",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_fe_ioexpanderx1B"
|
||||
},
|
||||
{
|
||||
"name": "ioexpanderx1A",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_fe_ioexpanderx1A"
|
||||
},
|
||||
{
|
||||
"name": "ioexpanderx1D",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_fe_ioexpanderx1D"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "sync",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "ioexpanderx71",
|
||||
"driver": "OC_GPIO",
|
||||
"driver_cfg": "debug_sync_ioexpanderx71"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ethernet",
|
||||
"components": [
|
||||
{
|
||||
"name": "comp_all",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "port0",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_phyport0",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "port1",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_phyport1",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "port2",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_phyport2",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "port3",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_phyport3",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "port4",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_phyport4",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "global1",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_global1",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "global2",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_global2",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "swport0",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_swport0",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "swport1",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_swport1",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "swport2",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_swport2",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "swport3",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_swport3",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "swport4",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_swport4",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "swport5",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_swport5",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
},
|
||||
{
|
||||
"name": "swport6",
|
||||
"driver": "OC_MDIO",
|
||||
"driver_cfg": "debug_mdio_swport6",
|
||||
"postDisabled": "POST_DISABLED"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -15,11 +15,14 @@ default:
|
||||
@mkdir -p $(output_dir)
|
||||
make all
|
||||
|
||||
all: get_cfg ocmw_uart ocmw_usb ocmw_eth occli ocmw_eth_stub ocware_stub hash
|
||||
all: get_cfg gen_schema ocmw_uart ocmw_usb ocmw_eth occli ocmw_eth_stub ocware_stub hash
|
||||
|
||||
get_cfg:
|
||||
cd ../utilities/build; ./envDetect.sh
|
||||
|
||||
gen_schema:
|
||||
cd ../utilities/schema; ./mk_schema.sh
|
||||
|
||||
hash:
|
||||
cd ../utilities/checksums; ./hashes.sh $(shell pwd)/$(output_dir) -host
|
||||
|
||||
|
||||
4
firmware/utilities/schema/meta_sys_schema_d0.json
Normal file
4
firmware/utilities/schema/meta_sys_schema_d0.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description" : "General purpose JSON validator"
|
||||
}
|
||||
99
firmware/utilities/schema/meta_sys_schema_d4.json
Normal file
99
firmware/utilities/schema/meta_sys_schema_d4.json
Normal file
@@ -0,0 +1,99 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title" : "OC-SDR schema",
|
||||
"description" : "OC-SDR system specification",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Subsystem"
|
||||
},
|
||||
"definitions": {
|
||||
"Subsystem": {
|
||||
"title": "Subsystem",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {"type": "string"},
|
||||
"components": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Component"
|
||||
}
|
||||
},
|
||||
"driver_cfg": {"type": "string"},
|
||||
"ssHookSet" : {
|
||||
"type" : "object",
|
||||
"items" : {
|
||||
"$ref": "#/definitions/SsHookSet"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["name", "components"],
|
||||
"additionalProperties" : false
|
||||
},
|
||||
"Component": {
|
||||
"title" : "Component",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {"type": "string"},
|
||||
"components": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Subcomponent"
|
||||
}
|
||||
},
|
||||
"driver": {"type": "string"},
|
||||
"driver_cfg": {"type": "string"},
|
||||
"factory_config": {"type": "string"},
|
||||
"commands": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Command"
|
||||
}
|
||||
},
|
||||
"ssHookSet" : {
|
||||
"type" : "object",
|
||||
"items" : {
|
||||
"$ref": "#/definitions/SsHookSet"
|
||||
}
|
||||
},
|
||||
"postDisabled": {"type" : "string"},
|
||||
"ss" : {"type" : "string"}
|
||||
},
|
||||
"required": ["name"],
|
||||
"additionalProperties" : false
|
||||
},
|
||||
"Subcomponent" : {
|
||||
"title" : "Subcomponent",
|
||||
"type" : "object",
|
||||
"properties": {
|
||||
"name" : {"type" : "string"},
|
||||
"driver" : {"type" : "string"},
|
||||
"driver_cfg" : {"type" : "string"},
|
||||
"postDisabled" : {"type" : "string"},
|
||||
"factory_config" : {"type" : "string"}
|
||||
},
|
||||
"required" : ["name"],
|
||||
"additionalProperties" : false
|
||||
},
|
||||
"Command" : {
|
||||
"title" : "Command",
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"name": {"type" : "string"},
|
||||
"parameters" : {"type" : "string"},
|
||||
"cb_cmd" : {"type" : "string"}
|
||||
},
|
||||
"required" : ["name"],
|
||||
"additionalProperties" : false
|
||||
},
|
||||
"SsHookSet" : {
|
||||
"title" : "SSHookSet",
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"preInitFxn": {"type" : "string"},
|
||||
"postInitFxn" : {"type" : "string"}
|
||||
},
|
||||
"required" : ["preInitFxn", "postInitFxn"],
|
||||
"additionalProperties" : false
|
||||
}
|
||||
}
|
||||
}
|
||||
94
firmware/utilities/schema/meta_sys_schema_d6.json
Normal file
94
firmware/utilities/schema/meta_sys_schema_d6.json
Normal file
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-06/schema#",
|
||||
"title" : "OC-SDR schema",
|
||||
"description" : "OC-SDR system specification",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Subsystem"
|
||||
},
|
||||
"definitions": {
|
||||
"Subsystem": {
|
||||
"title": "Subsystem",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {"type": "string"},
|
||||
"components": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Component"
|
||||
}
|
||||
},
|
||||
"driver_cfg": {"type": "string"},
|
||||
"ssHookSet" : {
|
||||
"type" : "object",
|
||||
"items" : {
|
||||
"$ref": "#/definitions/SsHookSet"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["name", "components"]
|
||||
},
|
||||
"Component": {
|
||||
"title" : "Component",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {"type": "string"},
|
||||
"components": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Subcomponent"
|
||||
}
|
||||
},
|
||||
"driver": {"type": "string"},
|
||||
"driver_cfg": {"type": "string"},
|
||||
"factory_config": {"type": "string"},
|
||||
"commands": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Command"
|
||||
}
|
||||
},
|
||||
"ssHookSet" : {
|
||||
"type" : "object",
|
||||
"items" : {
|
||||
"$ref": "#/definitions/SsHookSet"
|
||||
}
|
||||
},
|
||||
"postDisabled": {"type" : "string"},
|
||||
"ss" : {"type" : "string"}
|
||||
},
|
||||
"required": ["name"]
|
||||
},
|
||||
"Subcomponent" : {
|
||||
"title" : "Subcomponent",
|
||||
"type" : "object",
|
||||
"properties": {
|
||||
"name" : {"type" : "string"},
|
||||
"driver" : {"type" : "string"},
|
||||
"driver_cfg" : {"type" : "string"},
|
||||
"postDisabled" : {"type" : "string"},
|
||||
"factory_config" : {"type" : "string"}
|
||||
},
|
||||
"required" : ["name"]
|
||||
},
|
||||
"Command" : {
|
||||
"title" : "Command",
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"name": {"type" : "string"},
|
||||
"parameters" : {"type" : "string"},
|
||||
"cb_cmd" : {"type" : "string"}
|
||||
},
|
||||
"required" : ["name"]
|
||||
},
|
||||
"SsHookSet" : {
|
||||
"title" : "SSHookSet",
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"preInitFxn": {"type" : "string"},
|
||||
"postInitFxn" : {"type" : "string"}
|
||||
},
|
||||
"required" : ["preInitFxn", "postInitFxn"]
|
||||
}
|
||||
}
|
||||
}
|
||||
48
firmware/utilities/schema/mk_schema.sh
Executable file
48
firmware/utilities/schema/mk_schema.sh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/bin/sh -e
|
||||
#
|
||||
# Description
|
||||
# The purpose of this script is to automatically generate
|
||||
# the schema C-file when it is deemed necessary.
|
||||
#
|
||||
# Notes
|
||||
# 1. To force an update, touch sys_schema.json
|
||||
# 2. See usage notes in sdtester.py
|
||||
#
|
||||
# Usage
|
||||
# Error check
|
||||
# Exit if JSON schema source file does not exist
|
||||
# Run sdtester.py when (in order of precedence):
|
||||
# 1. Auto schema C-file does not exist
|
||||
# 2. JSON validation schema file does not exist
|
||||
# 3. JSON schema source file has been updated
|
||||
# Else do nothing
|
||||
#
|
||||
VAL_FNAME=valid_schema.json
|
||||
SCHEMAPATH=../../ec/platform/oc-sdr/schema
|
||||
JSON_FNAME=sys_schema.json
|
||||
C_FNAME=auto_schema.c
|
||||
INPUT_FNAME=$SCHEMAPATH/$JSON_FNAME
|
||||
OUTPUT_FNAME=$SCHEMAPATH/$C_FNAME
|
||||
|
||||
gen_schema()
|
||||
{
|
||||
python3 sdtester.py -j $INPUT_FNAME -c $OUTPUT_FNAME
|
||||
}
|
||||
|
||||
if [ ! -e $INPUT_FNAME ]; then
|
||||
echo "ERROR: $JSON_FNAME does not exist" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -e $OUTPUT_FNAME ]; then
|
||||
echo "Generating $C_FNAME because it does not exist"
|
||||
gen_schema
|
||||
elif [ ! -e $VAL_FNAME ]; then
|
||||
echo "Generating $C_FNAME because validation file does not exist"
|
||||
gen_schema
|
||||
elif [ $INPUT_FNAME -nt $VAL_FNAME ] || [ $INPUT_FNAME -nt $OUTPUT_FNAME ]; then
|
||||
echo "Generating $C_FNAME because $JSON_FNAME has been updated"
|
||||
gen_schema
|
||||
else
|
||||
echo "$C_FNAME does not need an update"
|
||||
fi
|
||||
428
firmware/utilities/schema/schemautils.py
Normal file
428
firmware/utilities/schema/schemautils.py
Normal file
@@ -0,0 +1,428 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (c) 2018-present, Facebook, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the BSD-style license found in the
|
||||
# LICENSE file in the root directory of this source tree. An additional grant
|
||||
# of patent rights can be found in the PATENTS file in the same directory.
|
||||
#
|
||||
|
||||
import re
|
||||
import json
|
||||
import jsonschema as js
|
||||
|
||||
|
||||
class SchemaUtils:
|
||||
draftFiles = {'d0' : 'meta_sys_schema_d0.json',
|
||||
'd4' : 'meta_sys_schema_d4.json',
|
||||
'd6' : 'meta_sys_schema_d6.json'}
|
||||
|
||||
def __init__(self, md, json_fname, c_fname, draft):
|
||||
"""
|
||||
Load meta schema and configuration schema
|
||||
"""
|
||||
self.draft = draft
|
||||
self.valid = False
|
||||
self.json_fname = json_fname
|
||||
self.c_fname = c_fname
|
||||
self.sys_schema = ''
|
||||
self.md = md
|
||||
# Meta schema: this shouldn't change except when either a new JSON
|
||||
# draft requires it, or when the hardware is redesigned
|
||||
self.metaschema = json.load(open(SchemaUtils.draftFiles[draft], 'r'))
|
||||
|
||||
if md != 'g':
|
||||
# JSON definition file exists and we want to produce the
|
||||
# corresponding C-file
|
||||
|
||||
# Configuration schema: this can change any time device
|
||||
# configuration changes
|
||||
self.cfgschema = json.load(open(self.json_fname, 'r'))
|
||||
else:
|
||||
# Want to create JSON definition file from a C-file
|
||||
# containing a schema declared as a structure
|
||||
self.cfgschema = []
|
||||
|
||||
def generate(self):
|
||||
new_schema = []
|
||||
with open(self.c_fname, 'r') as f:
|
||||
in_schema = False
|
||||
# Find start of schema declaration and extract
|
||||
for line in f:
|
||||
# find start of schema declaration
|
||||
if (not in_schema) and ('sys_schema' in line):
|
||||
in_schema = True
|
||||
# Skip first line
|
||||
new_schema.append('[\n')
|
||||
continue
|
||||
if in_schema:
|
||||
new_schema.append(line)
|
||||
schema = ''.join(str(line) for line in new_schema)
|
||||
|
||||
# Remove all C language features
|
||||
schema = SchemaUtils.stripC(schema)
|
||||
# Find terminations to array declarations
|
||||
schema = SchemaUtils.fixarray(schema)
|
||||
# JSON line formatting
|
||||
schema = SchemaUtils.parse(schema, 4)
|
||||
# JSON punctuation
|
||||
self.sys_schema = SchemaUtils.punct(schema)
|
||||
|
||||
def auto_file(self):
|
||||
"""
|
||||
Write C-file from validated schema
|
||||
"""
|
||||
# Remove all JSON format features
|
||||
schema, decls = SchemaUtils.strip(self.sys_schema)
|
||||
# Format values as required for each data type
|
||||
schema = SchemaUtils.typeformat(schema)
|
||||
# Write C-file
|
||||
SchemaUtils.writeSchema(decls, schema, self.c_fname)
|
||||
|
||||
def dump(self):
|
||||
"""
|
||||
Save the validated schema
|
||||
"""
|
||||
if self.md != 'g':
|
||||
# convert the data dictionary to a string
|
||||
if self.valid:
|
||||
self.sys_schema = json.dumps(self.cfgschema, indent=4)
|
||||
#
|
||||
v_fname = 'valid_schema.json'
|
||||
msg = 'Saved validated schema to ' + v_fname
|
||||
else:
|
||||
v_fname = self.json_fname
|
||||
msg = 'Saved auto generated schema to ' + v_fname
|
||||
|
||||
with open(v_fname, 'w') as f:
|
||||
f.write(self.sys_schema)
|
||||
f.close()
|
||||
print(msg)
|
||||
|
||||
def validate(self):
|
||||
"""
|
||||
Check for errors in either instance or schema
|
||||
"""
|
||||
# Sample errors:
|
||||
# self.metaschema['definitions']['Subcomponent']['required'] = []
|
||||
# self.cfgschema[0]['name'] = []
|
||||
try:
|
||||
try:
|
||||
if (self.draft == 'd4') or (self.draft == 'd0'):
|
||||
js.Draft4Validator.check_schema(self.metaschema)
|
||||
else:
|
||||
# not supported until jsonschema 3.0
|
||||
js.Draft6Validator.check_schema(self.metaschema)
|
||||
print('Meta-schema OK')
|
||||
except js.SchemaError as e:
|
||||
print('Error in meta-schema:' + str(e))
|
||||
except Exception():
|
||||
raise
|
||||
|
||||
try:
|
||||
js.validate(self.cfgschema, self.metaschema)
|
||||
print('Configuration schema validated')
|
||||
except js.ValidationError as e:
|
||||
print('Error in schema configuration:' + str(e))
|
||||
except Exception():
|
||||
raise
|
||||
except Exception() as e:
|
||||
print(e)
|
||||
self.valid = False
|
||||
else:
|
||||
self.valid = True
|
||||
return self.valid
|
||||
|
||||
@staticmethod
|
||||
def declares(text):
|
||||
"""
|
||||
Select fields for which either a declaration or a prototype is necessary
|
||||
"""
|
||||
setA = set()
|
||||
setC = set()
|
||||
setP = set()
|
||||
for line in text.split('\n'):
|
||||
words = line.split()
|
||||
if 'driver_cfg' in line:
|
||||
setA.add(words[-1])
|
||||
if 'factory_config' in line:
|
||||
setC.add(words[-1])
|
||||
if 'null' not in line.lower():
|
||||
if 'preInitFxn' in line:
|
||||
setP.add(words[-1])
|
||||
if 'postInitFxn' in line:
|
||||
setP.add(words[-1])
|
||||
if 'cb_cmd' in line:
|
||||
setP.add(words[-1])
|
||||
|
||||
qual1 = 'SCHEMA_IMPORT DriverStruct '
|
||||
lines1 = [qual1 + value + ';' for value in iter(setA)]
|
||||
lines1.sort()
|
||||
str1 = '\n'.join(str(line) for line in lines1)
|
||||
|
||||
qual2 = 'SCHEMA_IMPORT const DriverStruct '
|
||||
lines2 = [qual2 + value + ';' for value in iter(setC)]
|
||||
lines2.sort()
|
||||
str2 = '\n'.join(str(line) for line in lines2)
|
||||
|
||||
qual3 = 'SCHEMA_IMPORT bool '
|
||||
qual4 = '(void *, void *)'
|
||||
lines3 = [qual3 + value + qual4 + ';' for value in iter(setP)]
|
||||
lines3.sort(key=str.lower)
|
||||
str3 = '\n'.join(str(line) for line in lines3)
|
||||
|
||||
decls = str1 + '\n\n' + str2 + '\n\n' + str3 + '\n\n'
|
||||
return decls
|
||||
|
||||
@staticmethod
|
||||
def strip(text):
|
||||
"""
|
||||
Remove JSON format features
|
||||
"""
|
||||
# Find and remove all double quotes
|
||||
p = re.compile(r'\"')
|
||||
result = p.sub('', text)
|
||||
|
||||
# Find and replace all colons
|
||||
result = re.sub(r':', ' =', result)
|
||||
|
||||
# Find and replace all commas
|
||||
result = re.sub(r',', '', result)
|
||||
|
||||
# Find values for which a declaration is required
|
||||
decls = SchemaUtils.declares(result)
|
||||
|
||||
# Format structure elements
|
||||
result = re.sub(r'name', '.name', result)
|
||||
result = re.sub(r'components', '.components', result)
|
||||
result = re.sub(r'\bdriver\b', '.driver', result)
|
||||
result = re.sub(r'\bdriver_cfg\b', '.driver_cfg', result)
|
||||
result = re.sub(r'factory_config', '.factory_config', result)
|
||||
result = re.sub(r'commands', '.commands', result)
|
||||
result = re.sub(r'ssHookSet', '.ssHookSet', result)
|
||||
result = re.sub(r'postDisabled', '.postDisabled', result)
|
||||
result = re.sub(r'cb_cmd', '.cb_cmd', result)
|
||||
result = re.sub(r'preInitFxn', '.preInitFxn', result)
|
||||
result = re.sub(r'postInitFxn', '.postInitFxn', result)
|
||||
return result, decls
|
||||
|
||||
@staticmethod
|
||||
def typeformat(text):
|
||||
"""
|
||||
Format each element type as required
|
||||
"""
|
||||
newschema = []
|
||||
for line in text.split('\n'):
|
||||
words = line.split()
|
||||
if '.name' in line:
|
||||
newline = line.replace(words[-1], '"' + words[-1] + '"')
|
||||
elif '.driver' in line:
|
||||
newline = line.replace(words[-1], '&' + words[-1])
|
||||
elif '.factory_config' in line:
|
||||
newline = line.replace(words[-1], '&' + words[-1])
|
||||
elif '.components' in line:
|
||||
newline = line.replace('[', '(Component[]) {')
|
||||
elif '.commands' in line:
|
||||
newline = line.replace('[', '(Command[]) {')
|
||||
elif '.ssHookSet' in line:
|
||||
newline = line.replace('{', '&(SSHookSet) {')
|
||||
elif '.preInitFxn' in line and 'NULL' not in line:
|
||||
newline = line.replace(words[-1], '(ssHook_Cb)' + words[-1])
|
||||
elif '.postInitFxn' in line and 'NULL' not in line:
|
||||
newline = line.replace(words[-1], '(ssHook_Cb)' + words[-1])
|
||||
elif ']' in line:
|
||||
n = line.find(']') + 4
|
||||
newschema.append(' ' * n + '{}')
|
||||
newline = line.replace(']', '}')
|
||||
else:
|
||||
newline = line
|
||||
|
||||
if '{' in newline:
|
||||
newschema.append(newline)
|
||||
else:
|
||||
newschema.append(newline + ',')
|
||||
|
||||
# Set first line correctly
|
||||
newschema[0] = 'const Component sys_schema[] = {'
|
||||
# Set last line correctly
|
||||
newschema[-1] = '};'
|
||||
|
||||
return '\n'.join(str(line) for line in newschema)
|
||||
|
||||
@staticmethod
|
||||
def writeSchema(decls, schema, c_fname):
|
||||
"""
|
||||
Save schema to .c file
|
||||
"""
|
||||
f = open(c_fname, 'w')
|
||||
cpw = []
|
||||
cpw.append('/**')
|
||||
cpw.append('* Copyright (c) 2018-present, Facebook, Inc.')
|
||||
cpw.append('* All rights reserved.')
|
||||
cpw.append('*')
|
||||
cpw.append('* This source code is licensed under the BSD-style license')
|
||||
cpw.append('* found in the LICENSE file in the root directory of this')
|
||||
cpw.append('* source tree. An additional grant of patent rights can be')
|
||||
cpw.append('* found in the PATENTS file in the same directory.')
|
||||
cpw.append('*')
|
||||
cpw.append('* WARNING: Do not modify this file by hand. It is auto')
|
||||
cpw.append('* generated from the json schema definition.')
|
||||
cpw.append('* Refer to sdtester.py')
|
||||
cpw.append('*/\n')
|
||||
cpw.append('#include "auto_schema.h"\n\n')
|
||||
f.write('\n'.join(line for line in cpw))
|
||||
f.write(decls)
|
||||
f.write('\n')
|
||||
f.write(schema)
|
||||
f.write('\n')
|
||||
f.close()
|
||||
print('Saved schema to ' + c_fname)
|
||||
|
||||
@staticmethod
|
||||
def stripC(text):
|
||||
"""
|
||||
Using regular expressions, strip schema struct from
|
||||
C-languange features
|
||||
"""
|
||||
# Find and remove C-style comments, single line and multiline
|
||||
p = re.compile(r'/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/')
|
||||
result = p.sub('', text)
|
||||
# Find and remove all dots
|
||||
result = re.sub(r'\.', '', result)
|
||||
# Find and remove all double quotes
|
||||
result = re.sub(r'\"', '', result)
|
||||
# Find and remove all commas
|
||||
result = re.sub(r',', '', result)
|
||||
# Find and replace all =
|
||||
result = re.sub(r'=', ' : ', result)
|
||||
# Find and remove all ampersands
|
||||
result = re.sub(r'&', '', result)
|
||||
# Find and remove all {}
|
||||
result = re.sub(r'{}', '', result)
|
||||
# Find and remove all semicolons
|
||||
result = re.sub(r';', '', result)
|
||||
# Find and remove all empty lines
|
||||
result = re.sub(r'\n\s*\n', '\n', result)
|
||||
# Find and remove all array declarations
|
||||
p = re.compile(r'\(\w*\[\]\)\s?\{')
|
||||
result = p.sub('[', result)
|
||||
# Find and remove all type casts
|
||||
p = re.compile(r'\(\w*\)')
|
||||
result = p.sub('', result)
|
||||
#
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def fixarray(text):
|
||||
"""
|
||||
Use a stack to find where array declarations should end
|
||||
"""
|
||||
opers = []
|
||||
schema = []
|
||||
for line in text.split('\n'):
|
||||
modline = line
|
||||
if '{' in line:
|
||||
opers.append('{')
|
||||
if '[' in line:
|
||||
opers.append('[')
|
||||
if '}' in line:
|
||||
if opers.pop() == '[':
|
||||
modline = line.replace('}', ']')
|
||||
schema.append(modline)
|
||||
|
||||
return '\n'.join(str(line) for line in schema)
|
||||
|
||||
@staticmethod
|
||||
def parse(text, ident):
|
||||
"""
|
||||
Apply indentation levels by parsing through schema
|
||||
"""
|
||||
tab = ident * ' '
|
||||
depth = 0
|
||||
schema = []
|
||||
for line in text.split('\n'):
|
||||
indent, depth = SchemaUtils.stack(line, depth)
|
||||
modline = SchemaUtils.fields(line)
|
||||
newline = indent * tab + modline
|
||||
schema.append(newline)
|
||||
|
||||
return '\n'.join(str(line) for line in schema)
|
||||
|
||||
@staticmethod
|
||||
def punct(text):
|
||||
"""
|
||||
JSON punctuation
|
||||
"""
|
||||
schema = []
|
||||
lines = text.split('\n')
|
||||
n = len(lines) - 1
|
||||
for i in range(n):
|
||||
# No comma in starting bracket or brace
|
||||
if ('{' in lines[i]) or ('[' in lines[i]):
|
||||
modline = lines[i]
|
||||
# Comma in objects, except last in a group
|
||||
elif (':' in lines[i]) and ('}' not in lines[i + 1]):
|
||||
modline = lines[i] + ','
|
||||
# No comma in a last array member
|
||||
elif ('}' in lines[i]) and \
|
||||
(('}' in lines[i + 1]) or (']' in lines[i + 1])):
|
||||
modline = lines[i]
|
||||
# Comma after object member of an array
|
||||
# Comma after array member of an object
|
||||
elif (('}' in lines[i]) or (']' in lines[i])) and \
|
||||
(('{' in lines[i + 1]) or ('[' in lines[i + 1]) or
|
||||
(':' in lines[i + 1])):
|
||||
modline = lines[i] + ','
|
||||
else:
|
||||
modline = lines[i]
|
||||
schema.append(modline)
|
||||
schema.append(lines[-1])
|
||||
return '\n'.join(str(line) for line in schema)
|
||||
|
||||
@staticmethod
|
||||
def stack(line, depth):
|
||||
"""
|
||||
Compute indentation level
|
||||
"""
|
||||
if ('{' in line) or ('[' in line):
|
||||
indent = depth
|
||||
depth += 1
|
||||
elif ('}' in line) or (']' in line):
|
||||
depth -= 1
|
||||
indent = depth
|
||||
else:
|
||||
depth = depth
|
||||
indent = depth
|
||||
return indent, depth
|
||||
|
||||
@staticmethod
|
||||
def fields(line):
|
||||
"""
|
||||
Apply JSON formatting to the keys and values
|
||||
"""
|
||||
modline = ''
|
||||
for word in line.split():
|
||||
modline = modline + SchemaUtils.compose(word)
|
||||
return modline
|
||||
|
||||
@staticmethod
|
||||
def compose(word):
|
||||
"""
|
||||
Correct use of quotes and spaces
|
||||
"""
|
||||
if SchemaUtils.wordOK(word):
|
||||
newword = '"' + word + '"'
|
||||
elif word == ':':
|
||||
newword = ' : '
|
||||
else:
|
||||
newword = word
|
||||
return newword
|
||||
|
||||
@staticmethod
|
||||
def wordOK(word):
|
||||
"""
|
||||
Check for non-words
|
||||
"""
|
||||
return word != '{' and word != '}' and \
|
||||
word != '[' and word != ']' and word != ':'
|
||||
116
firmware/utilities/schema/sdtester.py
Normal file
116
firmware/utilities/schema/sdtester.py
Normal file
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (c) 2018-present, Facebook, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the BSD-style license found in the
|
||||
# LICENSE file in the root directory of this source tree. An additional grant
|
||||
# of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
"""
|
||||
|
||||
Structured Data Tester
|
||||
|
||||
This module runs the schema utilities. Two use cases are supported:
|
||||
1. Given a JSON schema declaration, validate and generate the C-files
|
||||
2. Given a C-file with a schema declaration, generate the JSON schema
|
||||
|
||||
Example 1:
|
||||
Check the JSON schema declaration and generate the C-file
|
||||
required by the firmware and middleware
|
||||
$ python3 sdtester.py -j ../../ec/platform/oc-sdr/schema/sys_schema.json -c ../../ec/platform/oc-sdr/schema/auto_schema.c -d d4
|
||||
|
||||
Example 2:
|
||||
Same as previous example but with all defaults
|
||||
$ python3 sdtester.py
|
||||
|
||||
Example 3:
|
||||
Generate the JSON schema from a given C-file
|
||||
$ python3 sdtester.py -g -c ../../ec/platform/oc-sdr/schema/schema.c -j ../../ec/platform/oc-sdr/schema/sys_schema.json
|
||||
|
||||
Example 4:
|
||||
Same as previous example but with all defaults
|
||||
$ python3 sdtester.py -g
|
||||
|
||||
Example 5:
|
||||
Check that any arbitrary JSON schema declaration generates a C-file.
|
||||
Use d0 validation for development purposes
|
||||
$ python3 sdtester.py -j test_schema.json -c test_schema.c -d d0
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import schemautils as sc
|
||||
import argparse
|
||||
|
||||
|
||||
def useCases(md, json_fname, c_fname, draft):
|
||||
# Error check
|
||||
if not os.path.isfile(json_fname) and md != 'g':
|
||||
print('Missing source JSON file\n')
|
||||
sys.exit()
|
||||
elif not os.path.isfile(c_fname) and md == 'g':
|
||||
print('Missing source C-file\n')
|
||||
sys.exit()
|
||||
|
||||
if md != 'g':
|
||||
schema = sc.SchemaUtils('', json_fname, c_fname, draft)
|
||||
# Validate schema
|
||||
if not schema.validate():
|
||||
sys.exit()
|
||||
# Write the valid schema to disk
|
||||
schema.dump()
|
||||
# Generate auto_schema.c
|
||||
schema.auto_file()
|
||||
else:
|
||||
schema = sc.SchemaUtils('g', json_fname, c_fname, draft)
|
||||
schema.generate()
|
||||
schema.dump()
|
||||
|
||||
|
||||
def main(args):
|
||||
if args.generate:
|
||||
useCases('g', args.json_fname, args.c_fname, args.draft)
|
||||
else:
|
||||
useCases('', args.json_fname, args.c_fname, args.draft)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
# JSON Source file
|
||||
parser.add_argument(
|
||||
'-j',
|
||||
dest='json_fname',
|
||||
action='store',
|
||||
default='../../ec/platform/oc-sdr/schema/sys_schema.json',
|
||||
type=str,
|
||||
help='JSON file where configuration schema is declared',
|
||||
)
|
||||
# C-file name
|
||||
parser.add_argument(
|
||||
'-c',
|
||||
dest='c_fname',
|
||||
action='store',
|
||||
default='../../ec/platform/oc-sdr/schema/auto_schema.c',
|
||||
type=str,
|
||||
help='Name of C-file to be read from or written to',
|
||||
)
|
||||
# Draft version
|
||||
parser.add_argument(
|
||||
'-d',
|
||||
dest='draft',
|
||||
action='store',
|
||||
default='d4',
|
||||
type=str,
|
||||
help='JSON draft version, e.g. \'d4\' or \'d6\' for build; \'d0\' for general purpose',
|
||||
)
|
||||
# Schema source C-file to convert into JSON schema
|
||||
parser.add_argument(
|
||||
'-g',
|
||||
dest='generate',
|
||||
action='store_true',
|
||||
help='If specified, generates JSON schema from C-file',
|
||||
)
|
||||
|
||||
main(parser.parse_args())
|
||||
Reference in New Issue
Block a user