Skip to content

Commit 9123f07

Browse files
authored
feat: Save the whole firmware path in annotation rather than just the firmware name (#21)
Signed-off-by: Yejin Seo <yejseo01@arm.com>
1 parent 239ed49 commit 9123f07

4 files changed

Lines changed: 15 additions & 16 deletions

File tree

internal/oci/annotations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const (
1212
StateDriverPath = "remoteproc.driver-path"
1313
StateFirmwarePath = "remoteproc.firmware-path"
1414

15-
OptionalStateStoredFirmwareName = "remoteproc.stored-firmware-name"
15+
OptionalStateStoredFirmwarePath = "remoteproc.stored-firmware-path"
1616
)
1717

1818
func validateSpecAnnotations(spec *specs.Spec) error {

internal/remoteproc/remoteproc.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,19 @@ func StoreFirmware(sourcePath string) (string, error) {
107107
if err := os.WriteFile(destPath, data, 0o644); err != nil {
108108
return "", fmt.Errorf("failed to write firmware file %s: %w", destPath, err)
109109
}
110-
return targetFileName, nil
110+
return destPath, nil
111111
}
112112

113-
func RemoveFirmware(firmwareFileName string) error {
114-
return os.Remove(filepath.Join(rprocFirmwareStorePath, firmwareFileName))
115-
}
116-
117-
func SetFirmware(devicePath string, firmwareFileName string) error {
113+
func SetFirmware(devicePath string, firmwareFilePath string) error {
118114
state, err := GetState(devicePath)
119115
if err != nil {
120116
return fmt.Errorf("pre-flight state check failed: %w", err)
121117
}
122118
if state == StateRunning {
123119
return fmt.Errorf("remote processor is already running")
124120
}
121+
122+
firmwareFileName := filepath.Base(firmwareFilePath)
125123
if err := os.WriteFile(buildFirmwareFilePath(devicePath), []byte(firmwareFileName), 0o644); err != nil {
126124
return fmt.Errorf("failed to set firmware %s: %w", firmwareFileName, err)
127125
}

internal/runtime/delete.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package runtime
33
import (
44
"fmt"
55
"log/slog"
6+
"os"
67
"syscall"
78

89
"github.com/arm/remoteproc-runtime/internal/oci"
9-
"github.com/arm/remoteproc-runtime/internal/remoteproc"
1010
"github.com/opencontainers/runtime-spec/specs-go"
1111
)
1212

@@ -29,9 +29,9 @@ func delete(containerID string) error {
2929
return fmt.Errorf("cannot delete running container %s", containerID)
3030
}
3131

32-
firmwareName, ok := state.Annotations[oci.OptionalStateStoredFirmwareName]
32+
firmwarePath, ok := state.Annotations[oci.OptionalStateStoredFirmwarePath]
3333
if ok {
34-
if err := remoteproc.RemoveFirmware(firmwareName); err != nil {
34+
if err := os.Remove(firmwarePath); err != nil {
3535
return fmt.Errorf("failed to remove firmware: %w", err)
3636
}
3737
}
@@ -56,9 +56,9 @@ func forceDelete(logger *slog.Logger, containerID string) {
5656
}
5757
}
5858

59-
firmwareName, ok := state.Annotations[oci.OptionalStateStoredFirmwareName]
59+
firmwarePath, ok := state.Annotations[oci.OptionalStateStoredFirmwarePath]
6060
if ok {
61-
if err := remoteproc.RemoveFirmware(firmwareName); err != nil {
61+
if err := os.Remove(firmwarePath); err != nil {
6262
logger.Error("failed to remove firmware", "error", err)
6363
}
6464
}

internal/runtime/start.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package runtime
22

33
import (
44
"fmt"
5+
"os"
56

67
"github.com/arm/remoteproc-runtime/internal/oci"
78
"github.com/arm/remoteproc-runtime/internal/proxy"
@@ -15,21 +16,21 @@ func Start(containerID string) error {
1516
return fmt.Errorf("failed to read state: %w", err)
1617
}
1718
firmwarePath := state.Annotations[oci.StateFirmwarePath]
18-
storedFirmwareName, err := remoteproc.StoreFirmware(firmwarePath)
19+
storedFirmwarePath, err := remoteproc.StoreFirmware(firmwarePath)
1920
if err != nil {
2021
return fmt.Errorf("failed to store firmware file %s: %w", firmwarePath, err)
2122
}
22-
state.Annotations[oci.OptionalStateStoredFirmwareName] = storedFirmwareName
23+
state.Annotations[oci.OptionalStateStoredFirmwarePath] = storedFirmwarePath
2324
needCleanup := true
2425
defer func() {
2526
if needCleanup {
26-
_ = remoteproc.RemoveFirmware(storedFirmwareName)
27+
_ = os.Remove(storedFirmwarePath)
2728
}
2829
}()
2930

3031
if err := remoteproc.SetFirmware(
3132
state.Annotations[oci.StateDriverPath],
32-
storedFirmwareName,
33+
storedFirmwarePath,
3334
); err != nil {
3435
return fmt.Errorf("failed to set firmware: %w", err)
3536
}

0 commit comments

Comments
 (0)