Skip to content

Commit 65854ea

Browse files
aviralgarg05acassis
authored andcommitted
system/nxpkg: add local package lifecycle helper
Add the initial nxpkg command, metadata and store handling, the local install/list path, and the repository export helper. Keep the current flow scoped to local artifacts and target-qualified repository entries so it remains usable as an incremental MVP while follow-up features land separately. Signed-off-by: aviralgarg05 <gargaviral99@gmail.com>
1 parent 477d04b commit 65854ea

15 files changed

Lines changed: 2920 additions & 0 deletions

system/nxpkg/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# ##############################################################################
2+
# apps/system/nxpkg/CMakeLists.txt
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
7+
# license agreements. See the NOTICE file distributed with this work for
8+
# additional information regarding copyright ownership. The ASF licenses this
9+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
10+
# use this file except in compliance with the License. You may obtain a copy of
11+
# the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations under
19+
# the License.
20+
#
21+
# ##############################################################################
22+
23+
if(CONFIG_SYSTEM_NXPKG)
24+
nuttx_add_application(
25+
MODULE
26+
${CONFIG_SYSTEM_NXPKG}
27+
NAME
28+
${CONFIG_SYSTEM_NXPKG_PROGNAME}
29+
STACKSIZE
30+
${CONFIG_SYSTEM_NXPKG_STACKSIZE}
31+
PRIORITY
32+
${CONFIG_SYSTEM_NXPKG_PRIORITY}
33+
SRCS
34+
pkg_main.c
35+
pkg_compat.c
36+
pkg_hash.c
37+
pkg_install.c
38+
pkg_log.c
39+
pkg_manifest.c
40+
pkg_metadata.c
41+
pkg_store.c
42+
pkg_txn.c)
43+
endif()

system/nxpkg/Kconfig

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see the file kconfig-language.txt in the NuttX tools repository.
4+
#
5+
6+
config SYSTEM_NXPKG
7+
bool "'nxpkg' lifecycle helper"
8+
default n
9+
select CRYPTO
10+
select NETUTILS_CJSON
11+
---help---
12+
Enable the thin package lifecycle helper proposed for the
13+
Dynamic ELF distribution work.
14+
15+
if SYSTEM_NXPKG
16+
17+
config SYSTEM_NXPKG_PROGNAME
18+
string "Program name"
19+
default "nxpkg"
20+
---help---
21+
This is the name of the program that will be used when the
22+
nxpkg tool is installed.
23+
24+
config SYSTEM_NXPKG_PRIORITY
25+
int "'nxpkg' task priority"
26+
default 100
27+
28+
config SYSTEM_NXPKG_STACKSIZE
29+
int "'nxpkg' stack size"
30+
default 16384
31+
32+
endif

system/nxpkg/Make.defs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
############################################################################
2+
# apps/system/nxpkg/Make.defs
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more
7+
# contributor license agreements. See the NOTICE file distributed with
8+
# this work for additional information regarding copyright ownership. The
9+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance with the
11+
# License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
############################################################################
22+
23+
ifneq ($(CONFIG_SYSTEM_NXPKG),)
24+
CONFIGURED_APPS += $(APPDIR)/system/nxpkg
25+
endif

system/nxpkg/Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
############################################################################
2+
# apps/system/nxpkg/Makefile
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more
7+
# contributor license agreements. See the NOTICE file distributed with
8+
# this work for additional information regarding copyright ownership. The
9+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance with the
11+
# License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
############################################################################
22+
23+
include $(APPDIR)/Make.defs
24+
25+
PROGNAME = $(CONFIG_SYSTEM_NXPKG_PROGNAME)
26+
PRIORITY = $(CONFIG_SYSTEM_NXPKG_PRIORITY)
27+
STACKSIZE = $(CONFIG_SYSTEM_NXPKG_STACKSIZE)
28+
MODULE = $(CONFIG_SYSTEM_NXPKG)
29+
30+
CSRCS = pkg_compat.c pkg_hash.c pkg_install.c pkg_log.c pkg_manifest.c
31+
CSRCS += pkg_metadata.c pkg_store.c pkg_txn.c
32+
MAINSRC = pkg_main.c
33+
34+
include $(APPDIR)/Application.mk

