[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 04/14] sdcard: Extract sd_frame48/136_calc_ch
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [Qemu-devel] [PATCH v2 04/14] sdcard: Extract sd_frame48/136_calc_checksum() |
Date: |
Wed, 9 May 2018 16:15:51 -0300 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 |
Hi Alistair,
On 05/09/2018 03:00 PM, Alistair Francis wrote:
> On Tue, May 8, 2018 at 8:46 PM, Philippe Mathieu-Daudé <address@hidden> wrote:
>> It will help when moving this around for qtesting in the next commit.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
>> ---
>> hw/sd/sd.c | 21 ++++++++++++++++++---
>> 1 file changed, 18 insertions(+), 3 deletions(-)
>>
>> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
>> index 27a70896cd..06607115a7 100644
>> --- a/hw/sd/sd.c
>> +++ b/hw/sd/sd.c
>> @@ -273,6 +273,21 @@ static uint16_t sd_crc16(const void *message, size_t
>> width)
>> return shift_reg;
>> }
>>
>> +enum {
>> + F48_CONTENT_LENGTH = 1 /* command */ + 4 /* argument */,
>> + F136_CONTENT_LENGTH = 15,
>> +};
>> +
>> +static uint8_t sd_frame48_calc_checksum(const void *content)
>> +{
>> + return sd_crc7(content, F48_CONTENT_LENGTH);
>> +}
>> +
>> +static uint8_t sd_frame136_calc_checksum(const void *content)
>> +{
>> + return (sd_crc7(content, F136_CONTENT_LENGTH) << 1) | 1;
>> +}
>> +
>> #define OCR_POWER_DELAY_NS 500000 /* 0.5ms */
>>
>> FIELD(OCR, VDD_VOLTAGE_WINDOW, 0, 24)
>> @@ -352,7 +367,7 @@ static void sd_set_cid(SDState *sd)
>> sd->cid[13] = 0x00 | /* Manufacture date (MDT) */
>> ((MDT_YR - 2000) / 10);
>> sd->cid[14] = ((MDT_YR % 10) << 4) | MDT_MON;
>> - sd->cid[15] = (sd_crc7(sd->cid, 15) << 1) | 1;
>> + sd->cid[15] = sd_frame136_calc_checksum(sd->cid);
>> }
>>
>> #define HWBLOCK_SHIFT 9 /* 512 bytes */
>> @@ -416,7 +431,7 @@ static void sd_set_csd(SDState *sd, uint64_t size)
>> sd->csd[13] = 0x40;
>> sd->csd[14] = 0x00;
>> }
>> - sd->csd[15] = (sd_crc7(sd->csd, 15) << 1) | 1;
>> + sd->csd[15] = sd_frame136_calc_checksum(sd->csd);
>> }
>>
>> static void sd_set_rca(SDState *sd)
>> @@ -491,7 +506,7 @@ static int sd_req_crc_validate(SDRequest *req)
>> buffer[0] = 0x40 | req->cmd;
>> stl_be_p(&buffer[1], req->arg);
>> return 0;
>> - return sd_crc7(buffer, 5) != req->crc; /* TODO */
>> + return sd_frame48_calc_checksum(buffer) != req->crc; /* TODO */
>
> This 5 has changed to a 15. Is that on purpose? It should be mentioned
> in the commit message if it is.
I just extracted this function:
static uint8_t sd_frame48_calc_checksum(const void *content)
{
return sd_crc7(content, F48_CONTENT_LENGTH);
}
Having:
enum {
F48_CONTENT_LENGTH = 1 /* command */ + 4 /* argument */,
So F48_CONTENT_LENGTH = 5 as previous.
This function is later verified with tests from patch 12 of this series.
>
> Alistair
>
>> }
>>
>> static void sd_response_r1_make(SDState *sd, uint8_t *response)
>> --
>> 2.17.0
>>
>>
[Qemu-devel] [PATCH v2 05/14] sdcard: Move sd_crc7() and calc_checksum() out for qtesting, Philippe Mathieu-Daudé, 2018/05/08
[Qemu-devel] [PATCH v2 06/14] sdcard: Add test_sd_verify_cksum_frame136(), Philippe Mathieu-Daudé, 2018/05/08
[Qemu-devel] [PATCH v2 07/14] sdcard: Invert the sd_req_crc_is_valid() logic, Philippe Mathieu-Daudé, 2018/05/08
[Qemu-devel] [PATCH v2 08/14] sdcard: Extract sd_frame48_verify_checksum() out for qtesting, Philippe Mathieu-Daudé, 2018/05/08
[Qemu-devel] [PATCH v2 09/14] sdcard: Add sd_frame136_verify_checksum(), Philippe Mathieu-Daudé, 2018/05/08