Skip to content

Commit

Permalink
STASH
Browse files Browse the repository at this point in the history
  • Loading branch information
d4nuu8 committed Jan 22, 2025
1 parent 41f4174 commit e6fc197
Show file tree
Hide file tree
Showing 36 changed files with 627 additions and 475 deletions.
11 changes: 11 additions & 0 deletions HACKING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Hacking SWUpdate

## Building

To build SWUpdate form source run the following commands:

```sh
$ meson setup .build
$ meson compile -C .build
$ meson test -C .build
```
31 changes: 18 additions & 13 deletions bindings/meson.build
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
if kconfig.has_key('CONFIG_LUA')
core_libs += shared_library(
'swupdate',
['auxiliar.c', 'lua_swupdate.c', 'lua_compat_shared.c'],
name_prefix: 'lua_',
include_directories: include_dirs,
dependencies: lua_dependency,
link_with: ipc_lib,
implicit_include_directories: false,
install: true,
install_dir: get_option('libdir') / 'lua'
+ lua_dependency.get_variable('major_version'),
version: '0.1',
)
core_libs += shared_library(
'swupdate',
['auxiliar.c', 'lua_swupdate.c', 'lua_compat_shared.c'],
name_prefix: 'lua_',
include_directories: include_dirs,
dependencies: lua_dependency,
link_with: ipc_lib,
implicit_include_directories: false,
install: true,
install_dir: get_option('datadir') / 'lua' / lua_dependency.get_variable(
'major_version',
default_value: lua_dependency.get_variable(
'abiver',
default_value: '',
),
),
version: '0.1',
)
endif
46 changes: 23 additions & 23 deletions bootloader/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,50 @@ sources = []
dependencies = []

if kconfig.has_key('CONFIG_UBOOT')
sources += 'uboot.c'
sources += 'uboot.c'
endif

if kconfig.has_key('CONFIG_BOOTLOADER_NONE')
sources += 'none.c'
sources += 'none.c'
endif

if kconfig.has_key('CONFIG_BOOTLOADER_GRUB')
sources += 'grub.c'
# TODO Use dependency() as soon as meson 0.62 can be used
dependencies += cc.find_library('dl', required: true)
sources += 'grub.c'
# TODO Use dependency() as soon as meson 0.62 can be used
dependencies += cc.find_library('dl', required: true)
endif

if kconfig.has_key('CONFIG_BOOTLOADER_EBG')
sources += 'ebg.c'
sources += 'ebg.c'

if kconfig.has_key('CONFIG_BOOTLOADER_STATIC_LINKED')
dependencies += dependency('libebgenv', required: true)
endif
if kconfig.has_key('CONFIG_BOOTLOADER_STATIC_LINKED')
dependencies += dependency('libebgenv', required: true)
endif
endif

if kconfig.has_key('CONFIG_BOOTLOADER_CBOOT')
sources += 'cboot.c'
sources += 'cboot.c'

if kconfig.has_key('CONFIG_BOOTLOADER_STATIC_LINKED')
dependencies += dependency('tegra-boot-tools', required: true)
endif
if kconfig.has_key('CONFIG_BOOTLOADER_STATIC_LINKED')
dependencies += dependency('tegra-boot-tools', required: true)
endif
endif

if not kconfig.has_key('CONFIG_BOOTLOADER_STATIC_LINKED')
# TODO Use dependency() as soon as meson 0.62 can be used
dependencies += cc.find_library('dl', required: true)
# TODO Use dependency() as soon as meson 0.62 can be used
dependencies += cc.find_library('dl', required: true)
endif

if sources.length() == 0
sources += 'none.c'
sources += 'none.c'
endif

if sources.length() != 0
core_libs += static_library(
'bootloader',
sources,
include_directories: include_dirs,
dependencies: dependencies,
implicit_include_directories: false,
)
core_libs += static_library(
'bootloader',
sources,
include_directories: include_dirs,
dependencies: dependencies,
implicit_include_directories: false,
)
endif
9 changes: 6 additions & 3 deletions ci/test-configs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
# SPDX-License-Identifier: GPL-2.0-only
set -eu

