u-boot bootcount functionality

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

u-boot bootcount functionality

Jump to solution
1,468 Views
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 Kudos
Reply
1 Solution
1,434 Views
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.

 

View solution in original post

0 Kudos
Reply
4 Replies
1,435 Views
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 Kudos
Reply
1,431 Views
AB22
Contributor III
Thank you for pointing me to that file. It is quite helpful.
1,449 Views
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 Kudos
Reply
1,430 Views
AB22
Contributor III
That is quite helpful. I misunderstood the usage of upgrade_available. Thank you.
0 Kudos
Reply