Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
System Manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
system
System Manager
Commits
711ed361
Commit
711ed361
authored
4 months ago
by
Amin Ben Romdhane
Browse files
Options
Downloads
Patches
Plain Diff
Store keep_config option under '/var/state'
parent
25cf2cbf
No related branches found
No related tags found
1 merge request
!27
Store keep_config option under '/var/state'
Pipeline
#196854
passed
4 months ago
Stage: static_code_analysis
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/files/usr/share/bbfdm/scripts/bbf_activate_handler.sh
+14
-4
14 additions, 4 deletions
src/files/usr/share/bbfdm/scripts/bbf_activate_handler.sh
src/fw_images.c
+47
-11
47 additions, 11 deletions
src/fw_images.c
with
61 additions
and
15 deletions
src/files/usr/share/bbfdm/scripts/bbf_activate_handler.sh
+
14
−
4
View file @
711ed361
...
@@ -19,6 +19,7 @@ log() {
...
@@ -19,6 +19,7 @@ log() {
activate_and_reboot_device
()
{
activate_and_reboot_device
()
{
local
bank_id
=
"
${
1
}
"
local
bank_id
=
"
${
1
}
"
local
keep_config
=
"
${
2
}
"
local
success
local
success
success
=
$(
ubus call fwbank set_bootbank
"{'bank':
${
bank_id
}
}"
| jsonfilter
-e
@.success
)
success
=
$(
ubus call fwbank set_bootbank
"{'bank':
${
bank_id
}
}"
| jsonfilter
-e
@.success
)
...
@@ -27,6 +28,14 @@ activate_and_reboot_device() {
...
@@ -27,6 +28,14 @@ activate_and_reboot_device() {
exit
1
exit
1
fi
fi
if
[
"
${
keep_config
}
"
=
"1"
]
;
then
success
=
$(
/etc/sysmngr/fwbank call copy_config 2> /dev/null | jsonfilter
-e
@.success
)
if
[
"
${
success
}
"
!=
"true"
]
;
then
log
"Can't copy config"
exit
1
fi
fi
log
"The device will restart after a few seconds"
log
"The device will restart after a few seconds"
ubus call rpc-sys reboot
ubus call rpc-sys reboot
exit
0
exit
0
...
@@ -36,6 +45,7 @@ handle_whenidle_mode() {
...
@@ -36,6 +45,7 @@ handle_whenidle_mode() {
local
bank_id
=
"
${
1
}
"
local
bank_id
=
"
${
1
}
"
local
end_time
=
"
${
2
}
"
local
end_time
=
"
${
2
}
"
local
force_activation
=
"
${
3
}
"
local
force_activation
=
"
${
3
}
"
local
keep_config
=
"
${
4
}
"
local
diff
=
0
local
diff
=
0
[
!
-x
"
${
CHECK_IDLE_FILE
}
"
]
&&
{
[
!
-x
"
${
CHECK_IDLE_FILE
}
"
]
&&
{
...
@@ -71,7 +81,7 @@ handle_whenidle_mode() {
...
@@ -71,7 +81,7 @@ handle_whenidle_mode() {
done
done
[
"
${
force_activation
}
"
=
"1"
]
&&
{
[
"
${
force_activation
}
"
=
"1"
]
&&
{
activate_and_reboot_device
"
${
bank_id
}
"
activate_and_reboot_device
"
${
bank_id
}
"
"
${
keep_config
}
"
}
}
}
}
...
@@ -83,11 +93,11 @@ handle_confirmation_needed_mode() {
...
@@ -83,11 +93,11 @@ handle_confirmation_needed_mode() {
######################## main ########################
######################## main ########################
if
[
"
${
MODE
}
"
=
"Immediately"
]
||
[
"
${
MODE
}
"
=
"AnyTime"
]
;
then
if
[
"
${
MODE
}
"
=
"Immediately"
]
||
[
"
${
MODE
}
"
=
"AnyTime"
]
;
then
activate_and_reboot_device
"
${
2
}
"
activate_and_reboot_device
"
${
2
}
"
"
${
7
}
"
elif
[
"
${
MODE
}
"
=
"WhenIdle"
]
;
then
elif
[
"
${
MODE
}
"
=
"WhenIdle"
]
;
then
handle_whenidle_mode
"
${
2
}
"
"
${
3
}
"
"
${
4
}
"
handle_whenidle_mode
"
${
2
}
"
"
${
3
}
"
"
${
4
}
"
"
${
7
}
"
elif
[
"
${
MODE
}
"
=
"ConfirmationNeeded"
]
;
then
elif
[
"
${
MODE
}
"
=
"ConfirmationNeeded"
]
;
then
handle_confirmation_needed_mode
"
${
2
}
"
"
${
3
}
"
"
${
4
}
"
"
${
5
}
"
"
${
6
}
"
handle_confirmation_needed_mode
"
${
2
}
"
"
${
3
}
"
"
${
4
}
"
"
${
5
}
"
"
${
6
}
"
"
${
7
}
"
else
else
log
"[
${
MODE
}
] mode is not supported"
log
"[
${
MODE
}
] mode is not supported"
exit
1
exit
1
...
...
This diff is collapsed.
Click to expand it.
src/fw_images.c
+
47
−
11
View file @
711ed361
...
@@ -12,13 +12,16 @@
...
@@ -12,13 +12,16 @@
#include
"utils.h"
#include
"utils.h"
#include
"fwbank.h"
#include
"fwbank.h"
#define MAX_TIME_WINDOW 5
struct
sysupgrade_ev_data
{
struct
sysupgrade_ev_data
{
const
char
*
bank_id
;
const
char
*
bank_id
;
bool
status
;
bool
status
;
};
};
#define CRONTABS_ROOT "/etc/crontabs/root"
#define ACTIVATE_HANDLER_FILE "/usr/share/bbfdm/scripts/bbf_activate_handler.sh"
#define COPY_CONFIG_CMD "/etc/sysmngr/fwbank call copy_config 2> /dev/null"
#define MAX_TIME_WINDOW 5
/*************************************************************
/*************************************************************
* COMMON FUNCTIONS
* COMMON FUNCTIONS
**************************************************************/
**************************************************************/
...
@@ -92,7 +95,25 @@ static char *get_fwbank_bank_id(const char *option_name)
...
@@ -92,7 +95,25 @@ static char *get_fwbank_bank_id(const char *option_name)
return
bank_id
?
bank_id
:
""
;
return
bank_id
?
bank_id
:
""
;
}
}
static
bool
fwbank_set_bootbank
(
char
*
bank_id
)
static
struct
uci_section
*
is_varstate_section_exist
(
const
char
*
package
,
const
char
*
section
)
{
struct
uci_section
*
s
=
NULL
;
uci_path_foreach_sections
(
varstate
,
package
,
section
,
s
)
{
return
s
;
}
return
NULL
;
}
static
void
fwbank_copy_config
(
void
)
{
char
output
[
64
]
=
{
0
};
run_cmd
(
COPY_CONFIG_CMD
,
output
,
sizeof
(
output
));
}
static
bool
fwbank_set_bootbank
(
const
char
*
bank_id
)
{
{
int
res
=
sysmngr_fwbank_set_bootbank
((
uint32_t
)
DM_STRTOUL
(
bank_id
),
NULL
);
int
res
=
sysmngr_fwbank_set_bootbank
((
uint32_t
)
DM_STRTOUL
(
bank_id
),
NULL
);
...
@@ -102,7 +123,7 @@ static bool fwbank_set_bootbank(char *bank_id)
...
@@ -102,7 +123,7 @@ static bool fwbank_set_bootbank(char *bank_id)
static
bool
fwbank_upgrade
(
const
char
*
path
,
const
char
*
auto_activate
,
const
char
*
bank_id
,
const
char
*
keep_settings
)
static
bool
fwbank_upgrade
(
const
char
*
path
,
const
char
*
auto_activate
,
const
char
*
bank_id
,
const
char
*
keep_settings
)
{
{
json_object
*
json_obj
=
NULL
;
json_object
*
json_obj
=
NULL
;
int
res
=
0
;
bool
res
=
false
;
dmubus_call_blocking
(
"fwbank"
,
"upgrade"
,
UBUS_ARGS
{{
"path"
,
path
,
String
},
{
"auto_activate"
,
auto_activate
,
Boolean
},
{
"bank"
,
bank_id
,
Integer
},
{
"keep_settings"
,
keep_settings
,
Boolean
}},
4
,
&
json_obj
);
dmubus_call_blocking
(
"fwbank"
,
"upgrade"
,
UBUS_ARGS
{{
"path"
,
path
,
String
},
{
"auto_activate"
,
auto_activate
,
Boolean
},
{
"bank"
,
bank_id
,
Integer
},
{
"keep_settings"
,
keep_settings
,
Boolean
}},
4
,
&
json_obj
);
...
@@ -533,6 +554,7 @@ static int operate_DeviceInfoFirmwareImage_Download(char *refparam, struct dmctx
...
@@ -533,6 +554,7 @@ static int operate_DeviceInfoFirmwareImage_Download(char *refparam, struct dmctx
{
{
const
char
*
command
=
"Download()"
;
const
char
*
command
=
"Download()"
;
char
obj_path
[
256
]
=
{
0
};
char
obj_path
[
256
]
=
{
0
};
char
*
keep_config
=
NULL
;
char
*
ret
=
DM_STRRCHR
(
refparam
,
'.'
);
char
*
ret
=
DM_STRRCHR
(
refparam
,
'.'
);
if
(
!
ret
)
if
(
!
ret
)
...
@@ -557,9 +579,17 @@ static int operate_DeviceInfoFirmwareImage_Download(char *refparam, struct dmctx
...
@@ -557,9 +579,17 @@ static int operate_DeviceInfoFirmwareImage_Download(char *refparam, struct dmctx
char
*
checksum_algorithm
=
dmjson_get_value
((
json_object
*
)
value
,
1
,
"CheckSumAlgorithm"
);
char
*
checksum_algorithm
=
dmjson_get_value
((
json_object
*
)
value
,
1
,
"CheckSumAlgorithm"
);
char
*
checksum
=
dmjson_get_value
((
json_object
*
)
value
,
1
,
"CheckSum"
);
char
*
checksum
=
dmjson_get_value
((
json_object
*
)
value
,
1
,
"CheckSum"
);
char
*
commandKey
=
dmjson_get_value
((
json_object
*
)
value
,
1
,
"CommandKey"
);
char
*
commandKey
=
dmjson_get_value
((
json_object
*
)
value
,
1
,
"CommandKey"
);
char
*
keep_config
=
NULL
;
#ifdef SYSMNGR_VENDOR_EXTENSIONS
#ifdef SYSMNGR_VENDOR_EXTENSIONS
keep_config
=
dmjson_get_value
((
json_object
*
)
value
,
1
,
CUSTOM_PREFIX
"KeepConfig"
);
keep_config
=
dmjson_get_value
((
json_object
*
)
value
,
1
,
CUSTOM_PREFIX
"KeepConfig"
);
bool
keep
=
DM_STRLEN
(
keep_config
)
?
dmuci_string_to_boolean
(
keep_config
)
:
true
;
struct
uci_section
*
s
=
is_varstate_section_exist
(
"sysmngr"
,
"globals"
);
if
(
!
s
)
dmuci_add_section_varstate
(
"sysmngr"
,
"globals"
,
&
s
);
dmuci_set_value_by_section_varstate
(
s
,
"keep_config"
,
keep
?
"1"
:
"0"
);
dmuci_commit_package_varstate
(
"sysmngr"
);
#endif
#endif
char
*
bank_id
=
get_fwbank_option_value
(
data
,
"id"
);
char
*
bank_id
=
get_fwbank_option_value
(
data
,
"id"
);
...
@@ -574,7 +604,6 @@ static int operate_DeviceInfoFirmwareImage_Download(char *refparam, struct dmctx
...
@@ -574,7 +604,6 @@ static int operate_DeviceInfoFirmwareImage_Download(char *refparam, struct dmctx
static
operation_args
firmware_image_activate_args
=
{
static
operation_args
firmware_image_activate_args
=
{
.
in
=
(
const
char
*
[])
{
.
in
=
(
const
char
*
[])
{
"TimeWindow.{i}.Start"
,
"TimeWindow.{i}.Start"
,
"TimeWindow.{i}.End"
,
"TimeWindow.{i}.End"
,
"TimeWindow.{i}.Mode"
,
"TimeWindow.{i}.Mode"
,
...
@@ -592,17 +621,20 @@ static int get_operate_args_DeviceInfoFirmwareImage_Activate(char *refparam, str
...
@@ -592,17 +621,20 @@ static int get_operate_args_DeviceInfoFirmwareImage_Activate(char *refparam, str
static
int
operate_DeviceInfoFirmwareImage_Activate
(
char
*
refparam
,
struct
dmctx
*
ctx
,
void
*
data
,
char
*
instance
,
char
*
value
,
int
action
)
static
int
operate_DeviceInfoFirmwareImage_Activate
(
char
*
refparam
,
struct
dmctx
*
ctx
,
void
*
data
,
char
*
instance
,
char
*
value
,
int
action
)
{
{
#define CRONTABS_ROOT "/etc/crontabs/root"
#define ACTIVATE_HANDLER_FILE "/usr/share/bbfdm/scripts/bbf_activate_handler.sh"
char
*
FW_Mode
[]
=
{
"AnyTime"
,
"Immediately"
,
"WhenIdle"
,
"ConfirmationNeeded"
,
NULL
};
char
*
FW_Mode
[]
=
{
"AnyTime"
,
"Immediately"
,
"WhenIdle"
,
"ConfirmationNeeded"
,
NULL
};
char
*
start_time
[
MAX_TIME_WINDOW
]
=
{
0
};
char
*
start_time
[
MAX_TIME_WINDOW
]
=
{
0
};
char
*
end_time
[
MAX_TIME_WINDOW
]
=
{
0
};
char
*
end_time
[
MAX_TIME_WINDOW
]
=
{
0
};
char
*
mode
[
MAX_TIME_WINDOW
]
=
{
0
};
char
*
mode
[
MAX_TIME_WINDOW
]
=
{
0
};
char
*
user_message
[
MAX_TIME_WINDOW
]
=
{
0
};
char
*
user_message
[
MAX_TIME_WINDOW
]
=
{
0
};
char
*
max_retries
[
MAX_TIME_WINDOW
]
=
{
0
};
char
*
max_retries
[
MAX_TIME_WINDOW
]
=
{
0
};
char
*
keep_config
=
NULL
;
int
res
=
0
,
last_idx
=
-
1
;
int
res
=
0
,
last_idx
=
-
1
;
dmuci_get_option_value_string_varstate
(
"sysmngr"
,
"globals"
,
"keep_config"
,
&
keep_config
);
if
(
DM_STRLEN
(
keep_config
)
==
0
)
{
keep_config
=
dmstrdup
(
"1"
);
}
for
(
int
i
=
0
;
i
<
MAX_TIME_WINDOW
;
i
++
)
{
for
(
int
i
=
0
;
i
<
MAX_TIME_WINDOW
;
i
++
)
{
char
buf
[
32
]
=
{
0
};
char
buf
[
32
]
=
{
0
};
...
@@ -666,7 +698,7 @@ static int operate_DeviceInfoFirmwareImage_Activate(char *refparam, struct dmctx
...
@@ -666,7 +698,7 @@ static int operate_DeviceInfoFirmwareImage_Activate(char *refparam, struct dmctx
t_time
+=
start_t
;
t_time
+=
start_t
;
struct
tm
*
tm_local
=
localtime
(
&
t_time
);
struct
tm
*
tm_local
=
localtime
(
&
t_time
);
snprintf
(
buffer
,
sizeof
(
buffer
),
"%d %d %d %d * sh %s '%s' '%s' '%ld' '%d' '%s' '%s'
\n
"
,
snprintf
(
buffer
,
sizeof
(
buffer
),
"%d %d %d %d * sh %s '%s' '%s' '%ld' '%d' '%s'
'%s'
'%s'
\n
"
,
tm_local
->
tm_min
,
tm_local
->
tm_min
,
tm_local
->
tm_hour
,
tm_local
->
tm_hour
,
tm_local
->
tm_mday
,
tm_local
->
tm_mday
,
...
@@ -677,7 +709,8 @@ static int operate_DeviceInfoFirmwareImage_Activate(char *refparam, struct dmctx
...
@@ -677,7 +709,8 @@ static int operate_DeviceInfoFirmwareImage_Activate(char *refparam, struct dmctx
(
DM_STRTOL
(
end_time
[
i
])
-
DM_STRTOL
(
start_time
[
i
])),
(
DM_STRTOL
(
end_time
[
i
])
-
DM_STRTOL
(
start_time
[
i
])),
(
i
==
last_idx
),
(
i
==
last_idx
),
user_message
[
i
],
user_message
[
i
],
max_retries
[
i
]);
max_retries
[
i
],
keep_config
);
fprintf
(
file
,
"%s"
,
buffer
);
fprintf
(
file
,
"%s"
,
buffer
);
}
}
...
@@ -689,6 +722,9 @@ static int operate_DeviceInfoFirmwareImage_Activate(char *refparam, struct dmctx
...
@@ -689,6 +722,9 @@ static int operate_DeviceInfoFirmwareImage_Activate(char *refparam, struct dmctx
if
(
!
fwbank_set_bootbank
(
bank_id
))
if
(
!
fwbank_set_bootbank
(
bank_id
))
return
USP_FAULT_COMMAND_FAILURE
;
return
USP_FAULT_COMMAND_FAILURE
;
if
(
DM_STRCMP
(
keep_config
,
"1"
)
==
0
)
fwbank_copy_config
();
bbfdm_task_fork
(
_exec_reboot
,
NULL
,
NULL
,
NULL
);
bbfdm_task_fork
(
_exec_reboot
,
NULL
,
NULL
,
NULL
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment