tegrarcm: T124 and new command support
cover tegrarcm: T124 and new command support
This patch series adds T124 support to tegrarcm, tested on laguna. It also adds support for new commands for ripping a BCT from a live system, for passing in the miniloader from a file, and for passing in the odmdata on the command line. Also fixed up some of the error handling so now USB commands will time out instead of hanging, and attempt to bring up nv3p even if RCM is unresponsive.
Allen Martin (11):
tegrarcm: Change NVIDIA license to apply to all miniloader files
tegrarcm: Add support for RCM protocol version 40
tegrarcm: Add Tegra124 miniloader
tegrarcm: Add Tegra124 support
tegrarcm: Add timeout to USB xfers
tegrarcm: Assume nv3p server is running if RCM doesn't respond
tegrarcm: Clean up usage info
tegrarcm: Add rip support
tegrarcm: Add support for odmdata command
tegrarcm: Add command to pass miniloader in from file
tegrarcm: Bump version to 1.5
LICENSE | 4 +- README | 2 + configure.ac | 2 +- src/Makefile.am | 1 + src/main.c | 398 +- src/miniloader/tegra124-miniloader.h | 8570 ++++++++++++++++++++++++++++++++++ src/nv3p.c | 26 +- src/nv3p.h | 27 + src/rcm.c | 74 + src/rcm.h | 58 +- src/tegrarcm.1.in | 21 +- src/usb.c | 10 +- src/usb.h | 1 + 13 files changed, 9066 insertions(+), 128 deletions(-) create mode 100644 src/miniloader/tegra124-miniloader.h
Signature · 1 line
1.8.1.5
A message that is not in the archive (sent off-list or not yet received): 1378757761-20939-1-git-send-email-amartin-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
PATCH 1/11 tegrarcm: Change NVIDIA license to apply to all miniloader files
Change the LICENSE file to make it clear that the NVIDIA proprietary license applies to all miniloader files, not just the ones explicitly listed.
--- LICENSE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
LICENSE +2 -2
@@ -26,8 +26,8 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -The files tegra20-miniloader.h and tegra30-miniloader.h are provided -pursuant to the following license agreement: +The files in the directory src/miniloader are provided pursuant to the +following license agreement: License For Use of NVIDIA Software
Signature · 1 line
1.8.1.5
PATCH 2/11 tegrarcm: Add support for RCM protocol version 40
In reply to a message not in the archiveRCM protocol 40 is required for Tegra124
--- src/rcm.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/rcm.h | 58 ++++++++++++++++++++++++++++++++----------------- 2 files changed, 112 insertions(+), 20 deletions(-)
src/rcm.c +74 -0
@@ -36,6 +36,7 @@static int rcm_sign_msg (uint8_t *buf);static int rcm1_sign_msg (uint8_t *buf);static int rcm35_sign_msg (uint8_t *buf); +static int rcm40_sign_msg (uint8_t *buf); static void rcm_init_msg( uint8_t *buf, uint32_t msg_len,
@@ -57,6 +58,13 @@ static void rcm35_init_msg(void *args, uint32_t args_len, uint32_t payload_len); +static void rcm40_init_msg ( +uint8_t *buf, +uint32_t msg_len, +uint32_t opcode, +void *args, +uint32_t args_len, +uint32_t payload_len);static uint8_t *rcm_get_msg_payload (uint8_t *buf);static void rcm_msg_pad (uint8_t *data,uint32_t len);static uint32_t rcm_get_pad_len (uint32_t payload_len);
@@ -79,6 +87,11 @@ int rcm_init(uint32_t version) message_size =sizeof (rcm35_msg_t); ret =0 ; } +else if (version ==RCM_VERSION_40 ) { + rcm_version = version; + message_size =sizeof (rcm40_msg_t); + ret =0 ; + }return ret; }
@@ -88,6 +101,8 @@ uint32_t rcm_get_msg_len(uint8_t *msg)return ((rcm1_msg_t *)msg)->len_insecure; else if (rcm_version == RCM_VERSION_35) return ((rcm35_msg_t*)msg)->len_insecure; + else if (rcm_version == RCM_VERSION_40) + return ((rcm40_msg_t*)msg)->len_insecure; else return 0; }
@@ -139,6 +154,8 @@ static int rcm_sign_msg(uint8_t *buf) {if (rcm_version ==RCM_VERSION_35 )return rcm35_sign_msg (buf); +else if (rcm_version ==RCM_VERSION_40 ) +return rcm40_sign_msg (buf);else if (rcm_version ==RCM_VERSION_1 )return rcm1_sign_msg (buf);else
@@ -184,6 +201,26 @@ static int rcm35_sign_msg(uint8_t *buf)return 0 ; } +static int rcm40_sign_msg (uint8_t *buf) +{ +rcm40_msg_t *msg; +uint32_t crypto_len; + + msg = (rcm40_msg_t *)buf; + +// signing does not include the len_insecure, modulus +// and object signature at the beginning of the message + crypto_len = msg->len_insecure -sizeof (msg->len_insecure) - +sizeof (msg->modulus) - +sizeof (msg->object_sig); +if (crypto_len %RCM_AES_BLOCK_SIZE ) { +return -EMSGSIZE ; + } + +cmac_hash (msg->reserved, crypto_len, msg->object_sig.cmac_hash); +return 0 ; +} +static uint32_t rcm_get_msg_buf_len (uint32_t payload_len) { return message_size + payload_len +
@@ -215,6 +252,9 @@ static void rcm_init_msg(if (rcm_version ==RCM_VERSION_35 )rcm35_init_msg (buf, msg_len, opcode, args, args_len, payload_len); +else if (rcm_version ==RCM_VERSION_40 ) +rcm40_init_msg (buf, msg_len, opcode, args, + args_len, payload_len);else if (rcm_version ==RCM_VERSION_1 )rcm1_init_msg (buf, msg_len, opcode, args, args_len, payload_len);
@@ -254,6 +294,40 @@ static void rcm35_init_msg(rcm_msg_pad (buf +sizeof (rcm35_msg_t) + payload_len, padding_len); } +static void rcm40_init_msg ( +uint8_t *buf, +uint32_t msg_len, +uint32_t opcode, +void *args, +uint32_t args_len, +uint32_t payload_len) +{ +uint32_t padding_len; +rcm40_msg_t *msg; + + msg = (rcm40_msg_t *)buf; + + padding_len =rcm_get_pad_len (payload_len); + + msg->len_insecure =sizeof (rcm40_msg_t) + payload_len + + padding_len; + +memset (&msg->object_sig.cmac_hash,0x0 ,sizeof (msg->object_sig.cmac_hash)); +memset (&msg->reserved,0x0 ,sizeof (msg->reserved)); + + msg->opcode = opcode; + msg->len_secure = msg->len_insecure; + msg->payload_len = payload_len; + msg->rcm_version =RCM_VERSION_40 ; + +if (args_len) +memcpy (msg->args, args, args_len); +memset (msg->args + args_len,0x0 ,sizeof (msg->args) - args_len); + +rcm_msg_pad (msg->padding,sizeof (msg->padding)); +rcm_msg_pad (buf +sizeof (rcm40_msg_t) + payload_len, padding_len); +} + static void rcm1_init_msg( uint8_t *buf, uint32_t msg_len,
src/rcm.h +38 -20
78 lines not on this page · raw message
Signature · 1 line
1.8.1.5
PATCH 4/11 tegrarcm: Add Tegra124 support
In reply to a message not in the archiveAdd Tegra124 USB device id, miniloader, and chip SKU information.
--- src/main.c | 15 +++++++++++++++ src/nv3p.h | 3 +++ src/tegrarcm.1.in | 4 +++- src/usb.c | 3 ++- src/usb.h | 1 + 5 files changed, 24 insertions(+), 2 deletions(-)
src/main.c +15 -0
@@ -57,6 +57,9 @@// tegra114 miniloader #include "miniloader/tegra114-miniloader.h" +// tegra124 miniloader +#include "miniloader/tegra124-miniloader.h" +static int wait_status (nv3p_handle_t h3p);static int send_file (nv3p_handle_t h3p,const char *filename); static int download_miniloader(usb_device_t *usb, uint8_t *miniloader,
@@ -208,6 +211,9 @@ int main(int argc, char **argv) }else if ((devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA114 ) {dprintf ("initializing RCM version 35\n" ); ret =rcm_init (RCM_VERSION_35 ); + }else if ((devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA124 ) { +dprintf ("initializing RCM version 40\n" ); + ret =rcm_init (RCM_VERSION_40 ); }else {error (1 ,ENODEV ,"unknown tegra device: 0x%x" , devid); }
@@ -249,6 +255,10 @@ int main(int argc, char **argv) miniloader = miniloader_tegra114; miniloader_size =sizeof (miniloader_tegra114); miniloader_entry =TEGRA114_MINILOADER_ENTRY ; + }else if ((devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA124 ) { + miniloader = miniloader_tegra124; + miniloader_size =sizeof (miniloader_tegra124); + miniloader_entry =TEGRA124_MINILOADER_ENTRY ; }else {error (1 ,ENODEV ,"unknown tegra device: 0x%x" , devid); }
@@ -481,6 +491,11 @@ static void dump_platform_info(nv3p_platform_info_t *info)case TEGRA114_CHIP_SKU_T114 : chip_name ="t114" ;break ;default : chip_name ="unknown" ;break ; } + }else if (info->chip_id.id ==0x40 ) { +switch (info->sku) { +case TEGRA124_CHIP_SKU_T124 : chip_name ="t124" ;break ; +default : chip_name ="unknown" ;break ; + } }else { chip_name ="unknown" ; }
src/nv3p.h +3 -0
@@ -68,6 +68,9 @@ typedef struct nv3p_state *nv3p_handle_t;// tegra114 chip sku #define TEGRA114_CHIP_SKU_T114 0x00 +// tegra124 chip sku +#define TEGRA124_CHIP_SKU_T124 0x00 +// boot device type #define NV3P_DEV_TYPE_NAND 0x1#define NV3P_DEV_TYPE_EMMC 0x2
src/tegrarcm.1.in +3 -1
@@ -24,6 +24,8 @@ device. .B Tegra30 .IP \(bu .B Tegra114 +.IP \(bu +.B Tegra124 .SS How to use .IP \(em
@@ -53,7 +55,7 @@ the firmware file that will be downloaded and executed. .B \-\-loadaddr \fIloadaddr\fP Specify the address the bootloader will be loaded at. This should be specified in hex and is typically 0x108000 for a Tegra20 device or -0x80108000 for a Tegra30 or Tegra114 device. +0x80108000 for a Tegra30, Tegra114, or Tegra124 device. .TP .B \-\-entryaddr \fIentryaddr\fP Specify the entry address that control will be passed to after the
src/usb.c +2 -1
@@ -155,7 +155,8 @@ usb_device_t *usb_open(uint16_t venid, uint16_t *devid)if (usb_match (device, venid, devid)) {if ((*devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA20 || (*devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA30 || - (*devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA114 ) { + (*devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA114 || + (*devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA124 ) { found = device;break ; }else {
src/usb.h +1 -0
@@ -35,6 +35,7 @@#define USB_DEVID_NVIDIA_TEGRA20 0x20#define USB_DEVID_NVIDIA_TEGRA30 0x30#define USB_DEVID_NVIDIA_TEGRA114 0x35 +#define USB_DEVID_NVIDIA_TEGRA124 0x40 typedef struct { libusb_device_handle *handle;
Signature · 1 line
1.8.1.5
A message that is not in the archive (sent off-list or not yet received): 1378757761-20939-5-git-send-email-amartin-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
Re: [PATCH 04/11] tegrarcm: Add Tegra124 support
Quoted 4 lines · Allen Martin
Add Tegra124 USB device id, miniloader, and chip SKU information.
src/main.c +0
-0@@ -481,6 +491,11 @@ static void dump_platform_info(nv3p_platform_info_t *info)case TEGRA114_CHIP_SKU_T114 : chip_name ="t114" ;break ;
src/main.c static void dump_platform_info(nv3p_platform_info_t *info) · line 501
Quoted 10 lines
src/main.c +5
-0default : chip_name ="unknown" ;break ; } + }else if (info->chip_id.id ==0x40 ) { +switch (info->sku) { +case TEGRA124_CHIP_SKU_T124 : chip_name ="t124" ;break ; +default : chip_name ="unknown" ;break ; + } }else { chip_name ="unknown" ; }
Do we really need to care about the SKU here? For chips other than Tegra20, can't we just switch on the chip ID and be done with it? The reason I ask is that in U-Boot, there are some SKU IDs that haven't been ported into tegrarcm, and I assume we should be keeping the two SKU ID lists in sync. It'd be simpler if we just made tegrarcm not care about SKU.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 04/11] tegrarcm: Add Tegra124 support
Quoted 13 lines · Stephen Warren
Quoted 12 lines · Allen Martin
Add Tegra124 USB device id, miniloader, and chip SKU information.
src/main.c +5
-0@@ -481,6 +491,11 @@ static void dump_platform_info(nv3p_platform_info_t *info)case TEGRA114_CHIP_SKU_T114 : chip_name ="t114" ;break ;default : chip_name ="unknown" ;break ; } + }else if (info->chip_id.id ==0x40 ) { +switch (info->sku) { +case TEGRA124_CHIP_SKU_T124 : chip_name ="t124" ;break ; +default : chip_name ="unknown" ;break ; + } }else {
Quoted 8 lines
src/main.c static void dump_platform_info(nv3p_platform_info_t *info) · line 501
Quoted 2 lines
src/main.c +0
-0chip_name ="unknown" ; }Do we really need to care about the SKU here? For chips other than Tegra20, can't we just switch on the chip ID and be done with it? The reason I ask is that in U-Boot, there are some SKU IDs that haven't been ported into tegrarcm, and I assume we should be keeping the two SKU ID lists in sync. It'd be simpler if we just made tegrarcm not care about SKU.
It's purely informative as we don't do anything with the information elsewhere in tegrarcm. Maybe I should just make the default be the chip family instead of "unknown" so it's more resistant to being out of sync (and also take a pass at syncing up with u-boot) ?
-Allen
Signature · 1 line
nvpublic
Re: [PATCH 04/11] tegrarcm: Add Tegra124 support
Quoted 23 lines · Allen Martin
Quoted 13 lines · Stephen Warren
Quoted 12 lines · Allen Martin
Add Tegra124 USB device id, miniloader, and chip SKU information.
src/main.c +5
-0@@ -481,6 +491,11 @@ static void dump_platform_info(nv3p_platform_info_t *info)case TEGRA114_CHIP_SKU_T114 : chip_name ="t114" ;break ;default : chip_name ="unknown" ;break ; } + }else if (info->chip_id.id ==0x40 ) { +switch (info->sku) { +case TEGRA124_CHIP_SKU_T124 : chip_name ="t124" ;break ; +default : chip_name ="unknown" ;break ; + } }else {Quoted 8 lines
src/main.c static void dump_platform_info(nv3p_platform_info_t *info) · line 501
Quoted 2 lines
src/main.c +0
-0chip_name ="unknown" ; }Do we really need to care about the SKU here? For chips other than Tegra20, can't we just switch on the chip ID and be done with it? The reason I ask is that in U-Boot, there are some SKU IDs that haven't been ported into tegrarcm, and I assume we should be keeping the two SKU ID lists in sync. It'd be simpler if we just made tegrarcm not care about SKU.
Quoted 4 lines
It's purely informative as we don't do anything with the information elsewhere in tegrarcm. Maybe I should just make the default be the chip family instead of "unknown" so it's more resistant to being out of sync (and also take a pass at syncing up with u-boot) ?
Sounds good to me.
PATCH 5/11 tegrarcm: Add timeout to USB xfers
In reply to a message not in the archiveThis prevents tegrarcm from just hanging in the event that the target gets in some bad state and stops responding to USB (like downloading a bad BCT). Set default timeout to 1s which should be plenty long enough for the max xfer size of 4096 bytes.
--- src/usb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
src/usb.c +5 -2
@@ -34,6 +34,9 @@#include "usb.h" #include "debug.h" +// USB xfer timeout in ms +#define USB_TIMEOUT 1000 +#define USB_XFER_MAX 4096//
@@ -225,7 +228,7 @@ int usb_write(usb_device_t *usb, uint8_t *buf, int len)while (len) { chunk_size =MIN (len,USB_XFER_MAX ); ret =libusb_bulk_transfer (usb->handle, usb->endpt_out, buf, - chunk_size, &actual_chunk,0 ); + chunk_size, &actual_chunk,USB_TIMEOUT );if (ret !=LIBUSB_SUCCESS ) {dprintf ("write failure: %d\n" , ret);return EIO ;
@@ -252,7 +255,7 @@ int usb_read(usb_device_t *usb, uint8_t *buf, int len, int *actual_len)while (len) { chunk_size =MIN (len,USB_XFER_MAX ); ret =libusb_bulk_transfer (usb->handle, usb->endpt_in, buf, - chunk_size, &actual_chunk,0 ); + chunk_size, &actual_chunk,USB_TIMEOUT );if (ret !=LIBUSB_SUCCESS ) {dprintf ("read failure: %d\n" , ret);return EIO ;
Signature · 1 line
1.8.1.5
PATCH 6/11 tegrarcm: Assume nv3p server is running if RCM doesn't respond
In reply to a message not in the archiveChange the initialization logic so that if RCM protocol isn't repsonding but a tegra recovery USB is reported, assume the nv3p server is already running. This allows things like enumeration of devices via nv3p without having to reset into RCM mode to talk to the device again.
--- src/main.c | 161 ++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 94 insertions(+), 67 deletions(-)
src/main.c +94 -67
@@ -60,6 +60,7 @@// tegra124 miniloader #include "miniloader/tegra124-miniloader.h" +static int initialize_rcm (uint16_t devid,usb_device_t *usb);static int wait_status (nv3p_handle_t h3p);static int send_file (nv3p_handle_t h3p,const char *filename); static int download_miniloader(usb_device_t *usb, uint8_t *miniloader,
@@ -95,11 +96,9 @@ static void usage(char *progname)int main (int argc,char **argv) {// discover devices -uint8_t *msg_buff;uint64_t uid[2 ];int actual_len;usb_device_t *usb; -uint32_t status;nv3p_platform_info_t info;nv3p_handle_t h3p;int ret;
@@ -110,10 +109,6 @@ int main(int argc, char **argv)uint32_t loadaddr =0 ;uint32_t entryaddr =0 ;uint16_t devid; -uint8_t *miniloader; -uint32_t miniloader_size; -uint32_t miniloader_entry; -int msg_len;static struct option long_options[] = { [OPT_BCT ] = {"bct" ,1 ,0 ,0 },
@@ -193,15 +188,72 @@ int main(int argc, char **argv)printf ("device id: 0x%x\n" , devid); ret =usb_read (usb, (uint8_t *)uid,sizeof (uid), &actual_len); +if (!ret) { +if (actual_len ==8 ) +printf ("uid: 0x%016" PRIx64"\n" , uid[0 ]); +else if (actual_len ==16 ) +printf ("uid: 0x%016" PRIx64"%016" PRIx64"\n" , + uid[1 ], uid[0 ]); +else +error (1 , errno,"USB read truncated" ); + +// initialize rcm and download the miniloader to start nv3p +initialize_rcm (devid, usb); + +// device may have re-enumerated, so reopen USB +usb_close (usb); + usb =usb_open (USB_VENID_NVIDIA , &devid); +if (!usb) +error (1 , errno,"could not open USB device" ); + } + +// now that miniloader is up, start nv3p protocol + ret =nv3p_open (&h3p, usb); +if (ret) +error (1 , errno,"3p open failed" ); + +// get platform info and dump it + ret =nv3p_cmd_send (h3p,NV3P_CMD_GET_PLATFORM_INFO , (uint8_t *)&info); +if (ret) +error (1 , errno,"retreiving platform info" ); + ret =wait_status (h3p); +if (ret) +error (1 , errno,"wait status after platform info" ); +dump_platform_info (&info); + +if (info.op_mode !=RCM_OP_MODE_DEVEL && + info.op_mode !=RCM_OP_MODE_ODM_OPEN && + info.op_mode !=RCM_OP_MODE_PRE_PRODUCTION ) +error (1 ,ENODEV ,"device is not in developer, open, " +"or pre-production mode, cannot flash" ); + +// download the BCT + ret =download_bct (h3p, bctfile); +if (ret) { +error (1 , ret,"error downloading bct: %s" , bctfile); + } + +// download the bootloader + ret =download_bootloader (h3p, blfile, entryaddr, loadaddr);if (ret) -error (1 , ret,"USB transfer failure" ); -if (actual_len ==8 ) -printf ("uid: 0x%016" PRIx64"\n" , uid[0 ]); -else if (actual_len ==16 ) -printf ("uid: 0x%016" PRIx64"%016" PRIx64"\n" , - uid[1 ], uid[0 ]); -else -error (1 , errno,"USB read truncated" ); +error (1 , ret,"error downloading bootloader: %s" , blfile); + +nv3p_close (h3p); +usb_close (usb); + +return 0 ; +} + +static int initialize_rcm (uint16_t devid,usb_device_t *usb) +{ +int ret; +uint8_t *msg_buff; +int msg_len; +uint32_t status; +int actual_len; +uint8_t *miniloader; +uint32_t miniloader_size; +uint32_t miniloader_entry;// initialize RCM if ((devid & 0xff) == USB_DEVID_NVIDIA_TEGRA20 ||
@@ -215,30 +267,41 @@ int main(int argc, char **argv)dprintf ("initializing RCM version 40\n" ); ret =rcm_init (RCM_VERSION_40 ); }else { -error (1 ,ENODEV ,"unknown tegra device: 0x%x" , devid); +fprintf (stderr,"unknown tegra device: 0x%x\n" , devid); +return errno; + } +if (ret) { +fprintf (stderr,"RCM initialize failed\n" ); +return ret; } -if (ret) -error (1 , errno,"RCM initialize failed" );// create query version message rcm_create_msg (RCM_CMD_QUERY_RCM_VERSION ,NULL ,0 ,NULL ,0 , &msg_buff);// write query version message to device msg_len =rcm_get_msg_len (msg_buff); -if (msg_len ==0 ) -error (1 ,EINVAL ,"unknown message length" ); +if (msg_len ==0 ) { +fprintf (stderr,"write RCM query version: unknown message length\n" ); +return EINVAL ; + } ret =usb_write (usb, msg_buff, msg_len); -if (ret) -error (1 , errno,"write query version - USB transfer failure" ); +if (ret) { +fprintf (stderr,"write RCM query version: USB transfer failure\n" ); +return ret; + }free (msg_buff); msg_buff =NULL ;// read response ret =usb_read (usb, (uint8_t *)&status,sizeof (status), &actual_len); -if (ret) -error (1 , ret,"read query version - USB transfer failure" ); -if (actual_len <sizeof (status)) -error (1 ,EIO ,"read query version - USB read truncated" ); +if (ret) { +fprintf (stderr,"read RCM query version: USB transfer failure\n" ); +return ret; + } +if (actual_len <sizeof (status)) { +fprintf (stderr,"read RCM query version: USB read truncated\n" ); +return EIO ; + }printf ("RCM version: %d.%d\n" ,RCM_VERSION_MAJOR (status),RCM_VERSION_MINOR (status));
@@ -260,57 +323,21 @@ int main(int argc, char **argv) miniloader_size =sizeof (miniloader_tegra124); miniloader_entry =TEGRA124_MINILOADER_ENTRY ; }else { -error (1 ,ENODEV ,"unknown tegra device: 0x%x" , devid); +fprintf (stderr,"unknown tegra device: 0x%x\n" , devid); +return ENODEV ; } ret =download_miniloader (usb, miniloader, miniloader_size, miniloader_entry); -if (ret) -error (1 , ret,"Error downloading miniloader" ); -printf ("miniloader downloaded successfully\n" ); - -// device may have re-enumerated, so reopen USB -usb_close (usb); - usb =usb_open (USB_VENID_NVIDIA , &devid); -if (!usb) -error (1 , errno,"could not open USB device" ); - -// now that miniloader is up, start nv3p protocol - ret =nv3p_open (&h3p, usb); -if (ret) -error (1 , errno,"3p open failed" ); - -// get platform info and dump it - ret =nv3p_cmd_send (h3p,NV3P_CMD_GET_PLATFORM_INFO , (uint8_t *)&info); -if (ret) -error (1 , errno,"retreiving platform info" ); - ret =wait_status (h3p); -if (ret) -error (1 , errno,"wait status after platform info" ); -dump_platform_info (&info); - -if (info.op_mode !=RCM_OP_MODE_DEVEL && - info.op_mode !=RCM_OP_MODE_ODM_OPEN && - info.op_mode !=RCM_OP_MODE_PRE_PRODUCTION ) -error (1 ,ENODEV ,"device is not in developer, open, " -"or pre-production mode, cannot flash" ); - -// download the BCT - ret =download_bct (h3p, bctfile);if (ret) { -error (1 , ret,"error downloading bct: %s" , bctfile); +fprintf (stderr,"Error downloading miniloader\n" ); +return ret; } - -// download the bootloader - ret =download_bootloader (h3p, blfile, entryaddr, loadaddr); -if (ret) -error (1 , ret,"error downloading bootloader: %s" , blfile); - -nv3p_close (h3p); -usb_close (usb); +printf ("miniloader downloaded successfully\n" );return 0 ; } +static int wait_status (nv3p_handle_t h3p) {int ret;
Signature · 1 line
1.8.1.5
A message that is not in the archive (sent off-list or not yet received): 1378757761-20939-7-git-send-email-amartin-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
Re: [PATCH 06/11] tegrarcm: Assume nv3p server is running if RCM doesn't respond
Quoted 7 lines · Allen Martin
Change the initialization logic so that if RCM protocol isn't repsonding but a tegra recovery USB is reported, assume the nv3p server is already running. This allows things like enumeration of devices via nv3p without having to reset into RCM mode to talk to the device again.
src/main.c int main(int argc, char **argv) · line 341
Quoted 7 lines
src/main.c +1
-0return 0 ; } +static int wait_status (nv3p_handle_t h3p)
Looks like a mistake.
PATCH 7/11 tegrarcm: Clean up usage info
In reply to a message not in the archiveAdded --help and --version commands to usage. Made it more clear that --entryaddr is optional.
--- src/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
src/main.c +9 -2
@@ -87,9 +87,16 @@ static void print_version(char *progname)static void usage (char *progname) { -fprintf (stderr,"usage: %s --bct=bctfile --bootloader=blfile --loadaddr=<loadaddr> --entryaddr=<entryaddr>\n" , progname); +fprintf (stderr,"usage: %s [options] --bct=bctfile --bootloader=blfile --loadaddr=<loadaddr>\n" , progname);fprintf (stderr,"\n" ); -fprintf (stderr,"\tIf entryaddr is not specified, it's assumed to be the same as loadaddr\n" ); +fprintf (stderr,"Options:\n" ); +fprintf (stderr,"\t--entryaddr=<entryaddr>\n" ); +fprintf (stderr,"\t\tSpecify the entry point for the bootloader, if this option is\n" ); +fprintf (stderr,"\t\tnot provided, it is assumed to be loadaddr\n" ); +fprintf (stderr,"\t--help\n" ); +fprintf (stderr,"\t\tPrint this help information\n" ); +fprintf (stderr,"\t--version\n" ); +fprintf (stderr,"\t\tPrint version information and exit\n" );fprintf (stderr,"\n" ); }
Signature · 1 line
1.8.1.5
PATCH 8/11 tegrarcm: Add rip support
In reply to a message not in the archiveAdd a new command "--ripbct" which will rip the BCT from the target system and write it to bctfile.
--- src/main.c | 97 +++++++++++++++++++++++++++++++++++++++++++++---------- src/nv3p.c | 10 ++++-- src/nv3p.h | 16 +++++++++ src/tegrarcm.1.in | 5 +++ 4 files changed, 108 insertions(+), 20 deletions(-)
src/main.c +80 -17
@@ -69,6 +69,7 @@ static void dump_platform_info(nv3p_platform_info_t *info);static int download_bct (nv3p_handle_t h3p,char *filename);static int download_bootloader (nv3p_handle_t h3p,char *filename,uint32_t entry,uint32_t loadaddr); +static int rip_bct (nv3p_handle_t h3p,char *filename);enum cmdline_opts {OPT_BCT ,
@@ -77,6 +78,7 @@ enum cmdline_opts {OPT_ENTRYADDR ,OPT_HELP ,OPT_VERSION , +OPT_RIPBCT , OPT_END, };
@@ -97,6 +99,8 @@ static void usage(char *progname)fprintf (stderr,"\t\tPrint this help information\n" );fprintf (stderr,"\t--version\n" );fprintf (stderr,"\t\tPrint version information and exit\n" ); +fprintf (stderr,"\t--ripbct\n" ); +fprintf (stderr,"\t\tRead the BCT from the target device and write to bctfile\n" );fprintf (stderr,"\n" ); }
@@ -116,6 +120,8 @@ int main(int argc, char **argv)uint32_t loadaddr =0 ;uint32_t entryaddr =0 ;uint16_t devid; +int do_rip =0 ; +int msg_len;static struct option long_options[] = { [OPT_BCT ] = {"bct" ,1 ,0 ,0 },
@@ -124,6 +130,7 @@ int main(int argc, char **argv) [OPT_ENTRYADDR] = {"entryaddr", 1, 0, 0}, [OPT_HELP] = {"help", 0, 0, 0}, [OPT_VERSION] = {"version", 0, 0, 0}, + [OPT_RIPBCT] = {"ripbct", 0, 0, 0}, [OPT_END ] = {0 ,0 ,0 ,0 } };
@@ -152,6 +159,9 @@ int main(int argc, char **argv)case OPT_VERSION :print_version (argv[0 ]);exit (0 ); +case OPT_RIPBCT : + do_rip =1 ; +break ;case OPT_HELP :default :usage (argv[0 ]);
@@ -170,24 +180,25 @@ int main(int argc, char **argv)usage (argv[0 ]);exit (EXIT_FAILURE ); } -if (blfile ==NULL ) { -fprintf (stderr,"bootloader file must be specified\n" ); -usage (argv[0 ]); -exit (EXIT_FAILURE ); - } -if (loadaddr ==0 ) { -fprintf (stderr,"loadaddr must be specified\n" ); -usage (argv[0 ]); -exit (EXIT_FAILURE ); - } -if (entryaddr ==0 ) { - entryaddr = loadaddr; - } -printf ("bct file: %s\n" , bctfile); -printf ("booloader file: %s\n" , blfile); -printf ("load addr 0x%x\n" , loadaddr); -printf ("entry addr 0x%x\n" , entryaddr); +if (!do_rip) { +if (blfile ==NULL ) { +fprintf (stderr,"bootloader file must be specified\n" ); +usage (argv[0 ]); +exit (EXIT_FAILURE ); + } +if (loadaddr ==0 ) { +fprintf (stderr,"loadaddr must be specified\n" ); +usage (argv[0 ]); +exit (EXIT_FAILURE ); + } +if (entryaddr ==0 ) { + entryaddr = loadaddr; + } +printf ("booloader file: %s\n" , blfile); +printf ("load addr 0x%x\n" , loadaddr); +printf ("entry addr 0x%x\n" , entryaddr); + } usb =usb_open (USB_VENID_NVIDIA , &devid);if (!usb)
@@ -219,6 +230,14 @@ int main(int argc, char **argv)if (ret)error (1 , errno,"3p open failed" ); +// rip the BCT +if (do_rip) { + ret =rip_bct (h3p, bctfile); +if (ret) +error (1 , errno,"error ripping bct" ); +exit (0 ); + } +// get platform info and dump it ret =nv3p_cmd_send (h3p,NV3P_CMD_GET_PLATFORM_INFO , (uint8_t *)&info);if (ret)
@@ -593,6 +612,50 @@ static int download_bct(nv3p_handle_t h3p, char *filename) } +static int rip_bct (nv3p_handle_t h3p,char *filename) +{ +int ret; +nv3p_bct_info_t bct_info; +uint8_t *bct_data; +int fd; + + ret =nv3p_cmd_send (h3p,NV3P_CMD_GET_BCT , (uint8_t *)&bct_info); +if (ret) { +dprintf ("error sending get bct command\n" ); +return ret; + } + ret =wait_status (h3p); +if (ret) { +dprintf ("error waiting for status after get bct\n" ); +return ret; + } + +printf ("bct length is %d\n" , bct_info.length); + + bct_data = (uint8_t *)malloc (bct_info.length); + ret =nv3p_data_recv (h3p, bct_data, bct_info.length); +if (ret) { +dprintf ("error retreiving bct data\n" ); +return ret; + } +printf ("bct: 0x%02x 0x%02x 0x%02x 0x%02x\n" , bct_data[0 ], bct_data[1 ], bct_data[2 ], bct_data[3 ]); + + fd =open (filename,O_WRONLY |O_CREAT ,0644 ); +if (fd <0 ) { +dprintf ("error opening %s for reading\n" , filename); +return errno; + } + +if (write (fd, bct_data, bct_info.length) != bct_info.length) { +dprintf ("short write on %s\n" , filename); +return errno; + } + +free (bct_data); +close (fd); +return 0 ; +} +static int download_bootloader (nv3p_handle_t h3p,char *filename,uint32_t entry,uint32_t loadaddr) {
src/nv3p.c +7 -3
@@ -123,7 +123,7 @@ typedef struct nv3p_state {* double the currently-largest command size, just to have some wiggle-room * (updates to commands without fixing this on accident, etc.) */ -#define NV3P_MAX_COMMAND_SIZE 128 +#define NV3P_MAX_COMMAND_SIZE (2 << 12)#define NV3P_MAX_ACK_SIZE \ NV3P_PACKET_SIZE_BASIC + \
@@ -209,7 +209,6 @@ static int nv3p_recv_hdr(nv3p_handle_t h3p, nv3p_header_t *hdr, uint32_t *checksum );static int nv3p_drain_packet (nv3p_handle_t h3p,nv3p_header_t *hdr );static void nv3p_nack (nv3p_handle_t h3p,uint32_t code); -static int nv3p_data_recv (nv3p_handle_t h3p,uint8_t *data,uint32_t length);static int nv3p_read (usb_device_t *usb,uint8_t *buf,int len);static int nv3p_get_args (nv3p_handle_t h3p,uint32_t command,void **args,uint8_t *packet );
@@ -321,6 +320,7 @@ static void nv3p_write_cmd(nv3p_handle_t h3p, uint32_t command, void *args,switch (command) {case NV3P_CMD_GET_PLATFORM_INFO : +case NV3P_CMD_GET_BCT :// no args or output only *length =0 ;WRITE32 (tmp, *length);
@@ -418,6 +418,9 @@ static int nv3p_get_cmd_return(nv3p_handle_t h3p, uint32_t command, void *args)case NV3P_CMD_GET_PLATFORM_INFO : length =sizeof (nv3p_platform_info_t);break ; +case NV3P_CMD_GET_BCT : + length =sizeof (nv3p_bct_info_t); +break ;case NV3P_CMD_DL_BCT :case NV3P_CMD_DL_BL :break ;
@@ -467,7 +470,7 @@ static int nv3p_recv_hdr(nv3p_handle_t h3p, nv3p_header_t *hdr,return 0 ; } -static int nv3p_data_recv (nv3p_handle_t h3p,uint8_t *data,uint32_t length) +int nv3p_data_recv (nv3p_handle_t h3p,uint8_t *data,uint32_t length) {int ret;uint8_t *tmp;
@@ -629,6 +632,7 @@ static int nv3p_get_args(nv3p_handle_t h3p, uint32_t command, void **args,switch (command) {case NV3P_CMD_GET_PLATFORM_INFO : +case NV3P_CMD_GET_BCT :// output only break ;case NV3P_CMD_STATUS :
src/nv3p.h +16 -0
@@ -39,6 +39,7 @@// commands #define NV3P_CMD_GET_PLATFORM_INFO 0x01 +#define NV3P_CMD_GET_BCT 0x02#define NV3P_CMD_DL_BCT 0x04#define NV3P_CMD_DL_BL 0x06#define NV3P_CMD_STATUS 0x0a
@@ -152,6 +153,20 @@ typedef struct {/* +* nv3p_bct_info_t: holds information about BCT size +*/ +typedef struct { +uint32_t length; +}nv3p_bct_info_t ; + +/* +* nv3p_cmd_get_bct_t: retrieves the BCT from the device +*/ +typedef struct { +uint32_t length; +}nv3p_cmd_get_bct_t ; + +/* * nv3p_cmd_dl_bct_t: downloads the system's BCT. */ typedef struct {
@@ -173,5 +188,6 @@ int nv3p_cmd_send(nv3p_handle_t h3p, uint32_t command, void *args);int nv3p_cmd_recv (nv3p_handle_t h3p,uint32_t *command,void **args);int nv3p_data_send (nv3p_handle_t h3p,uint8_t *data,uint32_t length);void nv3p_ack (nv3p_handle_t h3p); +int nv3p_data_recv (nv3p_handle_t h3p,uint8_t *data,uint32_t length);#endif // NV3P_H
src/tegrarcm.1.in +5 -0
@@ -67,6 +67,11 @@ Print the version number and exit. .TP .B \-\-help Print help text and exit. +.TP +.B \-\-ripbct +Read the BCT from the target device and write it to \fIbctfile\fP. If +this option is specified, the --bootloader, --loadaddr, and +--entryaddr options are ignored. .SH EXAMPLE To download u-boot firmware to a Tegra20 seaboard:
Signature · 1 line
1.8.1.5
A message that is not in the archive (sent off-list or not yet received): 1378757761-20939-9-git-send-email-amartin-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
Re: [PATCH 08/11] tegrarcm: Add rip support
Quoted 2 lines · Allen Martin
Add a new command "--ripbct" which will rip the BCT from the target system and write it to bctfile.
Bikeshed: s/rip/read/ or get or download? rip sounds a bit like a CD.
src/main.c static void usage(char *progname) · line 105
Quoted 10 lines
src/main.c +2
-0@@ -97,6 +99,8 @@ static void usage(char *progname)fprintf (stderr,"\t\tPrint this help information\n" );fprintf (stderr,"\t--version\n" );fprintf (stderr,"\t\tPrint version information and exit\n" ); +fprintf (stderr,"\t--ripbct\n" ); +fprintf (stderr,"\t\tRead the BCT from the target device and write to bctfile\n" );fprintf (stderr,"\n" ); }
It might be nice to try and make it more explicit that there are now 2 modes of operation, and have separate sections in the usage text to detail both. That would also help point out that e.g. --bootloader is now only required in non-(--rip)-mode.
I wonder if we should make this a sub-command rather than an option ("rip" rather than "--rip").
src/main.c static int download_bct(nv3p_handle_t h3p, char *filename) · line 641
Quoted 3 lines
src/main.c +2
-0+static int rip_bct(nv3p_handle_t h3p, char *filename) + printf("bct: 0x%02x 0x%02x 0x%02x 0x%02x\n", bct_data[0], bct_data[1], bct_data[2], bct_data[3]);
Left-over debugging?
src/main.c static int download_bct(nv3p_handle_t h3p, char *filename) · line 652
Quoted 4 lines
src/main.c +4
-0+if (write (fd, bct_data, bct_info.length) != bct_info.length) { +dprintf ("short write on %s\n" , filename); +return errno; + }
What if a signal gets delivered here; don't you need to loop until the whole buffer has been written? I don't recall whether fwrite() would do that automatically.
src/tegrarcm.1.in Print the version number and exit. · line 74
Quoted 7 lines
src/tegrarcm.1.in +5
-0+.TP +.B \-\-ripbct +Read the BCT from the target device and write it to \fIbctfile\fP. If +this option is specified, the --bootloader, --loadaddr, and +--entryaddr options are ignored.
Same comment here as for the usage text above.
PATCH 9/11 tegrarcm: Add support for odmdata command
In reply to a message not in the archiveAdd command "--odmdata" to pass odmdata down to the miniloader. This is used by the miniloader for things such as UART init and RAM sizing. It is normally not needed and is really only useful for miniloader debugging.
--- src/main.c | 34 +++++++++++++++++++++++++++++++++- src/nv3p.c | 16 ++++++++++++++++ src/nv3p.h | 8 ++++++++ src/tegrarcm.1.in | 4 ++++ 4 files changed, 61 insertions(+), 1 deletion(-)
src/main.c +33 -1
@@ -70,6 +70,7 @@ static int download_bct(nv3p_handle_t h3p, char *filename);static int download_bootloader (nv3p_handle_t h3p,char *filename,uint32_t entry,uint32_t loadaddr);static int rip_bct (nv3p_handle_t h3p,char *filename); +static int send_odmdata (nv3p_handle_t h3p,uint32_t odmdata);enum cmdline_opts {OPT_BCT ,
@@ -79,6 +80,7 @@ enum cmdline_opts {OPT_HELP ,OPT_VERSION ,OPT_RIPBCT , +OPT_ODMDATA , OPT_END, };
@@ -121,7 +123,7 @@ int main(int argc, char **argv)uint32_t entryaddr =0 ;uint16_t devid;int do_rip =0 ; -int msg_len; +uint32_t odmdata =0 ;static struct option long_options[] = { [OPT_BCT ] = {"bct" ,1 ,0 ,0 },
@@ -131,6 +133,7 @@ int main(int argc, char **argv) [OPT_HELP] = {"help", 0, 0, 0}, [OPT_VERSION] = {"version", 0, 0, 0}, [OPT_RIPBCT] = {"ripbct", 0, 0, 0}, + [OPT_ODMDATA] = {"odmdata", 1, 0, 0}, [OPT_END ] = {0 ,0 ,0 ,0 } };
@@ -162,6 +165,9 @@ int main(int argc, char **argv)case OPT_RIPBCT : do_rip =1 ;break ; +case OPT_ODMDATA : + odmdata =strtoul (optarg,NULL ,0 ); +break ;case OPT_HELP :default :usage (argv[0 ]);
@@ -238,6 +244,12 @@ int main(int argc, char **argv)exit (0 ); } +if (odmdata) { + ret =send_odmdata (h3p, odmdata); +if (ret) +error (1 , ret,"error sending ODM data" ); + } +// get platform info and dump it ret =nv3p_cmd_send (h3p,NV3P_CMD_GET_PLATFORM_INFO , (uint8_t *)&info);if (ret)
@@ -656,6 +668,26 @@ static int rip_bct(nv3p_handle_t h3p, char *filename)return 0 ; } +static int send_odmdata (nv3p_handle_t h3p,uint32_t odmdata) +{ +int ret; +nv3p_cmd_send_odmdata_t odm_info; + + odm_info.odmdata = odmdata; + ret =nv3p_cmd_send (h3p,NV3P_CMD_SEND_ODMDATA , (uint8_t *)&odm_info); +if (ret) { +dprintf ("error sending send odmdata command\n" ); +return ret; + } + ret =wait_status (h3p); +if (ret) { +dprintf ("error waiting for status after get bct\n" ); +return ret; + } + +return 0 ; +} +static int download_bootloader (nv3p_handle_t h3p,char *filename,uint32_t entry,uint32_t loadaddr) {
src/nv3p.c +16 -0
@@ -346,6 +346,15 @@ static void nv3p_write_cmd(nv3p_handle_t h3p, uint32_t command, void *args,WRITE32 (tmp, a->entry);break ; } +case NV3P_CMD_SEND_ODMDATA : + { +nv3p_cmd_send_odmdata_t *a = (nv3p_cmd_send_odmdata_t *)args; + *length = (1 *4 ); +WRITE32 (tmp, *length); +WRITE32 (tmp, command); +WRITE32 (tmp, a->odmdata); +break ; + }default :dprintf ("bad command: 0x%x\n" , command);break ;
@@ -423,6 +432,7 @@ static int nv3p_get_cmd_return(nv3p_handle_t h3p, uint32_t command, void *args)break ;case NV3P_CMD_DL_BCT :case NV3P_CMD_DL_BL : +case NV3P_CMD_SEND_ODMDATA :break ;default :dprintf ("unknown command: 0x%x\n" , command);
@@ -659,6 +669,12 @@ static int nv3p_get_args(nv3p_handle_t h3p, uint32_t command, void **args,READ32 (tmp, a->entry);break ; } +case NV3P_CMD_SEND_ODMDATA : + { +nv3p_cmd_send_odmdata_t *a = (nv3p_cmd_send_odmdata_t *)buf; +READ32 (tmp, a->odmdata); +break ; + }default :dprintf ("unknown command: 0x%x\n" , command);return EINVAL ;
src/nv3p.h +8 -0
@@ -42,6 +42,7 @@#define NV3P_CMD_GET_BCT 0x02#define NV3P_CMD_DL_BCT 0x04#define NV3P_CMD_DL_BL 0x06 +#define NV3P_CMD_SEND_ODMDATA 0x07#define NV3P_CMD_STATUS 0x0a// nack codes
@@ -182,6 +183,13 @@ typedef struct {uint32_t entry;// Execution entry point } nv3p_cmd_dl_bl_t; +/* +* nv3p_cmd_send_odmdata_t: send ODMDATA to the device +*/ +typedef struct { +uint32_t odmdata; +}nv3p_cmd_send_odmdata_t ; +int nv3p_open (nv3p_handle_t *h3p,usb_device_t *usb);void nv3p_close (nv3p_handle_t h3p);int nv3p_cmd_send (nv3p_handle_t h3p,uint32_t command,void *args);
src/tegrarcm.1.in +4 -0
@@ -72,6 +72,10 @@ Print help text and exit. Read the BCT from the target device and write it to \fIbctfile\fP. If this option is specified, the --bootloader, --loadaddr, and --entryaddr options are ignored. +.TP +.B \-\-odmdata +Pass odmdata down to the miniloader. This is really only useful for +miniloader debugging. .SH EXAMPLE To download u-boot firmware to a Tegra20 seaboard:
Signature · 1 line
1.8.1.5
A message that is not in the archive (sent off-list or not yet received): 1378757761-20939-10-git-send-email-amartin-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
Re: [PATCH 09/11] tegrarcm: Add support for odmdata command
Quoted 4 lines · Allen Martin
Add command "--odmdata" to pass odmdata down to the miniloader. This is used by the miniloader for things such as UART init and RAM sizing. It is normally not needed and is really only useful for miniloader debugging.
Does the miniloader put it into the BCT in IRAM so that the bootloader can also read it? If suppose we expect the correct ODMDATA to be already included in the BCT that tegrarcm sends though, so the bootloader already sees the correct value.
I think usage() needs updating in this patch.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 09/11] tegrarcm: Add support for odmdata command
Quoted 10 lines · Stephen Warren
Quoted 4 lines · Allen Martin
Add command "--odmdata" to pass odmdata down to the miniloader. This is used by the miniloader for things such as UART init and RAM sizing. It is normally not needed and is really only useful for miniloader debugging.
Does the miniloader put it into the BCT in IRAM so that the bootloader can also read it? If suppose we expect the correct ODMDATA to be already included in the BCT that tegrarcm sends though, so the bootloader already sees the correct value.
Yes, miniloader will update the BCT with the new value if you send this command after downloading a BCT. Really the only thing I'm using this for is the side effect inside miniloader that causes it to reinitialize the UART with the new odmdata value. For some reason when you donwload the BCT, miniloader does not do that, and when you boot in recovery mode there's no initial BCT so UART never gets initialized in miniloader and you get no debug prints.
Quoted 2 lines
I think
usage()needs updating in this patch.
Will do.
Signature · 1 line
nvpublic
Re: [PATCH 09/11] tegrarcm: Add support for odmdata command
Quoted 12 lines · Allen Martin
Quoted 10 lines · Stephen Warren
Quoted 4 lines · Allen Martin
Add command "--odmdata" to pass odmdata down to the miniloader. This is used by the miniloader for things such as UART init and RAM sizing. It is normally not needed and is really only useful for miniloader debugging.
Does the miniloader put it into the BCT in IRAM so that the bootloader can also read it? If suppose we expect the correct ODMDATA to be already included in the BCT that tegrarcm sends though, so the bootloader already sees the correct value.
Quoted 7 lines
Yes, miniloader will update the BCT with the new value if you send this command after downloading a BCT. Really the only thing I'm using this for is the side effect inside miniloader that causes it to reinitialize the UART with the new odmdata value. For some reason when you donwload the BCT, miniloader does not do that, and when you boot in recovery mode there's no initial BCT so UART never gets initialized in miniloader and you get no debug prints.
Oh, I wasn't aware that the miniloader ever initialized the UART. Debug prints from what? The miniloader itself, or what it loads (which I think should be initializing the UART from scratch anyway, since I assume the boot ROM doesn't do it for the regular boot path either).
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 09/11] tegrarcm: Add support for odmdata command
Quoted 21 lines · Stephen Warren
Quoted 12 lines · Allen Martin
Quoted 10 lines · Stephen Warren
Quoted 4 lines · Allen Martin
Add command "--odmdata" to pass odmdata down to the miniloader. This is used by the miniloader for things such as UART init and RAM sizing. It is normally not needed and is really only useful for miniloader debugging.
Does the miniloader put it into the BCT in IRAM so that the bootloader can also read it? If suppose we expect the correct ODMDATA to be already included in the BCT that tegrarcm sends though, so the bootloader already sees the correct value.
Quoted 7 lines
Yes, miniloader will update the BCT with the new value if you send this command after downloading a BCT. Really the only thing I'm using this for is the side effect inside miniloader that causes it to reinitialize the UART with the new odmdata value. For some reason when you donwload the BCT, miniloader does not do that, and when you boot in recovery mode there's no initial BCT so UART never gets initialized in miniloader and you get no debug prints.
Quoted 4 lines
Oh, I wasn't aware that the miniloader ever initialized the UART. Debug prints from what? The miniloader itself, or what it loads (which I think should be initializing the UART from scratch anyway, since I assume the boot ROM doesn't do it for the regular boot path either).
Yes, debugging the miniloader. I loaded a debug version of the miniloader during venice2 bringup to determine why it was failing and added this command so I could see the error messages from it. It may only be useful to me, so I can yank it from the series if you don't think it's useful for inclusion in the upstream repository.
-Allen
Re: [PATCH 09/11] tegrarcm: Add support for odmdata command
Quoted 27 lines · Allen Martin
Quoted 21 lines · Stephen Warren
Quoted 12 lines · Allen Martin
Quoted 10 lines · Stephen Warren
Quoted 4 lines · Allen Martin
Add command "--odmdata" to pass odmdata down to the miniloader. This is used by the miniloader for things such as UART init and RAM sizing. It is normally not needed and is really only useful for miniloader debugging.
Does the miniloader put it into the BCT in IRAM so that the bootloader can also read it? If suppose we expect the correct ODMDATA to be already included in the BCT that tegrarcm sends though, so the bootloader already sees the correct value.
Quoted 7 lines
Yes, miniloader will update the BCT with the new value if you send this command after downloading a BCT. Really the only thing I'm using this for is the side effect inside miniloader that causes it to reinitialize the UART with the new odmdata value. For some reason when you donwload the BCT, miniloader does not do that, and when you boot in recovery mode there's no initial BCT so UART never gets initialized in miniloader and you get no debug prints.
Quoted 4 lines
Oh, I wasn't aware that the miniloader ever initialized the UART. Debug prints from what? The miniloader itself, or what it loads (which I think should be initializing the UART from scratch anyway, since I assume the boot ROM doesn't do it for the regular boot path either).
Quoted 5 lines
Yes, debugging the miniloader. I loaded a debug version of the miniloader during venice2 bringup to determine why it was failing and added this command so I could see the error messages from it. It may only be useful to me, so I can yank it from the series if you don't think it's useful for inclusion in the upstream repository.
It might not be a bad idea to remove it then; having it around will just encourage people to use it rather than setting the ODMDATA correctly in the BCT. If/when we get an OSS miniloader replacement, we can always think about adding it back, although then I'd argue that the UART should be initialized as a side-effect of downloading/activating the BCT anyway, so you still wouldn't need the command.
PATCH 10/11 tegrarcm: Add command to pass miniloader in from file
In reply to a message not in the archiveAdd --miniloader and --miniloader_entry commands which allow passing in the miniloader from a file and specifying the miniloader entry address from the command line instead of using built-in miniloader.
--- src/main.c | 112 +++++++++++++++++++++++++++++++++++++++++------------- src/tegrarcm.1.in | 8 ++++ 2 files changed, 93 insertions(+), 27 deletions(-)
src/main.c +85 -27
@@ -61,6 +61,7 @@#include "miniloader/tegra124-miniloader.h" static int initialize_rcm (uint16_t devid,usb_device_t *usb); +static int initialize_miniloader (uint16_t devid,usb_device_t *usb,char *mlfile,uint32_t mlentry);static int wait_status (nv3p_handle_t h3p);static int send_file (nv3p_handle_t h3p,const char *filename); static int download_miniloader(usb_device_t *usb, uint8_t *miniloader,
@@ -81,6 +82,8 @@ enum cmdline_opts {OPT_VERSION ,OPT_RIPBCT ,OPT_ODMDATA , +OPT_MINILOADER , +OPT_MINIENTRY , OPT_END, };
@@ -103,6 +106,11 @@ static void usage(char *progname)fprintf (stderr,"\t\tPrint version information and exit\n" );fprintf (stderr,"\t--ripbct\n" );fprintf (stderr,"\t\tRead the BCT from the target device and write to bctfile\n" ); +fprintf (stderr,"\t--miniloader=mlfile\n" ); +fprintf (stderr,"\t\tRead the miniloader from file instead of using built-in\n" ); +fprintf (stderr,"\t\tminiloader\n" ); +fprintf (stderr,"\t--miniloader_entry=<mlentry>\n" ); +fprintf (stderr,"\t\tSpecify the entry point for the miniloader\n" );fprintf (stderr,"\n" ); }
@@ -114,7 +122,7 @@ int main(int argc, char **argv)usb_device_t *usb;nv3p_platform_info_t info;nv3p_handle_t h3p; -int ret; +int ret, ret2;int c;int option_index =0 ;char *bctfile =NULL ;
@@ -124,6 +132,8 @@ int main(int argc, char **argv)uint16_t devid;int do_rip =0 ;uint32_t odmdata =0 ; +char *mlfile =NULL ; +uint32_t mlentry =0 ;static struct option long_options[] = { [OPT_BCT ] = {"bct" ,1 ,0 ,0 },
@@ -134,6 +144,8 @@ int main(int argc, char **argv) [OPT_VERSION] = {"version", 0, 0, 0}, [OPT_RIPBCT] = {"ripbct", 0, 0, 0}, [OPT_ODMDATA] = {"odmdata", 1, 0, 0}, + [OPT_MINILOADER] = {"miniloader", 1, 0, 0}, + [OPT_MINIENTRY] = {"miniloader_entry", 1, 0, 0}, [OPT_END ] = {0 ,0 ,0 ,0 } };
@@ -168,6 +180,12 @@ int main(int argc, char **argv)case OPT_ODMDATA : odmdata =strtoul (optarg,NULL ,0 );break ; +case OPT_MINILOADER : + mlfile = optarg; +break ; +case OPT_MINIENTRY : + mlentry =strtoul (optarg,NULL ,0 ); +break ;case OPT_HELP :default :usage (argv[0 ]);
@@ -221,8 +239,15 @@ int main(int argc, char **argv)else error (1 , errno,"USB read truncated" ); -// initialize rcm and download the miniloader to start nv3p -initialize_rcm (devid, usb); +// initialize rcm + ret2 =initialize_rcm (devid, usb); +if (ret2) +error (1 , errno,"error initializing RCM protocol" ); + +// download the miniloader to start nv3p + ret2 =initialize_miniloader (devid, usb, mlfile, mlentry); +if (ret2) +error (1 , errno,"error initializing miniloader" );// device may have re-enumerated, so reopen USB usb_close (usb);
@@ -289,9 +314,6 @@ static int initialize_rcm(uint16_t devid, usb_device_t *usb)int msg_len;uint32_t status;int actual_len; -uint8_t *miniloader; -uint32_t miniloader_size; -uint32_t miniloader_entry;// initialize RCM if ((devid & 0xff) == USB_DEVID_NVIDIA_TEGRA20 ||
@@ -343,27 +365,65 @@ static int initialize_rcm(uint16_t devid, usb_device_t *usb)printf ("RCM version: %d.%d\n" ,RCM_VERSION_MAJOR (status),RCM_VERSION_MINOR (status)); -printf ("downloading miniloader to target...\n" ); -if ((devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA20 ) { - miniloader = miniloader_tegra20; - miniloader_size =sizeof (miniloader_tegra20); - miniloader_entry =TEGRA20_MINILOADER_ENTRY ; - }else if ((devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA30 ) { - miniloader = miniloader_tegra30; - miniloader_size =sizeof (miniloader_tegra30); - miniloader_entry =TEGRA30_MINILOADER_ENTRY ; - }else if ((devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA114 ) { - miniloader = miniloader_tegra114; - miniloader_size =sizeof (miniloader_tegra114); - miniloader_entry =TEGRA114_MINILOADER_ENTRY ; - }else if ((devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA124 ) { - miniloader = miniloader_tegra124; - miniloader_size =sizeof (miniloader_tegra124); - miniloader_entry =TEGRA124_MINILOADER_ENTRY ; +return 0 ; +} + +static int initialize_miniloader (uint16_t devid,usb_device_t *usb,char *mlfile,uint32_t mlentry) +{ +int fd; +struct stat sb; +int ret; +uint8_t *miniloader; +uint32_t miniloader_size; +uint32_t miniloader_entry; + +// use prebuilt miniloader if not loading from a file +if (mlfile) { + fd =open (mlfile,O_RDONLY ,0 ); +if (fd <0 ) { +dprintf ("error opening %s for reading\n" , mlfile); +return errno; + } + ret =fstat (fd, &sb); +if (ret) { +dprintf ("error on fstat of %s\n" , mlfile); +return ret; + } + miniloader_size = sb.st_size; + miniloader = (uint8_t *)malloc (miniloader_size); +if (!miniloader) { +dprintf ("error allocating %d bytes for miniloader\n" , miniloader_size); +return errno; + } +if (read (fd, miniloader, miniloader_size) != miniloader_size) { +dprintf ("error reading from miniloader file" ); +return errno; + } + miniloader_entry = mlentry; }else { -fprintf (stderr,"unknown tegra device: 0x%x\n" , devid); -return ENODEV ; +if ((devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA20 ) { + miniloader = miniloader_tegra20; + miniloader_size =sizeof (miniloader_tegra20); + miniloader_entry =TEGRA20_MINILOADER_ENTRY ; + }else if ((devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA30 ) { + miniloader = miniloader_tegra30; + miniloader_size =sizeof (miniloader_tegra30); + miniloader_entry =TEGRA30_MINILOADER_ENTRY ; + }else if ((devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA114 ) { + miniloader = miniloader_tegra114; + miniloader_size =sizeof (miniloader_tegra114); + miniloader_entry =TEGRA114_MINILOADER_ENTRY ; + }else if ((devid &0xff ) ==USB_DEVID_NVIDIA_TEGRA124 ) { + miniloader = miniloader_tegra124; + miniloader_size =sizeof (miniloader_tegra124); + miniloader_entry =TEGRA124_MINILOADER_ENTRY ; + }else { +fprintf (stderr,"unknown tegra device: 0x%x\n" , devid); +return ENODEV ; + } } +printf ("downloading miniloader to target at address 0x%x (%d bytes)...\n" , + miniloader_entry, miniloader_size); ret =download_miniloader (usb, miniloader, miniloader_size, miniloader_entry);if (ret) {
@@ -371,11 +431,9 @@ static int initialize_rcm(uint16_t devid, usb_device_t *usb)return ret; }printf ("miniloader downloaded successfully\n" ); -return 0 ; } -static int wait_status (nv3p_handle_t h3p) {int ret;
src/tegrarcm.1.in +8 -0
@@ -76,6 +76,14 @@ this option is specified, the --bootloader, --loadaddr, and .B \-\-odmdata Pass odmdata down to the miniloader. This is really only useful for miniloader debugging. +.TP +.B \-\-miniloader \fImlfile\fP +Read the miniloader from the specified file instead of using the +built-in one. +.TP +.B \-\-miniloader_entry \fImlentry\fP +Specify the entry address of the miniloader. + .SH EXAMPLE To download u-boot firmware to a Tegra20 seaboard:
Signature · 1 line
1.8.1.5
A message that is not in the archive (sent off-list or not yet received): 1378757761-20939-11-git-send-email-amartin-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
Re: [PATCH 10/11] tegrarcm: Add command to pass miniloader in from file
src/main.c static int initialize_rcm(uint16_t devid, usb_device_t *usb) · line 435
Quoted 11 lines · Allen Martin
Add --miniloader and --miniloader_entry commands which allow passing in the miniloader from a file and specifying the miniloader entry address from the command line instead of using built-in miniloader.
src/main.c +0
-1@@ -371,11 +431,9 @@ static int initialize_rcm(uint16_t devid, usb_device_t *usb)return ret; }printf ("miniloader downloaded successfully\n" ); -return 0 ; }
Note sure if you want to remove that blank line.
Review static int initialize_rcm(uint16_t devid, usb_device_t *usb) · line 436
Quoted 3 lines
(quoted diff) +0
-1- static int wait_status(nv3p_handle_t h3p)
Ah, I guess the fix for my earlier comment went into the wrong patch:-)
PATCH 11/11 tegrarcm: Bump version to 1.5
In reply to a message not in the archiveUpdate README with change log for version 1.5, and bump version number.
--- README | 2 ++ configure.ac | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
README +2 -0
@@ -56,6 +56,8 @@ u-boot.bin sent successfully Changes (see git logs for complete list): +V1.5 - Added support for RCM protocol version 40 + - Added Tegra124 support V1.4 - Added --version command - Updated T114 miniloader to fix SPI boot problem - Added --help command to man page
configure.ac +1 -1
@@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.67]) -AC_INIT([tegrarcm], [1.4], [[email protected]]) +AC_INIT([tegrarcm], [1.5], [[email protected]]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_HEADERS([config.h])
Signature · 1 line
1.8.1.5
A message that is not in the archive (sent off-list or not yet received): 1378757761-20939-12-git-send-email-amartin-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
Re: [PATCH 11/11] tegrarcm: Bump version to 1.5
README u-boot.bin sent successfully · line 60
Quoted 8 lines · Allen Martin
Update README with change log for version 1.5, and bump version number.
README +2
-0Changes (see git logs for complete list): +V1.5 - Added support for RCM protocol version 40 + - Added Tegra124 support
It might be worth mentioning the new --rip, --odmdata, --mini* command-line options?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 11/11] tegrarcm: Bump version to 1.5
Quoted 4 lines · Stephen Warren
Quoted 2 lines · Allen Martin
Update README with change log for version 1.5, and bump version number.
Quoted 9 lines
README u-boot.bin sent successfully · line 60
Quoted 5 lines
README +2
-0Changes (see git logs for complete list): +V1.5 - Added support for RCM protocol version 40 + - Added Tegra124 supportIt might be worth mentioning the new --rip, --odmdata, --mini* command-line options?
Good point, will do
Signature · 1 line
nvpublic
Stephen Warren
Reviewed-byQuoted 6 lines · Allen Martin
This patch series adds T124 support to tegrarcm, tested on laguna. It also adds support for new commands for ripping a BCT from a live system, for passing in the miniloader from a file, and for passing in the odmdata on the command line. Also fixed up some of the error handling so now USB commands will time out instead of hanging, and attempt to bring up nv3p even if RCM is unresponsive.
Aside from the few relatively minor comments I made, the series,