2022-07-27 01:42:14 -03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
script to determine what features have been built into an ArduPilot binary
|
|
|
|
|
|
|
|
AP_FLAKE8_CLEAN
|
|
|
|
"""
|
2023-02-03 17:09:32 -04:00
|
|
|
import argparse
|
2022-07-27 01:42:14 -03:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import string
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import time
|
2022-08-09 23:29:13 -03:00
|
|
|
import build_options
|
2023-02-10 10:26:17 -04:00
|
|
|
import select
|
2022-07-27 01:42:14 -03:00
|
|
|
|
|
|
|
|
|
|
|
if sys.version_info[0] < 3:
|
|
|
|
running_python3 = False
|
|
|
|
else:
|
|
|
|
running_python3 = True
|
|
|
|
|
|
|
|
|
|
|
|
class ExtractFeatures(object):
|
|
|
|
|
2023-10-24 08:01:10 -03:00
|
|
|
class FindString(object):
|
|
|
|
def __init__(self, string):
|
|
|
|
self.string = string
|
|
|
|
|
|
|
|
def __init__(self, filename, nm="arm-none-eabi-nm", strings="strings"):
|
2022-07-27 01:42:14 -03:00
|
|
|
self.filename = filename
|
2023-02-03 17:09:32 -04:00
|
|
|
self.nm = nm
|
2023-10-24 08:01:10 -03:00
|
|
|
self.strings = strings
|
2022-07-27 01:42:14 -03:00
|
|
|
|
2022-08-09 23:29:13 -03:00
|
|
|
# feature_name should match the equivalent feature in
|
|
|
|
# build_options.py ('FEATURE_NAME', 'EXPECTED_SYMBOL').
|
|
|
|
# EXPECTED_SYMBOL is a regular expression which will be matched
|
|
|
|
# against "define" in build_options's feature list, and
|
|
|
|
# FEATURE_NAME will have substitutions made from the match.
|
|
|
|
# the substitutions will be upper-cased
|
2022-07-27 01:42:14 -03:00
|
|
|
self.features = [
|
2023-09-16 22:49:20 -03:00
|
|
|
('AP_ADVANCEDFAILSAFE_ENABLED', r'AP_AdvancedFailsafe::heartbeat\b',),
|
2023-04-21 22:28:25 -03:00
|
|
|
('AP_BOOTLOADER_FLASHING_ENABLED', 'ChibiOS::Util::flash_bootloader',),
|
2022-08-09 23:29:13 -03:00
|
|
|
('AP_AIRSPEED_ENABLED', 'AP_Airspeed::AP_Airspeed',),
|
2022-07-31 10:29:16 -03:00
|
|
|
('AP_AIRSPEED_{type}_ENABLED', r'AP_Airspeed_(?P<type>.*)::init',),
|
|
|
|
|
2023-03-22 05:45:41 -03:00
|
|
|
('AC_PRECLAND_ENABLED', 'AC_PrecLand::AC_PrecLand',),
|
2023-03-27 08:07:27 -03:00
|
|
|
('AC_PRECLAND_ENABLED', 'AC_PrecLand::AC_PrecLand',),
|
|
|
|
('AC_PRECLAND_{type}_ENABLED', 'AC_PrecLand_(?P<type>.*)::update',),
|
2023-03-22 05:45:41 -03:00
|
|
|
|
2022-08-09 23:29:13 -03:00
|
|
|
('HAL_ADSB_ENABLED', 'AP_ADSB::AP_ADSB',),
|
2022-07-31 10:29:16 -03:00
|
|
|
('HAL_ADSB_{type}_ENABLED', r'AP_ADSB_(?P<type>.*)::update',),
|
|
|
|
('HAL_ADSB_UCP_ENABLED', 'AP_ADSB_uAvionix_UCP::update',),
|
2023-02-07 00:35:08 -04:00
|
|
|
|
|
|
|
('AP_COMPASS_{type}_ENABLED', r'AP_Compass_(?P<type>.*)::read\b',),
|
2023-03-10 18:18:05 -04:00
|
|
|
('AP_COMPASS_ICM20948_ENABLED', r'AP_Compass_AK09916::probe_ICM20948',),
|
2024-03-08 21:51:58 -04:00
|
|
|
('AP_COMPASS_DRONECAN_HIRES_ENABLED', r'AP_Compass_DroneCAN::handle_magnetic_field_hires',),
|
2023-02-07 00:35:08 -04:00
|
|
|
|
2022-07-31 10:29:16 -03:00
|
|
|
('AP_AIS_ENABLED', 'AP_AIS::AP_AIS',),
|
|
|
|
|
2022-08-09 23:29:13 -03:00
|
|
|
('HAL_EFI_ENABLED', 'AP_EFI::AP_EFI',),
|
2023-03-15 20:05:59 -03:00
|
|
|
('AP_EFI_{type}_ENABLED', 'AP_EFI_(?P<type>.*)::update',),
|
2023-02-08 19:49:44 -04:00
|
|
|
|
|
|
|
('AP_TEMPERATURE_SENSOR_ENABLED', 'AP_TemperatureSensor::AP_TemperatureSensor',),
|
|
|
|
('AP_TEMPERATURE_SENSOR_{type}_ENABLED', 'AP_TemperatureSensor_(?P<type>.*)::update',),
|
|
|
|
|
2023-04-09 04:39:19 -03:00
|
|
|
('AP_BEACON_ENABLED', 'AP_Beacon::AP_Beacon',),
|
2022-08-09 23:29:13 -03:00
|
|
|
('HAL_TORQEEDO_ENABLED', 'AP_Torqeedo::AP_Torqeedo'),
|
2022-07-31 10:29:16 -03:00
|
|
|
|
|
|
|
('HAL_NAVEKF3_AVAILABLE', 'NavEKF3::NavEKF3',),
|
|
|
|
('HAL_NAVEKF2_AVAILABLE', 'NavEKF2::NavEKF2',),
|
|
|
|
('HAL_EXTERNAL_AHRS_ENABLED', r'AP_ExternalAHRS::init\b',),
|
2023-04-24 06:54:51 -03:00
|
|
|
('AP_EXTERNAL_AHRS_{type}_ENABLED', r'AP_ExternalAHRS_{type}::healthy\b',),
|
2022-07-31 10:29:16 -03:00
|
|
|
('HAL_INS_TEMPERATURE_CAL_ENABLE', 'AP_InertialSensor::TCal::Learn::save_calibration',),
|
|
|
|
('HAL_VISUALODOM_ENABLED', 'AP_VisualOdom::init',),
|
|
|
|
|
|
|
|
('AP_RANGEFINDER_ENABLED', 'RangeFinder::RangeFinder',),
|
|
|
|
('AP_RANGEFINDER_{type}_ENABLED', r'AP_RangeFinder_(?P<type>.*)::update\b',),
|
2022-09-02 04:56:46 -03:00
|
|
|
('AP_RANGEFINDER_{type}_ENABLED', r'AP_RangeFinder_(?P<type>.*)::get_reading\b',),
|
|
|
|
('AP_RANGEFINDER_{type}_ENABLED', r'AP_RangeFinder_(?P<type>.*)::model_dist_max_cm\b',),
|
|
|
|
('AP_RANGEFINDER_LIGHTWARE_SERIAL_ENABLED', r'AP_RangeFinder_LightWareSerial::get_reading\b',),
|
|
|
|
('AP_RANGEFINDER_LWI2C_ENABLED', r'AP_RangeFinder_LightWareI2C::update\b',),
|
|
|
|
('AP_RANGEFINDER_MAXBOTIX_SERIAL_ENABLED', r'AP_RangeFinder_MaxsonarSerialLV::get_reading\b',),
|
|
|
|
('AP_RANGEFINDER_TRI2C_ENABLED', r'AP_RangeFinder_TeraRangerI2C::update\b',),
|
2023-10-26 04:55:55 -03:00
|
|
|
('AP_RANGEFINDER_JRE_SERIAL_ENABLED', r'AP_RangeFinder_JRE_Serial::get_reading\b',),
|
2023-05-09 21:04:45 -03:00
|
|
|
('AP_RANGEFINDER_RDS02UF_ENABLED', r'AP_RangeFinder_RDS02UF::get_reading\b',),
|
2022-07-31 10:29:16 -03:00
|
|
|
|
|
|
|
('AP_GPS_{type}_ENABLED', r'AP_GPS_(?P<type>.*)::read\b',),
|
|
|
|
|
2022-09-02 04:56:46 -03:00
|
|
|
('AP_OPTICALFLOW_ENABLED', 'AP_OpticalFlow::AP_OpticalFlow',),
|
2022-07-31 10:29:16 -03:00
|
|
|
('AP_OPTICALFLOW_{type}_ENABLED', r'AP_OpticalFlow_(?P<type>.*)::update\b',),
|
|
|
|
|
|
|
|
('AP_BARO_{type}_ENABLED', r'AP_Baro_(?P<type>.*)::update\b',),
|
|
|
|
|
|
|
|
('AP_MOTORS_FRAME_{type}_ENABLED', r'AP_MotorsMatrix::setup_(?P<type>.*)_matrix\b',),
|
|
|
|
|
|
|
|
('HAL_MSP_ENABLED', r'AP_MSP::init\b',),
|
|
|
|
('HAL_MSP_{type}_ENABLED', r'AP_(?P<type>.*)_MSP::update\b',),
|
|
|
|
('HAL_MSP_{type}_ENABLED', r'AP_(?P<type>.*)_MSP::read\b',),
|
|
|
|
('HAL_WITH_MSP_DISPLAYPORT', r'AP_OSD_MSP_DisplayPort::init\b',),
|
|
|
|
|
|
|
|
|
2023-03-06 22:02:49 -04:00
|
|
|
('AP_BATTERY_{type}_ENABLED', r'AP_BattMonitor_(?P<type>.*)::init\b',),
|
2023-08-21 20:56:16 -03:00
|
|
|
('AP_BATTERY_ESC_TELEM_OUTBOUND_ENABLED', r'AP_BattMonitor_Backend::update_esc_telem_outbound\b',),
|
2023-11-09 18:43:56 -04:00
|
|
|
('AP_BATTERY_WATT_MAX_ENABLED', 'AP_BattMonitor_Params::_watt_max',),
|
2022-07-31 10:29:16 -03:00
|
|
|
|
|
|
|
('HAL_MOUNT_ENABLED', 'AP_Mount::AP_Mount',),
|
|
|
|
('HAL_MOUNT_{type}_ENABLED', r'AP_Mount_(?P<type>.*)::update\b',),
|
|
|
|
('HAL_SOLO_GIMBAL_ENABLED', 'AP_Mount_SoloGimbal::init',),
|
|
|
|
('HAL_MOUNT_STORM32SERIAL_ENABLED', 'AP_Mount_SToRM32_serial::init',),
|
|
|
|
('HAL_MOUNT_STORM32MAVLINK_ENABLED', 'AP_Mount_SToRM32::init',),
|
|
|
|
|
|
|
|
('HAL_{type}_TELEM_ENABLED', r'AP_(?P<type>.*)_Telem::init',),
|
2024-01-12 22:50:16 -04:00
|
|
|
('AP_{type}_TELEM_ENABLED', r'AP_(?P<type>.*)_Telem::init',),
|
2022-07-31 10:29:16 -03:00
|
|
|
('HAL_CRSF_TELEM_TEXT_SELECTION_ENABLED', 'AP_CRSF_Telem::calc_text_selection',),
|
|
|
|
('AP_LTM_TELEM_ENABLED', 'AP_LTM_Telem::init',),
|
|
|
|
('HAL_HIGH_LATENCY2_ENABLED', 'GCS_MAVLINK::handle_control_high_latency',),
|
|
|
|
|
2023-02-08 19:49:44 -04:00
|
|
|
('AP_FRSKY_TELEM_ENABLED', 'AP::frsky_telem',),
|
|
|
|
('AP_FRSKY_D_TELEM_ENABLED', 'AP_Frsky_D::send',),
|
|
|
|
('AP_FRSKY_SPORT_TELEM_ENABLED', 'AP_Frsky_SPort::send_sport_frame',),
|
|
|
|
('AP_FRSKY_SPORT_PASSTHROUGH_ENABLED', 'AP::frsky_passthrough_telem',),
|
2024-07-25 00:06:28 -03:00
|
|
|
('HAL_WITH_FRSKY_TELEM_BIDIRECTIONAL', 'AP_Frsky_SPort_Passthrough::set_telem_data'),
|
2023-02-08 19:49:44 -04:00
|
|
|
|
2022-09-02 04:56:46 -03:00
|
|
|
('MODE_{type}_ENABLED', r'Mode(?P<type>.+)::init',),
|
|
|
|
('MODE_GUIDED_NOGPS_ENABLED', r'ModeGuidedNoGPS::init',),
|
2022-07-31 10:29:16 -03:00
|
|
|
|
2023-02-08 19:49:44 -04:00
|
|
|
('AP_CAMERA_ENABLED', 'AP_Camera::var_info',),
|
2023-03-17 21:16:20 -03:00
|
|
|
('AP_CAMERA_{type}_ENABLED', 'AP_Camera_(?P<type>.*)::trigger_pic',),
|
2023-09-20 23:38:18 -03:00
|
|
|
('AP_CAMERA_SEND_FOV_STATUS_ENABLED', 'AP_Camera::send_camera_fov_status'),
|
2022-07-31 10:29:16 -03:00
|
|
|
('HAL_RUNCAM_ENABLED', 'AP_RunCam::AP_RunCam',),
|
|
|
|
|
2023-04-06 10:18:18 -03:00
|
|
|
('HAL_PROXIMITY_ENABLED', 'AP_Proximity::AP_Proximity',),
|
|
|
|
('AP_PROXIMITY_{type}_ENABLED', 'AP_Proximity_(?P<type>.*)::update',),
|
|
|
|
('AP_PROXIMITY_CYGBOT_ENABLED', 'AP_Proximity_Cygbot_D1::update',),
|
|
|
|
('AP_PROXIMITY_LIGHTWARE_{type}_ENABLED', 'AP_Proximity_LightWare(?P<type>.*)::update',),
|
|
|
|
|
2022-07-31 10:29:16 -03:00
|
|
|
('HAL_PARACHUTE_ENABLED', 'AP_Parachute::update',),
|
|
|
|
('AP_FENCE_ENABLED', r'AC_Fence::check\b',),
|
2023-08-18 02:01:47 -03:00
|
|
|
('HAL_RALLY_ENABLED', r'AP_Rally::get_rally_max\b',),
|
2024-03-08 22:35:26 -04:00
|
|
|
('AP_AVOIDANCE_ENABLED', 'AC_Avoid::AC_Avoid',),
|
|
|
|
('AP_OAPATHPLANNER_ENABLED', 'AP_OAPathPlanner::AP_OAPathPlanner',),
|
2023-10-23 23:59:37 -03:00
|
|
|
('AC_PAYLOAD_PLACE_ENABLED', 'PayloadPlace::start_descent'),
|
2023-10-24 08:01:10 -03:00
|
|
|
('AP_MISSION_NAV_PAYLOAD_PLACE_ENABLED', ExtractFeatures.FindString('PayloadPlace')),
|
2022-07-31 10:29:16 -03:00
|
|
|
('AP_ICENGINE_ENABLED', 'AP_ICEngine::AP_ICEngine',),
|
|
|
|
('HAL_EFI_ENABLED', 'AP_RPM_EFI::AP_RPM_EFI',),
|
2023-03-15 20:05:59 -03:00
|
|
|
('AP_EFI_NWPWU_ENABLED', r'AP_EFI_NWPMU::update\b',),
|
|
|
|
('AP_EFI_CURRAWONG_ECU_ENABLED', r'AP_EFI_Currawong_ECU::update\b',),
|
2023-11-13 01:23:04 -04:00
|
|
|
('AP_EFI_SERIAL_HIRTH_ENABLED', r'AP_EFI_Serial_Hirth::update\b',),
|
2022-07-31 10:29:16 -03:00
|
|
|
('HAL_GENERATOR_ENABLED', 'AP_Generator::AP_Generator',),
|
2023-08-14 01:09:34 -03:00
|
|
|
('AP_GENERATOR_{type}_ENABLED', r'AP_Generator_(?P<type>.*)::init',),
|
2022-07-31 10:29:16 -03:00
|
|
|
|
2023-04-06 10:34:40 -03:00
|
|
|
('OSD_ENABLED', 'AP_OSD::update_osd',),
|
2022-07-31 10:29:16 -03:00
|
|
|
('HAL_PLUSCODE_ENABLE', 'AP_OSD_Screen::draw_pluscode',),
|
|
|
|
('OSD_PARAM_ENABLED', 'AP_OSD_ParamScreen::AP_OSD_ParamScreen',),
|
|
|
|
('HAL_OSD_SIDEBAR_ENABLE', 'AP_OSD_Screen::draw_sidebars',),
|
|
|
|
|
2023-02-07 04:18:07 -04:00
|
|
|
('AP_VIDEOTX_ENABLED', 'AP_VideoTX::AP_VideoTX',),
|
2023-01-19 15:55:36 -04:00
|
|
|
('AP_SMARTAUDIO_ENABLED', 'AP_SmartAudio::AP_SmartAudio',),
|
2022-07-31 10:29:16 -03:00
|
|
|
('AP_TRAMP_ENABLED', 'AP_Tramp::AP_Tramp',),
|
|
|
|
|
2023-10-02 11:22:57 -03:00
|
|
|
('AP_CHECK_FIRMWARE_ENABLED', 'AP_CheckFirmware::check_signed_bootloader',),
|
|
|
|
|
2022-07-31 10:29:16 -03:00
|
|
|
('HAL_QUADPLANE_ENABLED', 'QuadPlane::QuadPlane',),
|
2022-11-19 17:55:13 -04:00
|
|
|
('QAUTOTUNE_ENABLED', 'ModeQAutotune::_enter',),
|
2022-07-31 10:29:16 -03:00
|
|
|
('HAL_SOARING_ENABLED', 'SoaringController::var_info',),
|
|
|
|
('HAL_LANDING_DEEPSTALL_ENABLED', r'AP_Landing_Deepstall::terminate\b',),
|
|
|
|
|
2022-09-20 04:37:48 -03:00
|
|
|
('AP_GRIPPER_ENABLED', r'AP_Gripper::init\b',),
|
2022-07-31 10:29:16 -03:00
|
|
|
('HAL_SPRAYER_ENABLED', 'AC_Sprayer::AC_Sprayer',),
|
2022-10-01 07:21:38 -03:00
|
|
|
('AP_LANDINGGEAR_ENABLED', r'AP_LandingGear::init\b',),
|
2023-04-09 03:45:04 -03:00
|
|
|
('AP_WINCH_ENABLED', 'AP_Winch::AP_Winch',),
|
2023-10-01 18:43:19 -03:00
|
|
|
('AP_WINCH_{type}_ENABLED', r'AP_Winch_(?P<type>.*)::update\b',),
|
2023-06-09 22:02:09 -03:00
|
|
|
('AP_RELAY_ENABLED', 'AP_Relay::init',),
|
|
|
|
('AP_SERVORELAYEVENTS_ENABLED', 'AP_ServoRelayEvents::update_events',),
|
2022-07-31 10:29:16 -03:00
|
|
|
|
2023-05-03 10:08:00 -03:00
|
|
|
('AP_RCPROTOCOL_ENABLED', r'AP_RCProtocol::init\b',),
|
2023-03-14 08:18:29 -03:00
|
|
|
('AP_RCPROTOCOL_{type}_ENABLED', r'AP_RCProtocol_(?P<type>.*)::_process_byte\b',),
|
|
|
|
('AP_RCPROTOCOL_{type}_ENABLED', r'AP_RCProtocol_(?P<type>.*)::_process_pulse\b',),
|
|
|
|
|
2022-07-31 10:29:16 -03:00
|
|
|
('AP_VOLZ_ENABLED', r'AP_Volz_Protocol::init\b',),
|
2023-04-06 21:18:02 -03:00
|
|
|
('AP_DRONECAN_VOLZ_FEEDBACK_ENABLED', r'AP_DroneCAN::handle_actuator_status_Volz\b',),
|
2022-07-31 10:29:16 -03:00
|
|
|
('AP_ROBOTISSERVO_ENABLED', r'AP_RobotisServo::init\b',),
|
|
|
|
('AP_FETTEC_ONEWIRE_ENABLED', r'AP_FETtecOneWire::init\b',),
|
2023-06-15 05:52:08 -03:00
|
|
|
('AP_SBUSOUTPUT_ENABLED', 'AP_SBusOut::sbus_format_frame',),
|
2023-03-23 20:34:29 -03:00
|
|
|
('AP_KDECAN_ENABLED', r'AP_KDECAN::update\b',),
|
2022-07-31 10:29:16 -03:00
|
|
|
|
2022-09-20 18:46:57 -03:00
|
|
|
('AP_RPM_ENABLED', 'AP_RPM::AP_RPM',),
|
2023-02-08 19:49:44 -04:00
|
|
|
('AP_RPM_{type}_ENABLED', r'AP_RPM_(?P<type>.*)::update',),
|
2022-07-31 10:29:16 -03:00
|
|
|
|
2023-10-02 11:22:57 -03:00
|
|
|
('AP_OPENDRONEID_ENABLED', 'AP_OpenDroneID::update',),
|
|
|
|
|
2022-07-31 10:29:16 -03:00
|
|
|
('GPS_MOVING_BASELINE', r'AP_GPS_Backend::calculate_moving_base_yaw\b',),
|
2023-04-08 01:09:11 -03:00
|
|
|
('AP_DRONECAN_SEND_GPS', r'AP_GPS_DroneCAN::instance_exists\b',),
|
2024-05-04 09:02:57 -03:00
|
|
|
('AP_GPS_BLENDED_ENABLED', r'AP_GPS::calc_blend_weights\b',),
|
2022-07-31 10:29:16 -03:00
|
|
|
|
|
|
|
('HAL_WITH_DSP', r'AP_HAL::DSP::find_peaks\b',),
|
2024-02-12 20:26:08 -04:00
|
|
|
('AP_INERTIALSENSOR_HARMONICNOTCH_ENABLED', r'AP_InertialSensor::HarmonicNotch::update_params\b',),
|
2022-10-26 02:10:31 -03:00
|
|
|
('HAL_GYROFFT_ENABLED', r'AP_GyroFFT::AP_GyroFFT\b',),
|
2022-07-31 10:29:16 -03:00
|
|
|
('HAL_DISPLAY_ENABLED', r'Display::init\b',),
|
|
|
|
('HAL_NMEA_OUTPUT_ENABLED', r'AP_NMEA_Output::update\b',),
|
|
|
|
('HAL_BARO_WIND_COMP_ENABLED', r'AP_Baro::wind_pressure_correction\b',),
|
2023-11-02 22:58:01 -03:00
|
|
|
('AP_TEMPCALIBRATION_ENABLED', r'AP_TempCalibration::apply_calibration',),
|
2022-07-31 10:29:16 -03:00
|
|
|
|
2022-09-02 04:56:46 -03:00
|
|
|
('HAL_PICCOLO_CAN_ENABLE', r'AP_PiccoloCAN::update',),
|
|
|
|
('EK3_FEATURE_EXTERNAL_NAV', r'NavEKF3::writeExtNavVelData'),
|
2023-03-14 01:24:56 -03:00
|
|
|
('EK3_FEATURE_DRAG_FUSION', r'NavEKF3_core::FuseDragForces'),
|
2023-02-08 19:49:44 -04:00
|
|
|
|
|
|
|
('AP_RC_CHANNEL_AUX_FUNCTION_STRINGS_ENABLED', r'RC_Channel::lookuptable',),
|
2023-06-07 03:29:44 -03:00
|
|
|
('AP_SCRIPTING_ENABLED', r'AP_Scripting::init',),
|
2024-06-17 23:55:20 -03:00
|
|
|
('AP_SCRIPTING_SERIALDEVICE_ENABLED', r'AP_Scripting_SerialDevice::init',),
|
2023-02-08 19:49:44 -04:00
|
|
|
|
2023-04-20 22:35:37 -03:00
|
|
|
('AP_NOTIFY_TONEALARM_ENABLED', r'AP_ToneAlarm::init'),
|
2023-04-12 04:41:20 -03:00
|
|
|
('AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED', r'AP_Notify::handle_play_tune'),
|
2023-02-28 23:50:36 -04:00
|
|
|
('AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED', r'AP_Notify::handle_led_control'),
|
|
|
|
('AP_NOTIFY_NCP5623_ENABLED', r'NCP5623::write'),
|
|
|
|
('AP_NOTIFY_PROFILED_ENABLED', r'ProfiLED::init_ports'),
|
|
|
|
('AP_NOTIFY_PROFILED_SPI_ENABLED', r'ProfiLED_SPI::rgb_set_id'),
|
|
|
|
('AP_NOTIFY_NEOPIXEL_ENABLED', r'NeoPixel::init_ports'),
|
2023-06-06 23:44:21 -03:00
|
|
|
('AP_FILESYSTEM_FORMAT_ENABLED', r'AP_Filesystem::format'),
|
2023-06-05 23:12:12 -03:00
|
|
|
|
2023-06-13 20:54:51 -03:00
|
|
|
('AP_FILESYSTEM_{type}_ENABLED', r'AP_Filesystem_(?P<type>.*)::open'),
|
|
|
|
|
2023-06-05 23:12:12 -03:00
|
|
|
('AP_INERTIALSENSOR_KILL_IMU_ENABLED', r'AP_InertialSensor::kill_imu'),
|
2023-06-13 22:00:43 -03:00
|
|
|
('AP_CRASHDUMP_ENABLED', 'CrashCatcher_DumpMemory'),
|
2023-07-31 00:38:45 -03:00
|
|
|
('AP_CAN_SLCAN_ENABLED', 'SLCAN::CANIface::var_info'),
|
2023-08-07 02:38:55 -03:00
|
|
|
('AC_POLYFENCE_FENCE_POINT_PROTOCOL_SUPPORT', 'AC_PolyFence_loader::handle_msg_fetch_fence_point'),
|
2023-08-09 05:49:16 -03:00
|
|
|
('AP_MAVLINK_RALLY_POINT_PROTOCOL_ENABLED', 'GCS_MAVLINK::handle_common_rally_message'),
|
2023-08-19 17:33:10 -03:00
|
|
|
|
|
|
|
('AP_SDCARD_STORAGE_ENABLED', 'StorageAccess::attach_file'),
|
2023-08-18 02:01:47 -03:00
|
|
|
('AP_MAVLINK_AUTOPILOT_VERSION_REQUEST_ENABLED', 'GCS_MAVLINK::handle_send_autopilot_version'),
|
|
|
|
('AP_MAVLINK_MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES_ENABLED', 'GCS_MAVLINK::handle_command_request_autopilot_capabilities'), # noqa
|
|
|
|
('AP_MAVLINK_MSG_RELAY_STATUS_ENABLED', 'GCS_MAVLINK::send_relay_status'),
|
|
|
|
('AP_MAVLINK_BATTERY2_ENABLED', 'GCS_MAVLINK::send_battery2'),
|
2023-08-23 21:10:29 -03:00
|
|
|
('AP_MAVLINK_MSG_MOUNT_CONTROL_ENABLED', 'AP_Mount::handle_mount_control'),
|
|
|
|
('AP_MAVLINK_MSG_MOUNT_CONFIGURE_ENABLED', 'AP_Mount::handle_mount_configure'),
|
2023-09-01 10:13:54 -03:00
|
|
|
('AP_MAVLINK_MSG_DEVICE_OP_ENABLED', 'GCS_MAVLINK::handle_device_op_write'),
|
|
|
|
('AP_MAVLINK_SERVO_RELAY_ENABLED', 'GCS_MAVLINK::handle_servorelay_message'),
|
|
|
|
('AP_MAVLINK_MSG_SERIAL_CONTROL_ENABLED', 'GCS_MAVLINK::handle_serial_control'),
|
2023-10-12 03:35:00 -03:00
|
|
|
('AP_MAVLINK_MSG_MISSION_REQUEST_ENABLED', 'GCS_MAVLINK::handle_mission_request\b'),
|
2024-02-28 22:37:25 -04:00
|
|
|
('AP_MAVLINK_FTP_ENABLED', 'GCS_MAVLINK::ftp_worker'),
|
2024-07-16 19:42:53 -03:00
|
|
|
('AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED', 'Plane::get_external_HAGL'),
|
2024-02-28 22:37:25 -04:00
|
|
|
|
2023-09-02 03:37:56 -03:00
|
|
|
('AP_DRONECAN_HIMARK_SERVO_SUPPORT', 'AP_DroneCAN::SRV_send_himark'),
|
|
|
|
('AP_DRONECAN_HOBBYWING_ESC_SUPPORT', 'AP_DroneCAN::hobbywing_ESC_update'),
|
2023-09-18 10:07:43 -03:00
|
|
|
('COMPASS_CAL_ENABLED', 'CompassCalibrator::stop'),
|
2023-09-19 06:52:03 -03:00
|
|
|
('AP_TUNING_ENABLED', 'AP_Tuning::check_input'),
|
2023-11-18 17:34:59 -04:00
|
|
|
('AP_DRONECAN_SERIAL_ENABLED', 'AP_DroneCAN_Serial::update'),
|
2023-11-27 23:47:51 -04:00
|
|
|
('AP_SERIALMANAGER_IMUOUT_ENABLED', 'AP_InertialSensor::send_uart_data'),
|
2023-12-26 04:04:43 -04:00
|
|
|
('AP_NETWORKING_BACKEND_PPP', 'AP_Networking_PPP::init'),
|
2024-01-16 22:11:52 -04:00
|
|
|
('FORCE_APJ_DEFAULT_PARAMETERS', 'AP_Param::param_defaults_data'),
|
2024-01-17 23:55:12 -04:00
|
|
|
('HAL_BUTTON_ENABLED', 'AP_Button::update'),
|
2024-03-06 21:14:17 -04:00
|
|
|
('HAL_LOGGING_ENABLED', 'AP_Logger::init'),
|
2024-02-01 20:45:34 -04:00
|
|
|
('AP_COMPASS_CALIBRATION_FIXED_YAW_ENABLED', 'AP_Compass::mag_cal_fixed_yaw'),
|
|
|
|
('COMPASS_LEARN_ENABLED', 'CompassLearn::update'),
|
2024-02-29 00:39:18 -04:00
|
|
|
('AP_CUSTOMROTATIONS_ENABLED', 'AP_CustomRotation::init'),
|
2024-03-27 17:40:03 -03:00
|
|
|
('AP_OSD_LINK_STATS_EXTENSIONS_ENABLED', r'AP_OSD_Screen::draw_rc_tx_power'),
|
2024-04-10 02:09:47 -03:00
|
|
|
('HAL_ENABLE_DRONECAN_DRIVERS', r'AP_DroneCAN::init'),
|
2024-05-21 07:13:40 -03:00
|
|
|
('AP_MAVLINK_MSG_HIL_GPS_ENABLED', r'mavlink_msg_hil_gps_decode'),
|
2024-07-10 00:54:14 -03:00
|
|
|
('AP_BARO_PROBE_EXTERNAL_I2C_BUSES', r'AP_Compass::_probe_external_i2c_compasses'),
|
2024-07-23 08:54:46 -03:00
|
|
|
('AP_RSSI_ENABLED', r'AP_RSSI::init'),
|
2022-07-27 01:42:14 -03:00
|
|
|
]
|
|
|
|
|
2023-02-03 17:09:32 -04:00
|
|
|
def progress(self, msg):
|
|
|
|
"""Pretty-print progress."""
|
|
|
|
print("EF: %s" % msg)
|
2022-07-27 01:42:14 -03:00
|
|
|
|
2023-02-08 19:49:44 -04:00
|
|
|
def validate_features_list(self):
|
|
|
|
'''ensures that every define present in build_options.py could be
|
|
|
|
found by in our features list'''
|
|
|
|
# a list of problematic defines we don't have fixes for ATM:
|
|
|
|
whitelist = frozenset([
|
|
|
|
'HAL_PERIPH_SUPPORT_LONG_CAN_PRINTF', # this define changes single method body, hard to detect?
|
2023-05-17 00:09:23 -03:00
|
|
|
'AP_PLANE_BLACKBOX_LOGGING', # no visible signature
|
2023-02-08 19:49:44 -04:00
|
|
|
])
|
|
|
|
for option in build_options.BUILD_OPTIONS:
|
|
|
|
if option.define in whitelist:
|
|
|
|
continue
|
|
|
|
matched = False
|
|
|
|
for (define, _) in self.features:
|
|
|
|
# replace {type} with "match any number of word characters'''
|
|
|
|
define_re = "^" + re.sub(r"{type}", "\\\\w+", define) + "$"
|
|
|
|
# print("define re is (%s)" % define_re)
|
|
|
|
if re.match(define_re, option.define):
|
|
|
|
matched = True
|
|
|
|
break
|
|
|
|
if not matched:
|
|
|
|
raise ValueError("feature (%s) is not matched in extract_features" %
|
|
|
|
(option.define))
|
|
|
|
|
2022-07-27 01:42:14 -03:00
|
|
|
def run_program(self, prefix, cmd_list, show_output=True, env=None):
|
2023-02-03 17:09:32 -04:00
|
|
|
"""Swiped from build_binaries.py."""
|
2022-07-27 01:42:14 -03:00
|
|
|
if show_output:
|
|
|
|
self.progress("Running (%s)" % " ".join(cmd_list))
|
2022-10-05 21:51:11 -03:00
|
|
|
p = subprocess.Popen(
|
|
|
|
cmd_list,
|
|
|
|
stdin=None,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
close_fds=True,
|
2023-02-10 10:26:17 -04:00
|
|
|
stderr=subprocess.PIPE,
|
2022-10-05 21:51:11 -03:00
|
|
|
env=env)
|
2023-02-10 10:26:17 -04:00
|
|
|
stderr = bytearray()
|
2022-07-27 01:42:14 -03:00
|
|
|
output = ""
|
|
|
|
while True:
|
2023-02-10 10:26:17 -04:00
|
|
|
# read all of stderr:
|
|
|
|
while True:
|
|
|
|
(rin, _, _) = select.select([p.stderr.fileno()], [], [], 0)
|
|
|
|
if p.stderr.fileno() not in rin:
|
|
|
|
break
|
|
|
|
new = p.stderr.read()
|
|
|
|
if len(new) == 0:
|
|
|
|
break
|
|
|
|
stderr += new
|
|
|
|
|
2022-07-27 01:42:14 -03:00
|
|
|
x = p.stdout.readline()
|
|
|
|
if len(x) == 0:
|
2023-02-10 10:26:17 -04:00
|
|
|
(rin, _, _) = select.select([p.stderr.fileno()], [], [], 0)
|
|
|
|
if p.stderr.fileno() in rin:
|
|
|
|
stderr += p.stderr.read()
|
|
|
|
|
2022-07-27 01:42:14 -03:00
|
|
|
returncode = os.waitpid(p.pid, 0)
|
|
|
|
if returncode:
|
|
|
|
break
|
|
|
|
# select not available on Windows... probably...
|
|
|
|
time.sleep(0.1)
|
|
|
|
continue
|
|
|
|
if running_python3:
|
|
|
|
x = bytearray(x)
|
2023-02-03 17:09:32 -04:00
|
|
|
x = filter(lambda x: chr(x) in string.printable, x)
|
2022-07-27 01:42:14 -03:00
|
|
|
x = "".join([chr(c) for c in x])
|
|
|
|
output += x
|
|
|
|
x = x.rstrip()
|
|
|
|
if show_output:
|
|
|
|
print("%s: %s" % (prefix, x))
|
|
|
|
(_, status) = returncode
|
2023-02-08 19:49:44 -04:00
|
|
|
if status != 0:
|
2023-02-10 10:26:17 -04:00
|
|
|
stderr = stderr.decode('utf-8')
|
|
|
|
self.progress("Process failed (%s) (%s)" %
|
|
|
|
(str(returncode), stderr))
|
2022-07-27 01:42:14 -03:00
|
|
|
raise subprocess.CalledProcessError(
|
2023-02-10 10:26:17 -04:00
|
|
|
status, cmd_list, output=str(output), stderr=str(stderr))
|
2022-07-27 01:42:14 -03:00
|
|
|
return output
|
|
|
|
|
|
|
|
class Symbols(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.symbols = dict()
|
|
|
|
self.symbols_without_arguments = dict()
|
|
|
|
|
|
|
|
def add(self, key, attributes):
|
|
|
|
self.symbols[key] = attributes
|
|
|
|
|
|
|
|
# also keep around the same symbol name without arguments.
|
|
|
|
# if the key is already present then the attributes become
|
|
|
|
# None as there are multiple possible answers...
|
|
|
|
m = re.match("^([^(]+).*", key)
|
|
|
|
if m is None:
|
|
|
|
extracted_symbol_name = key
|
|
|
|
else:
|
|
|
|
extracted_symbol_name = m.group(1)
|
|
|
|
# print("Adding (%s)" % str(extracted_symbol_name))
|
|
|
|
if extracted_symbol_name in self.symbols_without_arguments:
|
|
|
|
self.symbols_without_arguments[extracted_symbol_name] = None
|
|
|
|
else:
|
|
|
|
self.symbols_without_arguments[extracted_symbol_name] = attributes
|
|
|
|
|
2022-08-09 23:29:13 -03:00
|
|
|
def dict_for_symbol(self, symbol):
|
|
|
|
if '(' not in symbol:
|
|
|
|
some_dict = self.symbols_without_arguments
|
|
|
|
else:
|
|
|
|
some_dict = self.symbols
|
|
|
|
return some_dict
|
2022-07-27 01:42:14 -03:00
|
|
|
|
|
|
|
def extract_symbols_from_elf(self, filename):
|
2023-02-03 17:09:32 -04:00
|
|
|
"""Parses ELF in filename, returns dict of symbols=>attributes."""
|
2022-07-27 01:42:14 -03:00
|
|
|
text_output = self.run_program('EF', [
|
|
|
|
self.nm,
|
|
|
|
'--demangle',
|
|
|
|
'--print-size',
|
|
|
|
filename
|
|
|
|
], show_output=False)
|
|
|
|
ret = ExtractFeatures.Symbols()
|
|
|
|
for line in text_output.split("\n"):
|
|
|
|
m = re.match("^([^ ]+) ([^ ]+) ([^ ]) (.*)", line.rstrip())
|
|
|
|
if m is None:
|
|
|
|
m = re.match("^([^ ]+) ([^ ]) (.*)", line.rstrip())
|
|
|
|
if m is None:
|
|
|
|
# raise ValueError("Did not match (%s)" % line)
|
|
|
|
# e.g. Did not match ( U _errno)
|
|
|
|
continue
|
|
|
|
(offset, symbol_type, symbol_name) = m.groups()
|
|
|
|
size = "0"
|
|
|
|
else:
|
|
|
|
(offset, size, symbol_type, symbol_name) = m.groups()
|
|
|
|
size = int(size, 16)
|
|
|
|
# print("symbol (%s) size %u" % (str(symbol_name), size))
|
|
|
|
ret.add(symbol_name, {
|
|
|
|
"size": size,
|
|
|
|
})
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
2023-10-24 08:01:10 -03:00
|
|
|
def extract_strings_from_elf(self, filename):
|
|
|
|
"""Runs strings on filename, returns as a list"""
|
|
|
|
text_output = self.run_program('EF', [
|
|
|
|
self.strings,
|
|
|
|
filename
|
|
|
|
], show_output=False)
|
|
|
|
return text_output.split("\n")
|
|
|
|
|
2023-04-07 23:48:40 -03:00
|
|
|
def extract(self):
|
|
|
|
'''returns two sets - compiled_in and not_compiled_in'''
|
2022-07-27 01:42:14 -03:00
|
|
|
|
2022-08-09 23:29:13 -03:00
|
|
|
build_options_defines = set([x.define for x in build_options.BUILD_OPTIONS])
|
2022-07-27 01:42:14 -03:00
|
|
|
|
2022-09-02 05:35:38 -03:00
|
|
|
symbols = self.extract_symbols_from_elf(self.filename)
|
2023-10-24 08:01:10 -03:00
|
|
|
strings = self.extract_strings_from_elf(self.filename)
|
2022-07-27 01:42:14 -03:00
|
|
|
|
2022-09-02 04:56:15 -03:00
|
|
|
remaining_build_options_defines = build_options_defines
|
2022-09-02 05:35:38 -03:00
|
|
|
compiled_in_feature_defines = []
|
2022-08-09 23:29:13 -03:00
|
|
|
for (feature_define, symbol) in self.features:
|
2023-10-24 08:01:10 -03:00
|
|
|
if isinstance(symbol, ExtractFeatures.FindString):
|
|
|
|
if symbol.string in strings:
|
|
|
|
some_define = feature_define
|
|
|
|
if some_define not in build_options_defines:
|
|
|
|
continue
|
|
|
|
compiled_in_feature_defines.append(some_define)
|
|
|
|
remaining_build_options_defines.discard(some_define)
|
|
|
|
else:
|
|
|
|
some_dict = symbols.dict_for_symbol(symbol)
|
|
|
|
# look for symbols without arguments
|
|
|
|
# print("Looking for (%s)" % str(name))
|
|
|
|
for s in some_dict.keys():
|
|
|
|
m = re.match(symbol, s)
|
|
|
|
# print("matching %s with %s" % (symbol, s))
|
|
|
|
if m is None:
|
|
|
|
continue
|
|
|
|
d = m.groupdict()
|
|
|
|
for key in d.keys():
|
|
|
|
d[key] = d[key].upper()
|
|
|
|
# filter to just the defines present in
|
|
|
|
# build_options.py - otherwise we end up with (e.g.)
|
|
|
|
# AP_AIRSPEED_BACKEND_ENABLED, even 'though that
|
|
|
|
# doesn't exist in the ArduPilot codebase.
|
|
|
|
some_define = feature_define.format(**d)
|
|
|
|
if some_define not in build_options_defines:
|
|
|
|
continue
|
|
|
|
compiled_in_feature_defines.append(some_define)
|
|
|
|
remaining_build_options_defines.discard(some_define)
|
2023-04-07 23:48:40 -03:00
|
|
|
return (compiled_in_feature_defines, remaining_build_options_defines)
|
|
|
|
|
|
|
|
def create_string(self):
|
|
|
|
'''returns a string with compiled in and not compiled-in features'''
|
|
|
|
|
|
|
|
(compiled_in_feature_defines, not_compiled_in_feature_defines) = self.extract()
|
|
|
|
|
|
|
|
ret = ""
|
2022-09-02 05:35:38 -03:00
|
|
|
|
2023-07-30 23:38:34 -03:00
|
|
|
combined = {}
|
|
|
|
for define in sorted(compiled_in_feature_defines):
|
|
|
|
combined[define] = True
|
|
|
|
for define in sorted(not_compiled_in_feature_defines):
|
|
|
|
combined[define] = False
|
|
|
|
|
|
|
|
def squash_hal_to_ap(a):
|
|
|
|
return re.sub("^HAL_", "AP_", a)
|
|
|
|
|
|
|
|
for define in sorted(combined.keys(), key=squash_hal_to_ap):
|
|
|
|
bang = ""
|
|
|
|
if not combined[define]:
|
|
|
|
bang = "!"
|
|
|
|
ret += bang + define + "\n"
|
2022-09-02 05:35:38 -03:00
|
|
|
return ret
|
|
|
|
|
|
|
|
def run(self):
|
2023-02-08 19:49:44 -04:00
|
|
|
self.validate_features_list()
|
2022-09-02 05:35:38 -03:00
|
|
|
print(self.create_string())
|
2022-07-27 01:42:14 -03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
2023-02-03 17:09:32 -04:00
|
|
|
parser = argparse.ArgumentParser(prog='extract_features.py', description='Extract ArduPilot features from binaries')
|
|
|
|
parser.add_argument('firmware_file', help='firmware binary')
|
|
|
|
parser.add_argument('-nm', type=str, default="arm-none-eabi-nm", help='nm binary to use.')
|
|
|
|
args = parser.parse_args()
|
2023-02-07 00:28:07 -04:00
|
|
|
# print(args.firmware_file, args.nm)
|
2022-07-27 01:42:14 -03:00
|
|
|
|
2023-02-03 17:09:32 -04:00
|
|
|
ef = ExtractFeatures(args.firmware_file, args.nm)
|
2022-07-27 01:42:14 -03:00
|
|
|
ef.run()
|