|
| 1 | +// Copyright 2025 CoreOS, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package nvidia_bluefield |
| 16 | + |
| 17 | +import ( |
| 18 | + "os" |
| 19 | + |
| 20 | + "github.com/coreos/ignition/v2/config/v3_6_experimental/types" |
| 21 | + "github.com/coreos/ignition/v2/internal/platform" |
| 22 | + "github.com/coreos/ignition/v2/internal/providers/util" |
| 23 | + "github.com/coreos/ignition/v2/internal/resource" |
| 24 | + |
| 25 | + "github.com/coreos/vcontext/report" |
| 26 | +) |
| 27 | + |
| 28 | +const ( |
| 29 | + bootfifoPath = "/sys/bus/platform/devices/MLNXBF04:00/bootfifo" |
| 30 | +) |
| 31 | + |
| 32 | +func init() { |
| 33 | + platform.Register(platform.Provider{ |
| 34 | + Name: "nvidia-bluefield", |
| 35 | + Fetch: fetchConfig, |
| 36 | + }) |
| 37 | +} |
| 38 | + |
| 39 | +func fetchConfig(f *resource.Fetcher) (cfg types.Config, rpt report.Report, err error) { |
| 40 | + data, err := os.ReadFile(bootfifoPath) |
| 41 | + if os.IsNotExist(err) { |
| 42 | + f.Logger.Info("Nvidia BlueField bootfifo was not found. Ignoring...") |
| 43 | + cfg, rpt, err = util.ParseConfig(f.Logger, []byte{}) |
| 44 | + return |
| 45 | + } else if err != nil { |
| 46 | + f.Logger.Err("couldn't read Nvidia BlueField config: %v", err) |
| 47 | + return |
| 48 | + } |
| 49 | + |
| 50 | + if len(data) == 0 { |
| 51 | + f.Logger.Info("no config found in Nvidia BlueField bootfifo") |
| 52 | + cfg, rpt, err = util.ParseConfig(f.Logger, []byte{}) |
| 53 | + return |
| 54 | + } |
| 55 | + |
| 56 | + cfg, rpt, err = util.ParseConfig(f.Logger, data) |
| 57 | + return |
| 58 | +} |
0 commit comments