Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions include/system/nxstore_chrome.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/****************************************************************************
* apps/include/system/nxstore_chrome.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

#ifndef __APPS_INCLUDE_SYSTEM_NXSTORE_CHROME_H
#define __APPS_INCLUDE_SYSTEM_NXSTORE_CHROME_H

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

/* Full-screen applications launched by nxstore share the framebuffer with
* its supervisor bar. They must leave this top strip untouched so the
* Close control remains visible and usable.
*/

#define NXSTORE_BAR_HEIGHT 36

#endif /* __APPS_INCLUDE_SYSTEM_NXSTORE_CHROME_H */
1 change: 1 addition & 0 deletions system/nxpkg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ if(CONFIG_SYSTEM_NXPKG)
pkg_log.c
pkg_manifest.c
pkg_metadata.c
pkg_repo.c
pkg_store.c
pkg_txn.c)
endif()
11 changes: 11 additions & 0 deletions system/nxpkg/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,15 @@ config SYSTEM_NXPKG_STACKSIZE
int "'nxpkg' stack size"
default 16384

config SYSTEM_NXPKG_ROOT
string "'nxpkg' storage root"
default "/var/lib/nxpkg"
---help---
Base directory used by nxpkg for its local index, installed
metadata, temporary downloads, and package payload storage.
The default follows the conventional persistent application-data
location. A board must mount persistent storage at /var or set
this to another persistent location, such as /mnt/sdcard/nxpkg,
if packages need to survive a reset.

endif
1 change: 1 addition & 0 deletions system/nxpkg/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ MODULE = $(CONFIG_SYSTEM_NXPKG)

CSRCS = pkg_compat.c pkg_hash.c pkg_install.c pkg_log.c pkg_manifest.c
CSRCS += pkg_metadata.c pkg_store.c pkg_txn.c
CSRCS += pkg_repo.c
MAINSRC = pkg_main.c

include $(APPDIR)/Application.mk
103 changes: 96 additions & 7 deletions system/nxpkg/pkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,93 @@
* Included Files
****************************************************************************/

#include <nuttx/config.h>

#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#define PKG_REPO_DIR "/etc/nxpkg"
#define PKG_REPO_INDEX "/etc/nxpkg/index.json"
#define PKG_REPO_INSTALLED "/var/lib/nxpkg/installed.json"
#define PKG_STORE_DIR "/var/lib/nxpkg/pkgs"
#define PKG_TMP_DIR "/var/cache/nxpkg"
#define PKG_TMP_PKG_DIR "/var/cache/nxpkg/pkg"
#define PKG_ROOT_DIR CONFIG_SYSTEM_NXPKG_ROOT
#define PKG_REPO_DIR PKG_ROOT_DIR
#define PKG_REPO_INDEX PKG_ROOT_DIR "/index.jsn"
#define PKG_REPO_SOURCE PKG_ROOT_DIR "/repo.url"
#define PKG_REPO_INSTALLED PKG_ROOT_DIR "/instpkg.jsn"
#define PKG_STORE_DIR PKG_ROOT_DIR "/pkgs"
#define PKG_TMP_DIR PKG_ROOT_DIR "/tmp"
#define PKG_TMP_PKG_DIR PKG_ROOT_DIR "/tmp/pkg"

#define PKG_NAME_MAX 63
#define PKG_VERSION_MAX 31
#define PKG_ARCH_MAX 31
#define PKG_COMPAT_MAX 63
#define PKG_DESCRIPTION_MAX 127
#define PKG_CATEGORY_MAX 31
#define PKG_HASH_HEX_LEN 64
#define PKG_INDEX_MAX 32
/* Each manifest slot is ~1.7KB (dominated by PKG_LAUNCH_ARGS_MAX slots).
* Keep the catalog bounded so repository-provided metadata cannot cause
* unbounded memory use. Callers should allocate struct pkg_index_s from
* the application heap rather than placing it on a small task stack.
*/

#define PKG_INDEX_MAX 16
#define PKG_INSTALLED_MAX 16
#define PKG_INSTALLED_VERSIONS_MAX 8
#define PKG_LAUNCH_ARGS_MAX 8
#define PKG_LAUNCH_ARG_MAX 127

/* Caps against a malicious/compromised HTTP server: without these, an
* oversized response can exhaust SD-card space (downloads) or force an
* unbounded single heap allocation sized directly off attacker-controlled
* content (pkg_store_read_text). Text/metadata files (index.jsn,
* instpkg.jsn) are always small; artifact downloads cover the largest
* real payloads seen in practice (a multi-MB WAD, a ~1MB game ELF) with
* generous headroom.
*/

#define PKG_TEXT_MAX_SIZE (256 * 1024)
#define PKG_DOWNLOAD_MAX_SIZE (32 * 1024 * 1024)

/* nxpkg is a one-shot CLI, not a daemon, so a lock file older than this
* cannot belong to a still-running install under normal use (even a full
* multi-MB artifact over a slow link finishes well within this window) -
* it can only be left over from a process that was killed or a device
* that lost power mid-install. Reclaiming it is what makes install/
* update/rollback usable again after the crash/power-loss scenarios this
* target is prone to, instead of failing with EBUSY forever.
*/

