Skip to content

Commit 568280b

Browse files
authored
Merge branch 'dev' into feat/hostname
2 parents f234807 + 3fcd5e7 commit 568280b

File tree

103 files changed

+11748
-1371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+11748
-1371
lines changed

.devcontainer/install-deps.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ sudo apt-get install -y --no-install-recommends \
1818
build-essential \
1919
device-tree-compiler \
2020
gperf g++-multilib gcc-multilib \
21+
gdb-multiarch \
2122
libnl-3-dev libdbus-1-dev libelf-dev libmpc-dev dwarves \
2223
bc openssl flex bison libssl-dev python3 python-is-python3 texinfo kmod cmake \
2324
wget zstd \

.vscode/c_cpp_properties.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [],
9+
"compilerPath": "/opt/jetkvm-native-buildkit/bin/arm-rockchip830-linux-uclibcgnueabihf-gcc",
10+
"cStandard": "c17",
11+
"cppStandard": "gnu++17",
12+
"intelliSenseMode": "linux-gcc-arm",
13+
"configurationProvider": "ms-vscode.cmake-tools"
14+
}
15+
],
16+
"version": 4
17+
}

.vscode/launch.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "GDB Debug - Native (binary)",
6+
"type": "cppdbg",
7+
"request": "launch",
8+
"program": "internal/native/cgo/build/jknative-bin",
9+
"args": [],
10+
"stopAtEntry": true,
11+
"cwd": "${workspaceFolder}",
12+
"environment": [],
13+
"MIMode": "gdb",
14+
"miDebuggerPath": "/usr/bin/gdb-multiarch",
15+
"miDebuggerServerAddress": "${config:TARGET_IP}:${config:DEBUG_PORT}",
16+
"targetArchitecture": "arm",
17+
"preLaunchTask": "deploy",
18+
"setupCommands": [
19+
{
20+
"description": "Pretty-printing for gdb",
21+
"text": "-enable-pretty-printing",
22+
"ignoreFailures": true
23+
}
24+
],
25+
"externalConsole": true
26+
}
27+
]
28+
}

.vscode/settings.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,19 @@
1010
]
1111
},
1212
"git.ignoreLimitWarning": true,
13-
"cmake.sourceDirectory": "/workspaces/kvm-static-ip/internal/native/cgo"
13+
"cmake.sourceDirectory": "${workspaceFolder}/internal/native/cgo",
14+
"cmake.ignoreCMakeListsMissing": true,
15+
"C_Cpp.inlayHints.autoDeclarationTypes.enabled": true,
16+
"C_Cpp.inlayHints.parameterNames.enabled": true,
17+
"C_Cpp.inlayHints.referenceOperator.enabled": true,
18+
"TARGET_IP": "192.168.0.199",
19+
"DEBUG_PORT": "2345",
20+
"json.schemas": [
21+
{
22+
"fileMatch": [
23+
"/internal/ota/testdata/ota/*.json"
24+
],
25+
"url": "./internal/ota/testdata/ota.schema.json"
26+
}
27+
]
1428
}

.vscode/tasks.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "deploy",
8+
"isBackground": true,
9+
"type": "shell",
10+
"command": "bash",
11+
"args": [
12+
"dev_deploy.sh",
13+
"-r",
14+
"${config:TARGET_IP}",
15+
"--gdb-port",
16+
"${config:DEBUG_PORT}",
17+
"--native-binary",
18+
"--disable-docker"
19+
],
20+
"problemMatcher": {
21+
"base": "$gcc",
22+
"background": {
23+
"activeOnStart": true,
24+
"beginsPattern": "${config:BINARY}",
25+
"endsPattern": "Listening on port [0-9]{4}"
26+
}
27+
}
28+
},
29+
]
30+
}

