304-mt7981-generic-reset-button-ignore-env.patch 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --- a/board/mediatek/mt7981/mt7981_rfb.c
  2. +++ b/board/mediatek/mt7981/mt7981_rfb.c
  3. @@ -6,9 +6,16 @@
  4. #include <common.h>
  5. #include <config.h>
  6. +#include <dm.h>
  7. +#include <button.h>
  8. #include <env.h>
  9. #include <init.h>
  10. #include <asm/global_data.h>
  11. +#include <linux/delay.h>
  12. +
  13. +#ifndef CONFIG_RESET_BUTTON_LABEL
  14. +#define CONFIG_RESET_BUTTON_LABEL "reset"
  15. +#endif
  16. #include <mtd.h>
  17. #include <linux/mtd/mtd.h>
  18. @@ -24,7 +31,22 @@ int board_init(void)
  19. int board_late_init(void)
  20. {
  21. - gd->env_valid = 1; //to load environment variable from persistent store
  22. + struct udevice *dev;
  23. +
  24. + gd->env_valid = ENV_VALID;
  25. + if (!button_get_by_label(CONFIG_RESET_BUTTON_LABEL, &dev)) {
  26. + puts("reset button found\n");
  27. +#ifdef CONFIG_RESET_BUTTON_SETTLE_DELAY
  28. + if (CONFIG_RESET_BUTTON_SETTLE_DELAY > 0) {
  29. + button_get_state(dev);
  30. + mdelay(CONFIG_RESET_BUTTON_SETTLE_DELAY);
  31. + }
  32. +#endif
  33. + if (button_get_state(dev) == BUTTON_ON) {
  34. + puts("button pushed, resetting environment\n");
  35. + gd->env_valid = ENV_INVALID;
  36. + }
  37. + }
  38. env_relocate();
  39. return 0;
  40. }