Tips : A20 Disable autostart and fix reboot when shutdown

Started by splite, September 11, 2015, 02:55:30 PM

Previous topic - Next topic

splite

Hey all !

I'm using a Lime2 board and I have been looking for a while how to fix the auto-start bug when AC plug is in and when using a battery pack. Furthermore I was looking how to fix the bug when you ask the board to shutdown and in fact the board was just rebooting by itself.

I did not use the Olimex Debian image but I found an other image from Igor Pečovnik, have a look at his website : http://www.igorpecovnik.com/ and http://www.armbian.com/

So below is what I did to fix those to bugs :

In order to apply the fix to U-Boot, the easiest method is to use Igor's script from github.
The best way to compile your U-boot is to do it on a virtual machine, fellow the instruction here : http://www.armbian.com/github/
Before lunching the compile.sh script fellow the instruction below to apply the patch


  • Modify KERNEL_ONLY="YES", FORCE_CHECKOUT="NO" in compile.sh
  • Comment line 62 and 64 in lib/patching.sh otherwise the U-Boot source will be update from GitHub
  • Add CONFIG_MFD_AXP20X=y and CONFIG_REGULATOR_AXP20X=y in sources/u-boot/configs/A20-OLinuXino-Lime2_defconfig (fix the reboot when shutdown command)
  • Edit sources/u-boot/board/sunxi/board.c (fix the auto start issue) at the beginning of void sunxi_board_init(void) add   
if (axp209_poweron_by_dc())
    {
      axp209_poweroff();
      return;//in a normal, return; is unreachable code, axp209 should cutoff outputs already
    }
[/li]
[li]Make sure the axp209_poweroff function exist in sources/u-boot/drivers/power/axp209.c otherwise add void axp209_poweroff(void)
{
u8 val;

if (axp209_read(AXP209_SHUTDOWN, &val) != 0)
return;

val |= AXP209_POWEROFF;

if (axp209_write(AXP209_SHUTDOWN, val) != 0)
return;

udelay(10000); /* wait for power to drain */
}
    [/li]
  • Lunch compile.sh, few minutes later you should have a linux-u-boot-lime2_4.3_armhf.deb in output/debs/
  • Scp the file on you board and install it with dpkg

Start the board, connect through SSH and Look in the /boot/bin folder for the lime2.bin file. Convert it in fex file (bin2fex lime2.bin > lime2.fex) then edit and change at the beginning of the file the following parameter power_start=1. Convert it back to .bin : fex2bin lime2.fex > lime2.bin

Normally no auto start up nor reboot when halt command any more. This is of course not the best way to do it but it works. In some case like me, I cannot use the mainline kernel 4x because of some device tree config file note ready to handle battery regulator and so on, so I stick to legacy kernel for now   

I can provide the .deb package if you want to try on your board

harolimex

I have the same problem as you and tried your tips, I followed your guide step by step but failed at compiling the source because of "undefined reference to 'axp209_poweron_by_dc()' also undefined reference to 'axp209_read' and 'axp209_write'.

Can I get your .debs for this ?

hiol

Hi,

I made this quick patch but It's not working for me:



diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 3cf3614..27efb76 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -475,6 +475,12 @@ void i2c_init_board(void)
#ifdef CONFIG_SPL_BUILD
void sunxi_board_init(void)
{
+  if (axp209_poweron_by_dc())
+  {
+   axp209_poweroff();
+   return;//in a normal, return; is unreachable code, axp209 should cutoff outputs already
+  }
+
int power_failed = 0;
unsigned long ramsize;

diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig
index 419cdfb..9932d9b 100644
--- a/configs/A20-OLinuXino-Lime2_defconfig
+++ b/configs/A20-OLinuXino-Lime2_defconfig
@@ -18,3 +18,5 @@ CONFIG_ETH_DESIGNWARE=y
CONFIG_AXP_ALDO3_VOLT=2800
CONFIG_AXP_ALDO4_VOLT=2800
CONFIG_USB_EHCI_HCD=y
+CONFIG_MFD_AXP20X=y
+CONFIG_REGULATOR_AXP20X=y
diff --git a/drivers/power/axp209.c b/drivers/power/axp209.c
index fc162a1..e412df1 100644
--- a/drivers/power/axp209.c
+++ b/drivers/power/axp209.c
@@ -180,3 +180,20 @@ int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
/* not reached */
return 0;
}
+
+int axp209_poweron_by_dc(void)
+{
+u8 reg;
+
+if (pmic_bus_read(AXP209_POWER_STATUS, &reg))
+  return 0;
+return (reg & AXP209_POWER_STATUS_ON_BY_DC);
+}
+
+void axp209_poweroff(void)
+{
+  pmic_bus_write(AXP209_SHUTDOWN, AXP209_POWEROFF);
+
+  udelay(10000);    /* wait for power to drain */
+} 
+
diff --git a/include/command.h b/include/command.h
index 08f0486..dad3eca 100644
--- a/include/command.h
+++ b/include/command.h
@@ -112,6 +112,9 @@ extern int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
extern int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);

+extern int axp209_poweron_by_dc(void);
+extern void axp209_poweroff(void);
+
/*
  * Error codes that commands return to cmd_process(). We use the standard 0
  * and 1 for success and failure, but add one more case - failure with a




splite

I had the same issue with the last version of the compile.sh script from Igor.

You have to add some function in the code :

In
u-boot/v2016.05/include/axp209.h
Add
extern int axp209_poweron_by_dc(void);
And in
u-boot/v2016.05/drivers/power/axp209.c
Add
int axp209_write(enum axp209_reg reg, u8 val)
{
        return i2c_write(0x34, reg, 1, &val, 1);
}

int axp209_read(enum axp209_reg reg, u8 *val)
{
        return i2c_read(0x34, reg, 1, val, 1);
}
int axp209_poweron_by_dc(void)
{
        u8 v;

        if (axp209_read(AXP209_POWER_STATUS, &v))
                return 0;
        return (v & AXP209_POWER_STATUS_ON_BY_DC);
}


Then I was able to compile and build linux-u-boot-next-lime2_5.14_armhf.deb and It worked on my lime2

However I do not guarantee the code. That would be nice if someone could double check on this.

Best
Florian