REPO_ROOT="$(git rev-parse --show-toplevel)"

find configs -type f | while read -r fname; do
echo "*** Testing config: $fname"
make "$(basename "$fname")"
make "-j$(nproc)"
make tests
"${REPO_ROOT}/scripts/KConfiglib/defconfig.py" "$fname"
meson setup .build
meson compile -C .build
meson test -C .build
done
16 changes: 8 additions & 8 deletions containers/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ sources = []
dependencies = []

if kconfig.has_key('CONFIG_DOCKER')
sources += 'docker.c'
sources += 'docker.c'
endif

if sources.length() != 0
core_libs += static_library(
'containers',
sources,
include_directories: include_dirs,
dependencies: dependencies,
implicit_include_directories: false,
)
core_libs += static_library(
'containers',
sources,
include_directories: include_dirs,
dependencies: dependencies,
implicit_include_directories: false,
)
endif
17 changes: 9 additions & 8 deletions core/installer.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "bootloader.h"
#include "progress.h"
#include "pctl.h"
#include "swupdate_config.h"
#include "swupdate_vars.h"
#include "lua_util.h"

Expand Down Expand Up @@ -584,30 +585,30 @@ void cleanup_files(struct swupdate_cfg *software) {
#endif
}

int preupdatecmd(struct swupdate_cfg *swcfg)
int preupdatecmd(struct swupdate_cfg *config)
{
if (swcfg) {
if (swcfg->parms.dry_run) {
if (config) {
if (config->parms.dry_run) {
DEBUG("Dry run, skipping Pre-update command");
} else {
DEBUG("Running Pre-update command");
return run_system_cmd(swcfg->preupdatecmd);
return run_system_cmd(config->preupdatecmd);
}
}

return 0;
}

int postupdate(struct swupdate_cfg *swcfg, const char *info)
int postupdate(struct swupdate_cfg *config, const char *info)
{
swupdate_progress_done(info);

if (swcfg) {
if (swcfg->parms.dry_run) {
if (config) {
if (config->parms.dry_run) {
DEBUG("Dry run, skipping Post-update command");
} else {
DEBUG("Running Post-update command");
return run_system_cmd(swcfg->postupdatecmd);
return run_system_cmd(config->postupdatecmd);
}

}
Expand Down
80 changes: 43 additions & 37 deletions core/meson.build
Original file line number Diff line number Diff line change
@@ -1,59 +1,65 @@
sources = [
'semver.c',
'strlcpy.c',
'syslog.c',
'bootloader.c',
'state.c',
'network_utils.c',
'hw-compatibility.c',
'install_from_file.c',
'notifier.c',
'pctl.c',
'progress_thread.c',
'swupdate_dict.c',
'artifacts_versions.c',
'cpio_utils.c',
'handler.c',
'installer.c',
'network_thread.c',
'parser.c',
'parsing_library.c',
'stream_interface.c',
'swupdate.c',
'swupdate_vars.c',
'util.c',
'semver.c',
'strlcpy.c',
'syslog.c',
'bootloader.c',
'state.c',
'network_utils.c',
'hw-compatibility.c',
'install_from_file.c',
'notifier.c',
'pctl.c',
'progress_thread.c',
'swupdate_dict.c',
'artifacts_versions.c',
'cpio_utils.c',
'handler.c',
'installer.c',
'network_thread.c',
'parser.c',
'parsing_library.c',
'stream_interface.c',
'swupdate_vars.c',
'util.c',
]

ubootenv_lib = cc.find_library('ubootenv', required: true)

dependencies = [json_dep, ubootenv_lib]

if kconfig.has_key('CONFIG_GUNZIP')
dependencies += dependency('zlib', required: true)
dependencies += dependency('zlib', required: true)
endif

if kconfig.has_key('CONFIG_PKCS11')
dependencies += dependency('p11-kit-1', required: true)
dependencies += dependency('p11-kit-1', required: true)
endif

if kconfig.has_key('CONFIG_ZSTD')
dependencies += dependency('libzstd', required: true)
dependencies += dependency('libzstd', required: true)
endif

if kconfig.has_key('CONFIG_SYSTEMD')
dependencies += dependency('libsystemd', required: true)
dependencies += dependency('libsystemd', required: true)
endif

if kconfig.has_key('CONFIG_LUA')
dependencies += lua_dependency
endif
dependencies += lua_dependency

swupdatelib = static_library(
'swupdate',
sources,
include_directories: include_dirs,
dependencies: dependencies,
link_with: core_libs,
link_args: link_args,
implicit_include_directories: false,
)

executable(
'swupdate',
sources,
include_directories: include_dirs,
dependencies: dependencies,
link_with: core_libs,
link_args: link_args,
install: true,
'swupdate',
'swupdate.c',
include_directories: include_dirs,
dependencies: dependencies,
link_with: swupdatelib,
install: true,
)
1 change: 1 addition & 0 deletions core/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "util.h"
#include "progress.h"
#include "handler.h"
#include "swupdate_config.h"

static parser_fn parsers[] = {
parse_cfg,
Expand Down
24 changes: 2 additions & 22 deletions core/swupdate.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "versions.h"
#include "hw-compatibility.h"
#include "swupdate_vars.h"
#include "swupdate_config.h"

#ifdef CONFIG_SYSTEMD
#include <systemd/sd-daemon.h>
Expand All @@ -62,20 +63,6 @@
static pthread_t network_daemon;

/* Tree derived from the configuration file */
static struct swupdate_cfg swcfg;

int loglevel = ERRORLEVEL;
int exit_code = EXIT_SUCCESS;

#ifdef CONFIG_MTD
/* Global MTD configuration */
static struct flash_description flashdesc;

struct flash_description *get_flash_info(void) {
return &flashdesc;
}
#endif

static struct option long_options[] = {
{"accepted-select", required_argument, NULL, 'q'},
#ifdef CONFIG_UBIATTACH
Expand Down Expand Up @@ -144,7 +131,7 @@ static void usage(char *programname)
" -P, --preupdate : execute pre-update command\n"
" -e, --select <software>,<mode> : Select software images set and source\n"
" Ex.: stable,main\n"
" -g, --get-root : detect and print the root device and exit\n"
" -g, --get-root : detect and print the root device and exit\n"
" -E, --get-emmc-boot <device> : read the boot partition (CSD register) for a /dev/mmcblkX device\n"
" -q, --accepted-select\n"
" <software>,<mode> : List for software images set and source\n"
Expand Down Expand Up @@ -202,10 +189,6 @@ static void usage(char *programname)
#endif
}

struct swupdate_cfg *get_swupdate_cfg(void) {
return &swcfg;
}

/*
* Extract board and revision number from command line
* The parameter is in the format <board>:<revision>
Expand Down Expand Up @@ -477,9 +460,6 @@ int main(int argc, char **argv)
char **dwlav = NULL;
int dwlac = 0;

#ifdef CONFIG_MTD
memset(&flashdesc, 0, sizeof(flashdesc));
#endif
memset(main_options, 0, sizeof(main_options));
memset(image_url, 0, sizeof(image_url));
strcpy(main_options, "vhni:e:E:gq:l:Lcf:p:P:o:s:N:R:MmB:");
Expand Down
3 changes: 3 additions & 0 deletions core/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ static char *fwenv_config = NULL;
static char* TMPDIR = NULL;
static char* TMPDIRSCRIPT = NULL;

int loglevel = ERRORLEVEL;
int exit_code = EXIT_SUCCESS;

/*
* Convert a hash as hexa string into a sequence of bytes
* hash must be an array of 32 bytes as specified by SHA256
Expand Down
3 changes: 2 additions & 1 deletion corelib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
lib-y += emmc_utils.o \
multipart_parser.o \
parsing_library_libjson.o \
server_utils.o
server_utils.o \
swupdate_settings.o
lib-$(CONFIG_DOWNLOAD) += downloader.o
lib-$(CONFIG_MTD) += mtd-interface.o
lib-$(CONFIG_LUA) += lua_interface.o lua_compat.o
Expand Down
Loading

0 comments on commit e6fc197

Please sign in to comment.