DEVELOPMENT.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ rm /userdata/kvm_config.json
208208
systemctl restart jetkvm
209209
```
210210

211+
### Debug native code with gdbserver
212+
213+
Change the `TARGET_IP` in `.vscode/settings.json` to your JetKVM device IP, then set breakpoints in your native code and start the `Debug Native` configuration in VSCode.
214+
215+
The code and GDB server will be deployed automatically.
216+
211217
---
212218

213219
## Testing Your Changes

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ SKIP_NATIVE_IF_EXISTS ?= 0
1414
SKIP_UI_BUILD ?= 0
1515
ENABLE_SYNC_TRACE ?= 0
1616

17+
CMAKE_BUILD_TYPE ?= Release
18+
1719
GO_BUILD_ARGS := -tags netgo,timetzdata,nomsgpack
1820
ifeq ($(ENABLE_SYNC_TRACE), 1)
1921
GO_BUILD_ARGS := $(GO_BUILD_ARGS),synctrace
@@ -52,6 +54,7 @@ build_native:
5254
echo "Building native..."; \
5355
CC="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-gcc" \
5456
LD="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-ld" \
57+
CMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \
5558
./scripts/build_cgo.sh; \
5659
fi
5760

cmd/main.go

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,39 @@ import (
1313

1414
"github.com/erikdubbelboer/gspt"
1515
"github.com/jetkvm/kvm"
16+
"github.com/jetkvm/kvm/internal/native"
17+
"github.com/jetkvm/kvm/internal/supervisor"
1618
)
1719

18-
const (
19-
envChildID = "JETKVM_CHILD_ID"
20-
errorDumpDir = "/userdata/jetkvm/crashdump"
21-
errorDumpLastFile = "last-crash.log"
22-
errorDumpTemplate = "jetkvm-%s.log"
20+
var (
21+
subcomponent string
2322
)
2423

2524
func program() {
26-
gspt.SetProcTitle(os.Args[0] + " [app]")
27-
kvm.Main()
25+
subcomponentOverride := os.Getenv(supervisor.EnvSubcomponent)
26+
if subcomponentOverride != "" {
27+
subcomponent = subcomponentOverride
28+
}
29+
switch subcomponent {
30+
case "native":
31+
native.RunNativeProcess(os.Args[0])
32+
default:
33+
kvm.Main()
34+
}
35+
}
36+
37+
func setProcTitle(status string) {
38+
if status != "" {
39+
status = " " + status
40+
}
41+
title := fmt.Sprintf("jetkvm: [supervisor]%s", status)
42+
gspt.SetProcTitle(title)
2843
}
2944

3045
func main() {
3146
versionPtr := flag.Bool("version", false, "print version and exit")
3247
versionJSONPtr := flag.Bool("version-json", false, "print version as json and exit")
48+
flag.StringVar(&subcomponent, "subcomponent", "", "subcomponent to run")
3349
flag.Parse()
3450

3551
if *versionPtr || *versionJSONPtr {
@@ -42,7 +58,7 @@ func main() {
4258
return
4359
}
4460

45-
childID := os.Getenv(envChildID)
61+
childID := os.Getenv(supervisor.EnvChildID)
4662
switch childID {
4763
case "":
4864
doSupervise()
@@ -55,6 +71,8 @@ func main() {
5571
}
5672

5773
func supervise() error {
74+
setProcTitle("")
75+
5876
// check binary path
5977
binPath, err := os.Executable()
6078
if err != nil {
@@ -74,7 +92,12 @@ func supervise() error {
7492
// run the child binary
7593
cmd := exec.Command(binPath)
7694

77-
cmd.Env = append(os.Environ(), []string{envChildID + "=" + kvm.GetBuiltAppVersion()}...)
95+
lastFilePath := filepath.Join(supervisor.ErrorDumpDir, supervisor.ErrorDumpLastFile)
96+
97+
cmd.Env = append(os.Environ(), []string{
98+
fmt.Sprintf("%s=%s", supervisor.EnvChildID, kvm.GetBuiltAppVersion()),
99+
fmt.Sprintf("%s=%s", supervisor.ErrorDumpLastFile, lastFilePath),
100+
}...)
78101
cmd.Args = os.Args
79102

80103
logFile, err := os.CreateTemp("", "jetkvm-stdout.log")
@@ -94,6 +117,8 @@ func supervise() error {
94117
return fmt.Errorf("failed to start command: %w", startErr)
95118
}
96119

120+
setProcTitle(fmt.Sprintf("started (pid=%d)", cmd.Process.Pid))
121+
97122
go func() {
98123
sigChan := make(chan os.Signal, 1)
99124
signal.Notify(sigChan, syscall.SIGTERM)
@@ -102,8 +127,6 @@ func supervise() error {
102127
_ = cmd.Process.Signal(sig)
103128
}()
104129

105-
gspt.SetProcTitle(os.Args[0] + " [sup]")
106-
107130
cmdErr := cmd.Wait()
108131
if cmdErr == nil {
109132
return nil
@@ -181,11 +204,11 @@ func renameFile(f *os.File, newName string) error {
181204

182205
func ensureErrorDumpDir() error {
183206
// TODO: check if the directory is writable
184-
f, err := os.Stat(errorDumpDir)
207+
f, err := os.Stat(supervisor.ErrorDumpDir)
185208
if err == nil && f.IsDir() {
186209
return nil
187210
}
188-
if err := os.MkdirAll(errorDumpDir, 0755); err != nil {
211+
if err := os.MkdirAll(supervisor.ErrorDumpDir, 0755); err != nil {
189212
return fmt.Errorf("failed to create error dump directory: %w", err)
190213
}
191214
return nil
@@ -195,7 +218,7 @@ func createErrorDump(logFile *os.File) {
195218
fmt.Println()
196219

197220
fileName := fmt.Sprintf(
198-
errorDumpTemplate,
221+
supervisor.ErrorDumpTemplate,
199222
time.Now().Format("20060102-150405"),
200223
)
201224

@@ -205,15 +228,15 @@ func createErrorDump(logFile *os.File) {
205228
return
206229
}
207230

208-
filePath := filepath.Join(errorDumpDir, fileName)
231+
filePath := filepath.Join(supervisor.ErrorDumpDir, fileName)
209232
if err := renameFile(logFile, filePath); err != nil {
210233
fmt.Printf("failed to rename file: %v\n", err)
211234
return
212235
}
213236

214237
fmt.Printf("error dump copied: %s\n", filePath)
215238

216-
lastFilePath := filepath.Join(errorDumpDir, errorDumpLastFile)
239+
lastFilePath := filepath.Join(supervisor.ErrorDumpDir, supervisor.ErrorDumpLastFile)
217240

218241
if err := ensureSymlink(filePath, lastFilePath); err != nil {
219242
fmt.Printf("failed to create symlink: %v\n", err)

config.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"strconv"
8+
"strings"
89
"sync"
910

1011
"github.com/jetkvm/kvm/internal/confparser"
@@ -15,6 +16,10 @@ import (
1516
"github.com/prometheus/client_golang/prometheus/promauto"
1617
)
1718

19+
const (
20+
DefaultAPIURL = "https://api.jetkvm.com"
21+
)
22+
1823
type WakeOnLanDevice struct {
1924
Name string `json:"name"`
2025
MacAddress string `json:"macAddress"`
@@ -80,6 +85,7 @@ func (m *KeyboardMacro) Validate() error {
8085

8186
type Config struct {
8287
CloudURL string `json:"cloud_url"`
88+
UpdateAPIURL string `json:"update_api_url"`
8389
CloudAppURL string `json:"cloud_app_url"`
8490
CloudToken string `json:"cloud_token"`
8591
GoogleIdentity string `json:"google_identity"`
@@ -107,8 +113,18 @@ type Config struct {
107113
DefaultLogLevel string `json:"default_log_level"`
108114
VideoSleepAfterSec int `json:"video_sleep_after_sec"`
109115
VideoQualityFactor float64 `json:"video_quality_factor"`
116+
NativeMaxRestart uint `json:"native_max_restart_attempts"`
117+
}
118+
119+
// GetUpdateAPIURL returns the update API URL
120+
func (c *Config) GetUpdateAPIURL() string {
121+
if c.UpdateAPIURL == "" {
122+
return DefaultAPIURL
123+
}
124+
return strings.TrimSuffix(c.UpdateAPIURL, "/") + "/releases"
110125
}
111126

127+
// GetDisplayRotation returns the display rotation
112128
func (c *Config) GetDisplayRotation() uint16 {
113129
rotationInt, err := strconv.ParseUint(c.DisplayRotation, 10, 16)
114130
if err != nil {
@@ -118,6 +134,7 @@ func (c *Config) GetDisplayRotation() uint16 {
118134
return uint16(rotationInt)
119135
}
120136

137+
// SetDisplayRotation sets the display rotation
121138
func (c *Config) SetDisplayRotation(rotation string) error {
122139
_, err := strconv.ParseUint(rotation, 10, 16)
123140
if err != nil {
@@ -156,7 +173,8 @@ var (
156173

157174
func getDefaultConfig() Config {
158175
return Config{
159-
CloudURL: "https://api.jetkvm.com",
176+
CloudURL: DefaultAPIURL,
177+
UpdateAPIURL: DefaultAPIURL,
160178
CloudAppURL: "https://app.jetkvm.com",
161179
AutoUpdateEnabled: true, // Set a default value
162180
ActiveExtension: "",

display.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ func updateStaticContents() {
252252
nativeInstance.UpdateLabelAndChangeVisibility("device_id", GetDeviceID())
253253
}
254254

255+
// configureDisplayOnNativeRestart is called when the native process restarts
256+
// it ensures the display is configured correctly after the restart
257+
func configureDisplayOnNativeRestart() {
258+
displayLogger.Info().Msg("native restarted, configuring display")
259+
updateStaticContents()
260+
requestDisplayUpdate(true, "native_restart")
261+
}
262+
255263
// setDisplayBrightness sets /sys/class/backlight/backlight/brightness to alter
256264
// the backlight brightness of the JetKVM hardware's display.
257265
func setDisplayBrightness(brightness int, reason string) error {

0 commit comments

Comments
 (0)