system/nxpkg/pkg.h

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/****************************************************************************
2+
* apps/system/nxpkg/pkg.h
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#ifndef __APPS_SYSTEM_NXPKG_PKG_H
24+
#define __APPS_SYSTEM_NXPKG_PKG_H
25+
26+
/****************************************************************************
27+
* Included Files
28+
****************************************************************************/
29+
30+
#include <limits.h>
31+
#include <stdbool.h>
32+
#include <stddef.h>
33+
#include <stdio.h>
34+
35+
/****************************************************************************
36+
* Pre-processor Definitions
37+
****************************************************************************/
38+
39+
#define PKG_REPO_DIR "/etc/nxpkg"
40+
#define PKG_REPO_INDEX "/etc/nxpkg/index.json"
41+
#define PKG_REPO_INSTALLED "/var/lib/nxpkg/installed.json"
42+
#define PKG_STORE_DIR "/var/lib/nxpkg/pkgs"
43+
#define PKG_TMP_DIR "/var/cache/nxpkg"
44+
#define PKG_TMP_PKG_DIR "/var/cache/nxpkg/pkg"
45+
46+
#define PKG_NAME_MAX 63
47+
#define PKG_VERSION_MAX 31
48+
#define PKG_ARCH_MAX 31
49+
#define PKG_COMPAT_MAX 63
50+
#define PKG_HASH_HEX_LEN 64
51+
#define PKG_INDEX_MAX 32
52+
#define PKG_INSTALLED_MAX 16
53+
#define PKG_INSTALLED_VERSIONS_MAX 8
54+
55+
/****************************************************************************
56+
* Public Types
57+
****************************************************************************/
58+
59+
enum pkg_payload_type_e
60+
{
61+
PKG_PAYLOAD_ELF = 0,
62+
PKG_PAYLOAD_SHARED_LIB
63+
};
64+
65+
enum pkg_txn_state_e
66+
{
67+
PKG_TXN_IDLE = 0,
68+
PKG_TXN_FETCHING,
69+
PKG_TXN_VERIFIED,
70+
PKG_TXN_STAGED,
71+
PKG_TXN_COMPAT_OK,
72+
PKG_TXN_ACTIVATED,
73+
PKG_TXN_CLEANUP,
74+
PKG_TXN_FAILED,
75+
PKG_TXN_RESTORE
76+
};
77+
78+
struct pkg_manifest_s
79+
{
80+
char name[PKG_NAME_MAX + 1];
81+
char version[PKG_VERSION_MAX + 1];
82+
char arch[PKG_ARCH_MAX + 1];
83+
char compat[PKG_COMPAT_MAX + 1];
84+
char artifact[PATH_MAX];
85+
char sha256[PKG_HASH_HEX_LEN + 1];
86+
enum pkg_payload_type_e type;
87+
};
88+
89+
struct pkg_index_s
90+
{
91+
struct pkg_manifest_s manifests[PKG_INDEX_MAX];
92+
size_t count;
93+
};
94+
95+
struct pkg_installed_entry_s
96+
{
97+
char name[PKG_NAME_MAX + 1];
98+
char current[PKG_VERSION_MAX + 1];
99+
char previous[PKG_VERSION_MAX + 1];
100+
char arch[PKG_ARCH_MAX + 1];
101+
char compat[PKG_COMPAT_MAX + 1];
102+
char versions[PKG_INSTALLED_VERSIONS_MAX][PKG_VERSION_MAX + 1];
103+
enum pkg_payload_type_e type;
104+
size_t version_count;
105+
};
106+
107+
struct pkg_installed_db_s
108+
{
109+
struct pkg_installed_entry_s entries[PKG_INSTALLED_MAX];
110+
size_t count;
111+
};
112+
113+
/****************************************************************************
114+
* Public Function Prototypes
115+
****************************************************************************/
116+
117+
const char *pkg_manifest_type_str(enum pkg_payload_type_e type);
118+
int pkg_manifest_validate(FAR const struct pkg_manifest_s *manifest);
119+
int pkg_manifest_parse_type(FAR const char *value,
120+
FAR enum pkg_payload_type_e *type);
121+
122+
int pkg_store_prepare_layout(void);
123+
int pkg_store_ensure_package_root(FAR const char *name);
124+
int pkg_store_ensure_version_dir(FAR const char *name,
125+
FAR const char *version);
126+
int pkg_store_format_index_path(FAR char *buffer, size_t size);
127+
int pkg_store_format_installed_path(FAR char *buffer, size_t size);
128+
int pkg_store_format_package_root(FAR char *buffer, size_t size,
129+
FAR const char *name);
130+
int pkg_store_format_version_path(FAR char *buffer, size_t size,
131+
FAR const char *name,
132+
FAR const char *version);
133+
int pkg_store_format_current_path(FAR char *buffer, size_t size,
134+
FAR const char *name);
135+
int pkg_store_format_previous_path(FAR char *buffer, size_t size,
136+
FAR const char *name);
137+
int pkg_store_format_txn_path(FAR char *buffer, size_t size,
138+
FAR const char *name);
139+
int pkg_store_format_lock_path(FAR char *buffer, size_t size,
140+
FAR const char *name);
141+
int pkg_store_format_download_path(FAR char *buffer, size_t size,
142+
FAR const char *name,
143+
FAR const char *version);
144+
int pkg_store_format_payload_path(FAR char *buffer, size_t size,
145+
FAR const char *name,
146+
FAR const char *version,
147+
FAR const char *artifact);
148+
int pkg_store_format_manifest_path(FAR char *buffer, size_t size,
149+
FAR const char *name,
150+
FAR const char *version);
151+
int pkg_store_read_text(FAR const char *path, FAR char **buffer);
152+
int pkg_store_write_text_atomic(FAR const char *path, FAR const char *text);
153+
int pkg_store_copy_file(FAR const char *src, FAR const char *dest);
154+
int pkg_store_remove_file(FAR const char *path);
155+
156+
const char *pkg_runtime_arch(void);
157+
const char *pkg_runtime_compat(void);
158+
int pkg_compat_check(FAR const struct pkg_manifest_s *manifest);
159+
160+
int pkg_hash_file_sha256(FAR const char *path,
161+
FAR char digest[PKG_HASH_HEX_LEN + 1]);
162+
163+
int pkg_metadata_load_index(FAR struct pkg_index_s *index);
164+
FAR const struct pkg_manifest_s *
165+
pkg_metadata_find_latest(FAR const struct pkg_index_s *index,
166+
FAR const char *name);
167+
int pkg_metadata_load_installed(FAR struct pkg_installed_db_s *db);
168+
int pkg_metadata_save_installed(FAR const struct pkg_installed_db_s *db);
169+
FAR struct pkg_installed_entry_s *
170+
pkg_metadata_find_installed(FAR struct pkg_installed_db_s *db,
171+
FAR const char *name);
172+
int pkg_metadata_write_manifest(FAR const char *path,
173+
FAR const struct pkg_manifest_s *manifest);
174+
int pkg_metadata_print_installed(FAR FILE *stream,
175+
FAR const struct pkg_installed_db_s *db);
176+
177+
const char *pkg_txn_state_str(enum pkg_txn_state_e state);
178+
int pkg_txn_write_state(FAR const char *name, enum pkg_txn_state_e state);
179+
int pkg_txn_clear_state(FAR const char *name);
180+
181+
int pkg_install(FAR const char *name);
182+
int pkg_list(FAR FILE *stream);
183+
184+
void pkg_error(FAR const char *fmt, ...);
185+
void pkg_info(FAR const char *fmt, ...);
186+
187+
#endif /* __APPS_SYSTEM_NXPKG_PKG_H */

system/nxpkg/pkg_compat.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/****************************************************************************
2+
* apps/system/nxpkg/pkg_compat.c
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <errno.h>
28+
#include <string.h>
29+
30+
#include "pkg.h"
31+
32+
/****************************************************************************
33+
* Public Functions
34+
****************************************************************************/
35+
36+
const char *pkg_runtime_arch(void)
37+
{
38+
return CONFIG_ARCH;
39+
}
40+
41+
const char *pkg_runtime_compat(void)
42+
{
43+
return CONFIG_ARCH_BOARD;
44+
}
45+
46+
int pkg_compat_check(FAR const struct pkg_manifest_s *manifest)
47+
{
48+
if (manifest == NULL)
49+
{
50+
return -EINVAL;
51+
}
52+
53+
if (strcmp(manifest->arch, pkg_runtime_arch()) != 0)
54+
{
55+
return -ENOEXEC;
56+
}
57+
58+
if (strcmp(manifest->compat, pkg_runtime_compat()) != 0)
59+
{
60+
return -EXDEV;
61+
}
62+
63+
return 0;
64+
}

0 commit comments

Comments
 (0)