u-boot bootcount functionality

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

u-boot bootcount functionality

跳至解决方案
2,063 次查看
AB22
Contributor III

I have made the following modifications to the u-boot configuration (Yocto Scarthgap/i.MX8M Plus):

CONFIG_BOOTCOUNT=y
CONFIG_BOOTCOUNT_LIMIT=y
CONFIG_BOOTCOUNT_BOOTLIMIT=3

Every time I printenv bootcount at the u-boot prompt, the value is 1. I would like for the bootcount functionality to indicate when to fallback to a working partition during dual-copy update (SWUpdate) in the event the boot process repeatedly fails. What conditions cause the bootcount to increment? I can corrupt files and cause a stall at the u-boot prompt but nothing is providing a mechanism to initiate fallback.

0 项奖励
回复
1 解答
2,029 次查看
Manuel_Salas
NXP TechSupport
NXP TechSupport

Hello @AB22 

I hope you are doing very well.

You can see the bootcount_env.c file under uboot-imx/drivers/bootcount.

// SPDX-License-Identifier: GPL-2.0+
/*
 * (C) Copyright 2013
 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
 */

#include <common.h>
#include <env.h>

void bootcount_store(ulong a)
{
	int upgrade_available = env_get_ulong("upgrade_available", 10, 0);

	if (upgrade_available) {
		env_set_ulong("bootcount", a);
		env_save();
	}
}

ulong bootcount_load(void)
{
	int upgrade_available = env_get_ulong("upgrade_available", 10, 0);
	ulong val = 0;

	if (upgrade_available)
		val = env_get_ulong("bootcount", 10, 0);

	return val;
}
 

You need to set the environment variable called upgrade_available on your U-boot.

u-boot=> setenv upgrade_available 1

 

After reset:

u-boot=> printenv bootcount
bootcount=2
 

I hope this can helps to you.

 

Best regards,

Salas.

 

在原帖中查看解决方案

0 项奖励
回复
4 回复数
2,030 次查看
Manuel_Salas
NXP TechSupport
NXP TechSupport

Hello @AB22 

I hope you are doing very well.

You can see the bootcount_env.c file under uboot-imx/drivers/bootcount.

// SPDX-License-Identifier: GPL-2.0+
/*
 * (C) Copyright 2013
 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
 */

#include <common.h>
#include <env.h>

void bootcount_store(ulong a)
{
	int upgrade_available = env_get_ulong("upgrade_available", 10, 0);

	if (upgrade_available) {
		env_set_ulong("bootcount", a);
		env_save();
	}
}

ulong bootcount_load(void)
{
	int upgrade_available = env_get_ulong("upgrade_available", 10, 0);
	ulong val = 0;

	if (upgrade_available)
		val = env_get_ulong("bootcount", 10, 0);

	return val;
}
 

You need to set the environment variable called upgrade_available on your U-boot.

u-boot=> setenv upgrade_available 1

 

After reset:

u-boot=> printenv bootcount
bootcount=2
 

I hope this can helps to you.

 

Best regards,

Salas.

 

0 项奖励
回复
2,026 次查看
AB22
Contributor III
Thank you for pointing me to that file. It is quite helpful.
2,044 次查看
xacov
Contributor I

It should not be a question. 

 

 
 
 
config BOOTCOUNT_ENV
bool "Boot counter in environment"
help
  If no softreset save registers are found on the hardware
  "bootcount" is stored in the environment. To prevent a
  saveenv on all reboots, the environment variable
  "upgrade_available" is used. If "upgrade_available" is
  0, "bootcount" is always 0. If "upgrade_available" is 1,
          "bootcount" is incremented in the environment.
  So the Userspace Application must set the "upgrade_available"
  and "bootcount" variables to 0, if the system booted successfully.

 

0 项奖励
回复
2,025 次查看
AB22
Contributor III
That is quite helpful. I misunderstood the usage of upgrade_available. Thank you.
0 项奖励
回复
%3CLINGO-SUB%20id%3D%22lingo-sub-2035853%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3Eu-boot%20bootcount%E5%8A%9F%E8%83%BD%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2035853%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E6%88%91%E5%AF%B9%20u-boot%20%E9%85%8D%E7%BD%AE%EF%BC%88Yocto%20Scarthgap%2Fi.MX8M%20Plus%EF%BC%89%E5%81%9A%E4%BA%86%E4%BB%A5%E4%B8%8B%E4%BF%AE%E6%94%B9%EF%BC%9A%3C%2FP%3E%3CP%3ECONFIG_BOOTCOUNT%3Dy%3CBR%20%2F%3E%20CONFIG_BOOTCOUNT_LIMIT%3Dy%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E%3CLINGO-LABS%20id%3D%22lingo-labs-2035853%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3Ei.MX%208%20%E7%B3%BB%E5%88%97%20%7C%20i.MX%208QuadMax%20(8QM)%20%7C%208QuadPlus%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EYocto%20Project%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2036228%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9Au-boot%20bootcount%E5%8A%9F%E8%83%BD%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2036228%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E8%BF%99%E9%9D%9E%E5%B8%B8%E6%9C%89%E5%B8%AE%E5%8A%A9%E3%80%82%E6%88%91%E8%AF%AF%E8%A7%A3%E4%BA%86upgrade_available%E7%9A%84%E7%94%A8%E6%B3%95%E3%80%82%E8%B0%A2%E8%B0%A2%E3%80%82%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2036227%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9Au-boot%20bootcount%E5%8A%9F%E8%83%BD%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2036227%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E6%84%9F%E8%B0%A2%E6%82%A8%E5%90%91%E6%88%91%E6%8C%87%E5%87%BA%E8%AF%A5%E6%96%87%E4%BB%B6%E3%80%82%E8%BF%99%E5%BE%88%E6%9C%89%E5%B8%AE%E5%8A%A9%E3%80%82%3C%2FLINGO-BODY%3E