#define PKG_LOCK_STALE_SECONDS (600)

static inline void *pkg_malloc(size_t size)
{
return malloc(size);
}

static inline void *pkg_zalloc(size_t size)
{
return calloc(1, size);
}

static inline void *pkg_realloc(void *ptr, size_t size)
{
return realloc(ptr, size);
}

static inline void pkg_free(void *ptr)
{
free(ptr);
}

static inline FAR char *pkg_path_alloc(void)
{
return pkg_malloc(PATH_MAX);
}

/****************************************************************************
* Public Types
Expand Down Expand Up @@ -83,7 +146,12 @@ struct pkg_manifest_s
char compat[PKG_COMPAT_MAX + 1];
char artifact[PATH_MAX];
char sha256[PKG_HASH_HEX_LEN + 1];
char launch_args[PKG_LAUNCH_ARGS_MAX][PKG_LAUNCH_ARG_MAX + 1];
char description[PKG_DESCRIPTION_MAX + 1];
char category[PKG_CATEGORY_MAX + 1];
char icon[PATH_MAX];
enum pkg_payload_type_e type;
size_t launch_argc;
};

struct pkg_index_s
Expand Down Expand Up @@ -116,6 +184,7 @@ struct pkg_installed_db_s

const char *pkg_manifest_type_str(enum pkg_payload_type_e type);
int pkg_manifest_validate(FAR const struct pkg_manifest_s *manifest);
bool pkg_validate_path_component(FAR const char *value);
int pkg_manifest_parse_type(FAR const char *value,
FAR enum pkg_payload_type_e *type);

Expand All @@ -124,6 +193,7 @@ int pkg_store_ensure_package_root(FAR const char *name);
int pkg_store_ensure_version_dir(FAR const char *name,
FAR const char *version);
int pkg_store_format_index_path(FAR char *buffer, size_t size);
int pkg_store_format_repo_source_path(FAR char *buffer, size_t size);
int pkg_store_format_installed_path(FAR char *buffer, size_t size);
int pkg_store_format_package_root(FAR char *buffer, size_t size,
FAR const char *name);
Expand Down Expand Up @@ -152,6 +222,8 @@ int pkg_store_read_text(FAR const char *path, FAR char **buffer);
int pkg_store_write_text_atomic(FAR const char *path, FAR const char *text);
int pkg_store_copy_file(FAR const char *src, FAR const char *dest);
int pkg_store_remove_file(FAR const char *path);
int pkg_store_remove_version_dir(FAR const char *name,
FAR const char *version);

const char *pkg_runtime_arch(void);
const char *pkg_runtime_compat(void);
Expand All @@ -160,7 +232,11 @@ int pkg_compat_check(FAR const struct pkg_manifest_s *manifest);
int pkg_hash_file_sha256(FAR const char *path,
FAR char digest[PKG_HASH_HEX_LEN + 1]);

int pkg_metadata_load_index_path(FAR const char *path,
FAR struct pkg_index_s *index);
int pkg_metadata_load_index(FAR struct pkg_index_s *index);
int pkg_metadata_load_manifest_path(FAR const char *path,
FAR struct pkg_manifest_s *manifest);
FAR const struct pkg_manifest_s *
pkg_metadata_find_latest(FAR const struct pkg_index_s *index,
FAR const char *name);
Expand All @@ -178,7 +254,20 @@ const char *pkg_txn_state_str(enum pkg_txn_state_e state);
int pkg_txn_write_state(FAR const char *name, enum pkg_txn_state_e state);
int pkg_txn_clear_state(FAR const char *name);

bool pkg_source_is_url(FAR const char *source);
int pkg_resolve_artifact_source(FAR char *buffer, size_t size,
FAR const struct pkg_manifest_s *manifest);
int pkg_resolve_icon_source(FAR char *buffer, size_t size,
FAR const struct pkg_manifest_s *manifest);
int pkg_acquire_source(FAR const char *source, FAR const char *dest,
FAR const char *renew_lock_path);
int pkg_lock_create(FAR const char *path);
void pkg_reclaim_stale_lock(FAR const char *path);
int pkg_sync(FAR const char *source);
int pkg_install(FAR const char *name);
int pkg_uninstall(FAR const char *name);
int pkg_rollback(FAR const char *name);
int pkg_available(FAR FILE *stream);
int pkg_list(FAR FILE *stream);

void pkg_error(FAR const char *fmt, ...);
Expand Down
9 changes: 9 additions & 0 deletions system/nxpkg/pkg_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ const char *pkg_runtime_arch(void)

const char *pkg_runtime_compat(void)
{
#ifdef CONFIG_ARCH_BOARD
return CONFIG_ARCH_BOARD;
#elif defined(CONFIG_ARCH_BOARD_CUSTOM_NAME)
if (CONFIG_ARCH_BOARD_CUSTOM_NAME[0] != '\0')
{
return CONFIG_ARCH_BOARD_CUSTOM_NAME;
}
#endif

return "";
}

int pkg_compat_check(FAR const struct pkg_manifest_s *manifest)
Expand Down
Loading
Loading