NishanthMenon changed the topic of #openocd to: this is the place to discuss all things OpenOCD | Logs: https://libera.irclog.whitequark.org/openocd/
wchrisg has quit [Quit: Leaving]
cp- has quit [Quit: Disappeared in a puff of smoke]
crabbedhaloablut has quit []
Hawk777 has joined #openocd
wchrisg has joined #openocd
_whitelogger has joined #openocd
stefanct has quit [Ping timeout: 252 seconds]
stefanct__ has joined #openocd
stefanct__ is now known as stefanct
nerozero has joined #openocd
gzlb has quit [Ping timeout: 245 seconds]
gzlb has joined #openocd
Hawk7771 has joined #openocd
Hawk777 has quit [Ping timeout: 246 seconds]
Hawk7771 is now known as Hawk777
crabbedhaloablut has joined #openocd
Hawk777 has quit [Quit: Leaving.]
Haohmaru has joined #openocd
c4017 has quit [Quit: Client closed]
davidmpye has joined #openocd
<davidmpye> Hello!  I have a somewhat niche SAMD20 question, if anyone might know the answer.   I am working on an OSS project to replace the firmware for Dyson vacuum cleaner battery packs.   The pack has an ATSAMD20 MCU on, with the security enable bit set.  I can unlock and erase it via Atmel-ICE and atmel studio, but for Joe-public, I'd like to be
<davidmpye> able to do it with Raspberry Pi and the GPIOs to provide an easy and cheap way for people to reflash the packs.
<davidmpye> The info about how to get openocd to clear the security bit is, well, a bit confusing.   The official at921samd file mentions 'not possible' but there are some patches I found that do seem to make it possible, but they were using cmsis-dap rather than Pi GPIO.
<davidmpye> has anyone ever tried or managed to do a similar feat with Pi GPIOs?
<PaulFertser> davidmpye: hi
<Haohmaru> davidmpye, there are cmsis-dap based debuggers that are cheaper and more obtainable than a raspberry pi
<PaulFertser> davidmpye: should be possible with RPi bitbanging too.
<PaulFertser> davidmpye: 4043 is certainly not adapter-specific and it was merged upstream.
<PaulFertser> davidmpye: 4044 you can probably imitate by "gpioset" commands before running OpenOCD.
<davidmpye> Thanks all so far, having a play here
<davidmpye> Haohmaru: That's true but my target hacker/maker 'market' will probably all have a Pi knocking around, but I hear you!
<PaulFertser> davidmpye: it just pulls both SRST and SWCLK low, then brings SRST high.
<Haohmaru> i don't have nor have had a single SBC
<davidmpye> tbf, if I can make a robust way to do it, then I should be able to make it possible for people to do with a variety of transports
<davidmpye> Haohmaru: At my hackspce, that would make you an outlier, but again, I get your point
<PaulFertser> One could probably even imitate that manually by connecting SWCLK to ground, not connecting SRST to the debug adapter, then pulsing SRST with tweezers, then connecting SWCLK to the debug adapter and starting OpenOCD.
<davidmpye> PaulFertser: The other problem, it seems, is that when the security bit is set you can't even connect to the device
<davidmpye> hence, it fails at Error: Error connecting DP: cannot read IDR
<PaulFertser> davidmpye: it extended reset?
<davidmpye> I think even in extended reset, you get a different ID, but I'll try further
<PaulFertser> davidmpye: also, are you enabling srst_only in reset config? And then you should be able to run command "at91samd chip-erase" even if it's not able to read IDR probably?
<PaulFertser> davidmpye: hm, so you have a CMSIS-DAP adapter already (the Atmel-ICE), you can try with the hack from 4044 and command from the users manual which mentions cmsis_dap_init_samd_cold_plug to have a reference point?
<PaulFertser> Hm, it should kinda connect in extended reset state.
<davidmpye> i'll have a tweak, and report back
<davidmpye> the DAP idea makes a lot of sense
<davidmpye> becuase I know that works
<davidmpye> I don't think cmsis_dap_init_samd_cold_plug ever made it fully upstream?
<davidmpye> the only reference to it seems to be in that patch afaics
<PaulFertser> davidmpye: yes, you need to apply it to current source
<davidmpye> Just having a play with the pi gpios to try to get extended reset to work - at present, as soon as I release the reset line, it starts running normally, which it shouldnt do if SWCLK remains low. Will dig further...
<davidmpye> So, in deep reset, you CAN connect to it (sort of) : Info : SWD DPIDR 0x0bc11477
<davidmpye> but you get Error: Target not examined yet in response to anything else
<PaulFertser> davidmpye: yeah, that looks correct.
<davidmpye> eg doing the "init; at91samd mwb 0x41002100 0x10; reset"
<PaulFertser> davidmpye: so how did you got into the extended reset state?
<davidmpye> which I am guessing, because it cannot do : "Error: Failed to read memory at 0xe000ed00
<davidmpye> "
<davidmpye> which it won't be able to do in secure mode, it just needs to write anyway
<PaulFertser> davidmpye: what about the special command "at91samd chip-erase" ?
<davidmpye> Error: Target not examined yet
<davidmpye> write to DSU CTRL failed
<davidmpye> but it needs to change the register address in secure mode, hence trying to use the mwb command
<PaulFertser> davidmpye: probably one just needs to skip that check if it's examined or not by adding another hack patch.
<PaulFertser> davidmpye: you should see all the details if you start openocd with -d3 log.
<PaulFertser> davidmpye: try commenting out the check in target_write_memory() in src/target/target.c to force writing
<davidmpye> you're right, d3 shows Error: 140 202 target.c:2674 target_write_u32(): Target not examined yet
<davidmpye> Error: 141 202 target.c:2715 target_write_u8(): Target not examined yet
<PaulFertser> davidmpye: you can try just removing that check for testing if it helps.
<PaulFertser> And then probably to add temporary change to examination status to chip-erase handler if it works.
<davidmpye> recompiling, back in an hour (pi zero...!)
<PaulFertser> davidmpye: you could have started checking with your normal computer and that cmsis-dap adapter you already have ;)
slobodan has joined #openocd
Foxyloxy has quit [Quit: Textual IRC Client: www.textualapp.com]
JakeSays has quit [Remote host closed the connection]
JakeSays has joined #openocd
davidmpye has quit [Quit: Client closed]
Foxyloxy has joined #openocd
davidmpye has joined #openocd
tsal has quit [Ping timeout: 245 seconds]
van has quit [Quit: WeeChat 3.8]
tsal has joined #openocd
van has joined #openocd
davidmpye has quit [Quit: Client closed]
davidmpye has joined #openocd
<davidmpye> Thank you for your help @PaulFertser
<davidmpye> That worked, and I can now do the necessary for the security bits
<davidmpye> Cheers!
<PaulFertser> davidmpye: probably add a hacking patch to the unclocking function upstream then? That would save current examined state, overwrite it, then restore.
<PaulFertser> davidmpye: do you have a link to your repo with that alternative firmware?
<davidmpye> There are a couple of things that would make that difficult - you'd need to hack something into each transport to do the cold reset, as well as change the read functions to not check for 'examined' status.
<davidmpye> It's disappointing, but I can see why things haven't got upstream
<PaulFertser> davidmpye: no, I mean the examine problem, not the cold reset.
<PaulFertser> davidmpye: for cold reset we can just add documentation to the manual so people could do it even manually if needed.
<davidmpye> I need to update the documentation and do a lot of 'how to install it' info
<PaulFertser> davidmpye: btw, why were your initial tries unsuccessful?
<davidmpye> The raspi-gpio set stuff works fine, it was just working out what needed to be tweaked in terms of the write memory functions. There were several that needed the 'examined' status removed.
<davidmpye> I like that suggestion for the examined state, i'll see how it could be doine
<davidmpye> *done
<PaulFertser> davidmpye: in src/flash/nor/at91samd.c samd_handle_chip_erase_command function.
<davidmpye> Interestingly, there is a target_set_examined function defined  in target.h, but no 'clear_examined' function
<davidmpye> so you can set it, which will allow the writes to succeed, but no way to clear
davidmpye has quit [Ping timeout: 246 seconds]
Haohmaru has quit [Ping timeout: 246 seconds]
nerozero has quit [Ping timeout: 246 seconds]
crabbedhaloablut has quit []
Foxyloxy has quit [Read error: Connection reset by peer]
Foxyloxy has joined #openocd