aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/utils/compat_check.cpp
blob: aebf6e6bf3eac70f5bbcf536ea3e8f1d705eaa3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// Copyright 2018 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: GPL-3.0
//

#include <uhd/exception.hpp>
#include <uhd/utils/log.hpp>
#include <uhdlib/utils/compat_check.hpp>
#include <boost/format.hpp>

void uhd::assert_fpga_compat(
    const size_t uhd_major,
    const size_t uhd_minor,
    const uint64_t fpga_compat,
    const std::string& fpga_component,
    const std::string& log_component,
    const bool fail_on_minor_behind
) {
    const size_t fpga_major = fpga_compat >> 32;
    const size_t fpga_minor = fpga_compat & 0xFFFFFFFF;

    if (!log_component.empty()) {
        UHD_LOGGER_DEBUG(log_component)
            << "Checking compat number for FPGA component `" << fpga_component
            << "': Expecting " << uhd_major << "." << uhd_minor << ", actual: "
            << fpga_major << "." << fpga_minor << "."
        ;
    }

    if (uhd_major > fpga_major) {
        if (!log_component.empty()) {
            UHD_LOGGER_ERROR(log_component)
                << "Major compat number mismatch for " << fpga_component << ":"
                   " Expecting " << uhd_major << ", got " << fpga_major << "."
            ;
        }
        throw uhd::runtime_error(str(
            boost::format("FPGA component `%s' is revision %d and UHD supports"
                          " revision %d. Please either upgrade the FPGA"
                          " image (recommended) or downgrade UHD.")
            % fpga_component
            % fpga_major
            % uhd_major
        ));
    }
    if (uhd_major < fpga_major) {
        if (!log_component.empty()) {
            UHD_LOGGER_ERROR(log_component)
                << "Major compat number mismatch for " << fpga_component << ":"
                " Expecting " << uhd_major << ", got " << fpga_major << "."
            ;
        }
        throw uhd::runtime_error(str(
            boost::format("FPGA component `%s' is revision %d and UHD supports"
                          " revision %d. Please either upgrade UHD "
                          " (recommended) or downgrade the FPGA image.")
            % fpga_component
            % fpga_major
            % uhd_major
        ));

    }
    if (uhd_minor > fpga_minor) {
        if (fail_on_minor_behind) {
            if (!log_component.empty()) {
                UHD_LOGGER_ERROR(log_component) << str(
                    boost::format("Minor compat number mismatch for `%s':"
                                  " Expecting %d.%d, got %d.%d.")
                    % fpga_component
                    % uhd_major
                    % uhd_minor
                    % fpga_major
                    % fpga_minor
                );
            }
            throw uhd::runtime_error(str(
                boost::format("FPGA component `%s' is revision %d.%d and UHD supports"
                              " revision %d.%d. Please either upgrade UHD "
                              " (recommended) or downgrade the FPGA image.")
                % fpga_component
                % fpga_major
                % fpga_minor
                % uhd_major
                % uhd_minor
            ));
        } else {
            if (!log_component.empty()) {
                UHD_LOGGER_WARNING(log_component) << str(
                    boost::format("Non-critical minor compat number mismatch "
                                  "for `%s': Expecting %d.%d, got %d.%d.")
                    % fpga_component
                    % uhd_major
                    % uhd_minor
                    % fpga_major
                    % fpga_minor
                );
            }
        }
    } else if (uhd_minor < fpga_minor) {
        if (!log_component.empty()) {
            UHD_LOGGER_WARNING(log_component) << str(
                boost::format("Non-critical minor compat number mismatch "
                              "for `%s': Expecting %d.%d, got %d.%d.")
                % fpga_component
                % uhd_major
                % uhd_minor
                % fpga_major
                % fpga_minor
            );
        }
    }
    // We got here? Then all is good.
}