Closed Qbicz closed 5 years ago
I wonder what's going on here. Bluetooth writes to flash only through the settings API, so the corruption would have to happen on some lower level. Is it really a good policy to have settings assert, instead of throwing an error, when encountering corrupted flash content?
Can be reproduced every time.
@jhedberg I agree asserting here is unfortunate. If we ignore such error, the previous record will be used, if any was valid before (am I correct?).
It may also be an effect of Bluetooth host writing something incorrect.
@jhedberg, @Qbicz: It is unfortunate that an assert is triggered, this is triggered if there is a record in flash that has no set handler. As a result it is not possible to store data on the flash that is not related to settings. However, in this case it is an advantage because there definitely is something wrong with what is written to settings by the bluetooth module:
[02454268] <dbg> bt_settings.bt_settings_encode_key: Encoded path �m
This is written after the disconnect and is clearly wrong.
[02454268] <dbg> bt_settings.bt_settings_encode_key: Encoded path �m
This is written after the disconnect and is clearly wrong.
@Laczen are you sure that's not just a missing log_strdup() call? Ever since we moved to deferred logging trying to log any on-stack strings will give you garbage like that, since by the time the logger thread processes the message the string is already out of scope.
@Laczen I just looked at the code and bt_settings_encode_key() is indeed missing a log_strdup(). So this corrupted string is a red herring, I think, i.e. probably safe to ignore (someone should submit a PR to add the log_strdup though).
@Laczen I created #13612 which should fix the corrupted string in the logs.
@jhedberg, OK, I really dislike this deferred logging. So it seems that it is failing on restoring "cf", this was the last thing stored but is not restored.
@jhedberg, in gatt.c: bt_gatt_store_cf()
&conn->le.dst
is used to store the key, is it guaranteed that this is a string that does not contain the separation \
?
@jhedberg, it might be something else: in bt_gatt_store_cf
key is not given a value if (!cfg)
, so what is stored? Should key be set to "bt/cf"
?
@Laczen thanks for finding that! This is indeed caused by cf
which was introduced as a new Bluetooth 5.1 feature in aecf7c7076. I confirm that initializing key
with "bt/cf/address"
or "bt/cf"
solves this particular problem.
FYI @Vudentz
Describe the bug Bluetooth host cannot load the values it previously stored in settings. After wake up or reset, it asserts with
set-value operation failure
. Insettings_set_value_priv()
,settings_parse_and_lookup()
fails and-EINVAL
is returned (-22
).Similar problem has been previously fixed in https://github.com/zephyrproject-rtos/zephyr/pull/11576, but now it happens again.
To Reproduce
ASSERTION FAIL [rc == 0]
Environment (please complete the following information):