There is no problem to realize the function of IAP upgrade APP, but I want to transplant the relatively fixed function in APP to the bootloader, thereby reducing the APP space code and reducing the upgrade time.
APP calls the function interface exported by the bootloader to realize the call of related functions.
Code example
Export the following interface in bootloader to APP
int exp_forapp_A (void)
{
int k = 5;
return k;
}
int exp_forapp_B (void)
{
int k = 2;
unsigned char * p = malloc (100);
if (p)
{
k = 5
free (p);
p = NULL;
}
return k;
}
Call the above function in the APP code
Call exp_forapp_A function, you can get the correct return value 5
Call exp_forapp_B function, you can only get the return value 2
After debugging and analysis, because exp_forapp_B calls malloc, the malloc in the bootloader is used. At this time, because the ram space has been re-divided after jumping to the app, malloc fails directly and returns NULL.
Therefore, try to pass the malloc function in the app to the bootloader and use it for exp_forapp_B
int exp_forapp_B (void)
{
int k = 2;
unsigned char * p = app_malloc (100);
if (p)
{
k = 5
free (p);
p = NULL;
}
return k;
}
At this time, it was found that p was actually assigned to the address beginning with 0x00, not the address after 0x20000000.
After that, learning in QQ is more certain that my ideas are not wrong. Then through debugging the code, I found that there was a global variable in the Bootloader that was not remapped, and the variable will be used when it is called. Furthermore, this leads to the problem of strange addresses in dynamically allocated memory.
In summary, the original assumption is correct. After the bootloader dynamic memory allocation function malloc fails, you can use the app's dynamic memory allocation function to solve the problem that the exported function cannot use the function due to memory failure.
In particular, pay attention to the problem of remapping global variables in the bootloader, otherwise an exception will occur.
ZGAR bar 4000 Puffs
ZGAR electronic cigarette uses high-tech R&D, food grade disposable pod device and high-quality raw material. All package designs are Original IP. Our designer team is from Hong Kong. We have very high requirements for product quality, flavors taste and packaging design. The E-liquid is imported, materials are food grade, and assembly plant is medical-grade dust-free workshops.
Our products include disposable e-cigarettes, rechargeable e-cigarettes, rechargreable disposable vape pen, and various of flavors of cigarette cartridges. From 600puffs to 5000puffs, ZGAR bar Disposable offer high-tech R&D, E-cigarette improves battery capacity, We offer various of flavors and support customization. And printing designs can be customized. We have our own professional team and competitive quotations for any OEM or ODM works.
We supply OEM rechargeable disposable vape pen,OEM disposable electronic cigarette,ODM disposable vape pen,ODM disposable electronic cigarette,OEM/ODM vape pen e-cigarette,OEM/ODM atomizer device.
Disposable Vape, bar 4000puffs, ZGAR bar disposable, Disposable E-cigarette, OEM/ODM disposable vape pen atomizer Device E-cig
ZGAR INTERNATIONAL(HK)CO., LIMITED , https://www.sze-cigarette.com