Monday, February 13, 2012

Wrangling Setup (msi) projects

To add a custom action to a Setup/Deployment project, you can write a stand alone script (in VBS), or write a standalone executable, or you can add an Installer class to your main application. I like the last one, since it keeps everything together in less files.

1. Add an "Installer Class" to your project using the Add New Item

2. Override the 4 class: Install, Commit, Uninstall, Rollback.

3. If you want to do any logging, use this.Context.LogMessage(string)

4. If you want to use passed parameters, use Context.Parameters

5. Build

6. Add the application as a Custom Action to your setup project. Add it to ALL 4 actions, otherwise you'll get an obscure error.

7. To pass parameters, use CustomActionData field, and format it like /name=value /name=value. Use double quotes if you have spaces in the values.

8. You can make it conditional by
a. adding a Checkbox to the user interface, and naming the property of the checkbox, ie DO_WHAT_I_WANT
b. Using that checkbox name (ie DO_WHAT_I WANT) as the Conditional of the custom action.

9. To debug, Use
System.Diagnostics.Debugger.Launch();
System.Diagnostics.Debugger.Break();
where you need it.

Tuesday, February 7, 2012

Stack size of bootloader versus application

I got myself in a bind when I changed the stack size of my application, but didn't change the size of the stack in the bootloader.

I learned something new today: the CPU sets the stack pointer to the first word of the vector table on reset. If you have a bootloader that does something like jump to the reset vector (__vector_table + 4 bytes), it will NOT reload the stack pointer. If your stack pointer is not changed, you are likely to start writing all over the stack with your static variables. yuck.

In my case, the bootloader had a stack of 0xC00. My main app was running out of memory, so I changed the stack to 0xB80 (which was more than enough). However, I noticed that my app was still using a stack of size 0xC00, when it had only allocated 0xB80 to it. uhoh.


To fix this, I added these 2 lines to the ResetHandler in startup_stm32f10x_md_vl.s (or the equivalent for other STM32s)


Reset_Handler
;; MTL
;;force reload of the stack pointer!
;; it is stored on the start of the vector table
LDR R0,=__vector_table
LDR SP,[R0]
;;
LDR R0, =SystemInit
BLX R0
LDR R0, =__iar_program_start
BX R0


Btw, IAR 6.3 has a feature to analyze the stack size. It kinda works, but it is a pain in the butt if you have C++ virtual functions or any function pointers.

Monday, February 6, 2012

How to add options to a Setup and Deployment project in Visual Studio

Visual Studio has a "Setup and Deployment" project, that is mostly easy to set up with a bunch of clicks.

If you want to customize the installer (with options for the user), you need to write little programs to do each custom operation.

The scripts can be written as *.exe or *.dll files, which need to be compiled. That seems a bit overkill.

The scripts can also be written as VBS (Visual Basic Scripting) language. For someone like me, I don't want to know about VBS, but that's the only other option you have. VBS is not the same as VB, but it is similar. In addition, some of the default assemblies you have access to in VBS from the command line are not available from the Setup Project.

To test out a VBS script, you run the 'cscript' command from the command line, or double click it.

Here's a VBS script that opens a firewall. You add the script to the Custom Action -> Commit, and change the CustomActionData property to [TARGETDIR]. There a bunch of variables you can pass in CustomActionData, but I've yet to find a complete list of them online.

You can make it conditional by adding something to the UserInterface (say Checkboxes (A)), name the property name of that checkbox, and then use that in a conditional for the custom action. Sorry that's vague, but should give me some hints when I actually need to implement it.


Dim target

'msgbox "start"
'msgbox Session.Property("CustomActionData")
target = Session.Property("CustomActionData")
'msgbox target

Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
filename = target & "cog-trk-db-service.exe"
'msgbox filename

Set objApplication = CreateObject("HNetCfg.FwAuthorizedApplication")
objApplication.Name = "cog-trk-db-service"
objApplication.IPVersion = 2
objApplication.ProcessImageFileName = filename
objApplication.RemoteAddresses = "*"
objApplication.Scope = 0
objApplication.Enabled = True

Set colApplications = objPolicy.AuthorizedApplications
colApplications.Add(objApplication)


msgbox "Firewall exception created for " & filename
'msgbox "stop"
STM32 fault handling

http://blog.frankvh.com/2011/12/07/cortex-m3-m4-hard-fault-handler/

Here is the IAR version of the asm.


NAME HardFault_Handler

AAPCS BASE,INTERWORK
PRESERVE8
REQUIRE8

EXTERN hard_fault_handler_c

SECTION .text:CODE:REORDER(2)
THUMB

PUBLIC HardFault_Handler
PUBLIC BusFault_Handler

HardFault_Handler
BusFault_Handler
TST LR, #4
ITE EQ
MRSEQ R0, MSP
MRSNE R0, PSP
B hard_fault_handler_c

END