Skip to content
This repository has been archived by the owner on Apr 15, 2022. It is now read-only.

Is there a bug in bool is_locked (int fd, enum DATA_ZONE zone) fucntion #43

Open
leomatrix opened this issue Oct 10, 2015 · 2 comments
Open

Comments

@leomatrix
Copy link

hi jbdatko:

maybe sentence : if (read4 (fd, CONFIG_ZONE, config_addr, &buf)) did'nt handle the case that read4() execution false, if read4() return false, however is_locked() return result still is true!!!! Am right?

bool is_locked (int fd, enum DATA_ZONE zone)
{
uint32_t buf = 0;
const uint8_t config_addr = 0x15;
uint8_t *ptr = (uint8_t *)&buf;
const uint8_t UNLOCKED = 0x55;
bool result = true;
const unsigned int CONFIG_ZONE_OFFSET = 3;
const unsigned int DATA_ZONE_OFFSET = 2;
unsigned int offset = 0;

switch (zone)
{
case CONFIG_ZONE:
offset = CONFIG_ZONE_OFFSET;
break;
case DATA_ZONE:
case OTP_ZONE:
offset = DATA_ZONE_OFFSET;
break;
default:
assert (false);
}

if (read4 (fd, CONFIG_ZONE, config_addr, &buf))
{
ptr = ptr + offset;
if (UNLOCKED == *ptr)
result = false;
else
result = true;
}

return result;
}

@jbdatko
Copy link
Member

jbdatko commented Oct 10, 2015

Hmmm, yes, your understanding is corrected. If read4 fails, is_locked returns true. I probably need to switch this to return an int where there's more than one status.

You can always do the read4 directly if you want.

Lastly, just as a FYI, if you are writing your own application, you may want to check out my other library. It works with the 204 as well.

Eventually, I mean to replaces the internals of hashlet with that library but I just haven't got around to it yet.

@leomatrix
Copy link
Author

OK , I will support you ! Now I apply atsha204 on the STM32F427 platform using nuttx RTOS, initially, I begin with ATMEL sha204_library,but when I want to personalize the chip, I find out that the library can't do this, fortunately, I find your repository, I will focus your contribution repository, thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants